Snippet
-
pushd/popd for scripts that cd into many directories
A directory stack so scripts do not leak working directories between steps.
-
Builder pattern in Rust with Default
Builder structs for configuration, without a macro crate, when the struct has 20 fields.
-
A PodDisruptionBudget that actually protects you
minAvailable as a percentage, matched to a workload that has more than one replica.
-
A generic atomic counter for typed IDs
sync/atomic plus Go generics, so counter.Add and counter.Load carry their type.
-
Fast row-count estimates without COUNT(*)
pg_class.reltuples for when you need an answer in milliseconds.
-
Parsing process.env with zod, once, at startup
A typed env object that crashes on boot if required variables are missing.
-
A good-enough email regex, with notes on what it ignores
The 90-percent regex I use, plus a list of the 10 percent it deliberately misses.
-
Graceful shutdown with signal.NotifyContext
Three lines that replace the old os/signal dance and are still the right pattern.
-
Bounded parallelism with asyncio.gather
A Semaphore wrapper that caps concurrent coroutines without losing gather ergonomics.
-
tokio::select with an explicit cancellation token
CancellationToken over ad-hoc shutdown channels, because it actually composes.
-
Multi-stage Dockerfile for a Go service on scratch
A tiny final image with certs, tzdata, a non-root user, and no surprises.
-
Parallel Go tests that share a per-test temp directory
t.TempDir plus t.Parallel: short, correct, and auto-cleaning.
-
Shell retry with exponential backoff and jitter
A copy-pasteable retry function for flaky network calls in CI and deploy scripts.
-
Find foreign-key violations before a migration
A query that tells you exactly which child rows will fail when you add the FK.
-
A Click stub for a multi-subcommand CLI
The pattern I copy when I am tired of argparse and need something useful in five minutes.