
Code Snippets &
Prompt Lab
Production-tested React hooks, AI engineering prompts, utility functions, and design patterns. Every snippet is battle-tested in real projects. Copy, paste, ship.
105+
Snippets
16
Categories
17+
Languages
100%
Copy Ready
Explore Snippets
Production-tested hooks, prompts, and utility functions.
Get unique values from a Bash array
Extract distinct elements from a Bash array while preserving order, using associative arrays (Bash 4+).
Python 3 CGI: safely read form variables
A ready‑to‑run CGI script that extracts GET and POST fields in Python 3 using cgi.FieldStorage and returns them as a dict.
Prevent Go net.Conn.Close() from hanging
A safe pattern that guarantees Close returns within a timeout by setting a deadline and forcibly closing the fd if needed.
Build Linux Kernel Module (LKM) with Cargo
Use Cargo's build script to call the kernel Makefile so you can compile a C LKM with `cargo build` and get a .ko artifact directly from Cargo.
Run a JavaScript if block only once
Use a closure‑based guard or a once‑helper so the conditional body executes a single time regardless of how many times the surrounding code runs.
Go: Service‑level transaction with proper rollback
Shows a clean pattern for wrapping a service method in a database/sql transaction, guaranteeing rollback on error and commit on success.
Pion WebRTC ReplaceTrack in Layered SFU – ensure video reaches Sub‑SFU
Shows the correct way to call ReplaceTrack on the parent SFU and keep the forwarding goroutine alive so the sub‑SFU continues to receive video without dropping packets.
Enable Tokio multi_thread runtime in Rust
Fix the compile error when Tokio defaults to multi_thread but the feature is disabled by adding the correct Cargo.toml feature flag and using #[tokio::main].
Fix Bash glob (*) on WSL 9P mounts
Remount a Windows folder via WSL's 9P driver with the right options so that `*` expands correctly. The snippet also shows a quick sanity check and how to include dotfiles if needed.
Bash: Unique values from an array
Extract distinct elements from a Bash array while preserving order, using only built‑in features.
Run JSNice locally via Docker (one‑liner script)
A bash helper that pulls the official JSNice Docker image and deobfuscates a JavaScript file in place, so you never need the web UI again.
Git status pre/post hook via alias
There is no native pre‑status/post‑status hook. Use a git alias that runs your scripts before and after the real status command, giving you hook‑like behavior.
Stay Ahead of the Curve
Get our weekly digest of production blueprints, deep-dive benchmarks, and architectural audits delivered directly to your inbox.
Join 5,000+ engineers. No spam, ever.