Snippet
-
Portable sed -i across GNU and BSD
The one invocation that does not blow up on macOS or Linux.
-
A sync.Pool of bytes.Buffer done right
The Put-before-you-Get-back idiom, and the cap-guard that keeps the pool small.
-
Rust: ok_or_else over ok_or, and why
A tiny pattern that avoids allocating error strings on the happy path.
-
Parallel xargs with an actual progress indicator
xargs -P plus a named pipe to print 'M of N done' without buffering the output.
-
Gaps-and-islands SQL for compressing event streaks
A window-function pattern that collapses consecutive states into runs.
-
Kubernetes webhook: skip a namespace with one selector
The namespaceSelector pattern that saved me from an admission-webhook outage.
-
Caddy snippet for security headers in one place
A named snippet I import into every site so headers stay consistent.
-
HTTP middleware that recovers panics cleanly
Recover, log with a stack, return 500, and do not crash the whole server.
-
Cancel long-idle Postgres transactions
A query plus a loop to find idle-in-transaction sessions and kindly end them.
-
Bash trap for cleaning up a temp directory
The five-line top-of-script pattern I use in every non-trivial bash tool.
-
Detaching a context for background work
A context that keeps the values but drops the cancellation, for async follow-ups.
-
Streaming a large CSV in Python without loading it
The DictReader loop plus a progress tick, so I stop reaching for pandas on 20GB files.
-
Recursive CTE to walk a parent-child tree in SQLite
The WITH RECURSIVE pattern for a self-joining table, with depth and path.
-
A ticker with jitter, cancelled by context
A drop-in replacement for time.NewTicker that stops when your context does and does not synchronize all your replicas.
-
rsync invocation that is actually safe to resume
The flag combo I copy into every backup job so half-done transfers do not corrupt files.