Recipes
Step-by-step solutions for real development tasks.
699 published
Page 10 of 20
Audit Missing Security Headers
Scan responses for missing HSTS, CSP, X-Content-Type-Options, and frame protections, then fix them with a middleware.
Audit and Constrain npm Install Scripts in Your Supply Chain
Enumerate which dependencies declare lifecycle scripts, run installs with scripts disabled, and gate the exceptions you truly need.
Audit PostgreSQL Unused Indexes
Use pg_stat_user_indexes to find indexes that are never scanned, then drop them safely after confirming they are not unique constraints.
Automate Blue-Green DNS Cutover
Switch traffic between blue and green stacks by updating DNS with a low TTL and verifying health before and after the cutover.
Automate Certificate Renewal with a Deploy Hook
Configure certbot renewals with dry runs, a deploy hook that reloads the right service, and monitoring that alerts when renewal stops happening.
Backfill a Warehouse Partition Safely
Backfill a single partition in place with an atomic swap so queries see either the old or the new data, never a partial mix.
Batch Network Calls Without Losing Latency
Coalesce many small requests into fewer batched calls using a short scheduling window to cut round-trip overhead.
Block SSH Brute Force with fail2ban
Match auth failures with a jail, ban repeat offenders with iptables or nftables, whitelist your own networks, and verify with a test ban.
Block Unnecessary Outbound Egress
Apply a default-deny egress policy so a compromised workload cannot reach arbitrary hosts on the internet.
Blue-Green Switch with Cloudflare Workers
Route a portion of traffic between two origins using a Worker and shift weight programmatically to enable instant rollback.
Build argparse Subcommands
Structure a Python CLI with subparsers so each command has its own arguments and a shared top-level parser.
Build Interactive CLI Prompts with Validation and Safe Defaults
Ask questions only when arguments are absent, validate answers in the loop, and make non-interactive mode the escape hatch that always works.
Bulk Upsert Thousands of Rows with ON CONFLICT in PostgreSQL
Stream rows through COPY or multi-row INSERT with ON CONFLICT DO UPDATE, avoiding per-row round trips and deadlocks from unordered writes.
Cache API Responses in a Service Worker
Apply a stale-while-revalidate strategy in a service worker so repeat visits render instantly and refresh in the background.
Cache Serialization with MessagePack
Swap JSON for MessagePack in a hot cache path to cut serialization CPU and payload size without changing semantics.
Capture gRPC DEADLINE_EXCEEDED Traces
Instrument a gRPC client to surface deadline budgets and server spans so DEADLINE_EXCEEDED can be traced to the slow dependency.
Catch a Retry Storm by Capturing Packets with tcpdump
Capture retransmissions and connection churn at the NIC level, correlate them with application retry counters, and size backoff correctly before disabling retries.
Debug Webhook HMAC Signature Mismatch
Compare the raw request body bytes used for HMAC signing against the bytes received, catching re-serialisation and encoding drift.
Catch Breaking OpenAPI Changes Before Release with oasdiff
Diff two OpenAPI documents with oasdiff in CI, fail the build on removed fields or narrowed types, and publish a human-readable changelog for review.
Choose Between Mocks, Stubs, and Fakes Deliberately
Pick test doubles by the question each test answers: stubs for state setup, mocks for interaction verification, fakes for realistic behavior.
Update a Huge Table in Safe Chunks
Rewrite millions of rows without a giant transaction by chunking on a key, committing per batch, tracking progress, and resuming after interruption.
Clone PostgreSQL Schema Without Data
Use pg_dump schema-only output to scaffold a staging database that matches production structure for safe query planning tests.
Colorize CLI Output with ANSI Codes
Add ANSI colour to CLI output only when the stream is a terminal and NO_COLOR is unset, respecting user preference.
Compare MySQL Query Plans Before and After an Index
Use EXPLAIN ANALYZE to measure real row counts and timing per step, then prove an index actually changed the plan instead of guessing.
Configure Docker Container Log Rotation Before It Fills the Disk
Set json-file log driver rotation options per container or daemon-wide, verify max-size and max-file take effect, and alert on remaining disk.
Configure SSH Bastion Jumps and Connection Multiplexing
Centralize jump-host access with ProxyJump, reuse connections with ControlMaster, and keep per-host keys instead of a shared bastion credential.
Harden a systemd Service Against Crashes and Reboots
Set Restart, watchdog, and resource limits on a systemd unit so crashes self-heal, hangs get killed, and boot ordering is explicit.
Configure External Uptime Probes That Users Agree With
Probe from outside the datacenter on the real user path, alert on consecutive failures with downtime tracking, and page on the right severity.
Convert a Large Table to Partitions Online
Attach a partitioned twin, dual-write or replicate into it, backfill by range, and swap names in one transaction with minimal lock time.
Debounce Search Input Without Losing Keystrokes or Requests
Debounce the expensive effect, not the input value, cancel in-flight requests on new input, and keep every keystroke responsive.
Debounce ResizeObserver Layout Work
Throttle layout work triggered by ResizeObserver so rapid resizes do not thrash the main thread.
Debug API Payload Schema Rejection
Reproduce a 422 payload rejection and use schema validation diagnostics to find the exact property path that fails.
Debug Cache Variation Leaks Between Users
Prove that a shared cache is serving one user personalized response to another by testing with two identities, then fix the missing Vary header.
Debug a Failing CORS Preflight with curl
Reproduce an OPTIONS preflight by hand with curl, read the Access-Control-* response headers, and fix the exact header the browser is complaining about.
Debug CSS Specificity Wars with the Cascade Layers Toolbox
Identify which rule actually wins and why, quantify specificity instead of guessing, and end arms races with layers and :where.
Debug GraphQL Persisted Query Misses
Resolve persisted-query-not-found errors by checking the APQ hash registry and hash generation between client and server.