Recipes
Step-by-step solutions for real development tasks.
699 published
Page 13 of 20
Reduce Go Allocations with sync.Pool
Reuse hot short-lived buffers through sync.Pool to cut garbage collection pressure on high-throughput paths.
Serve Responsive Images with srcset
Provide width descriptors and modern formats so devices download the smallest adequate image.
Lazy-Load Below-the-Fold Images and Widgets Correctly
Audit what actually ships in the initial payload, apply native lazy-loading plus fetchpriority hints, and verify with a network waterfall.
Package a Node CLI with a bin Entry
Publish a Node CLI with a bin mapping and executable shebang so it installs as a global command with the right name.
Parallelize Playwright E2E with Shards and Workers
Split E2E specs across CI machines and in-process workers, isolate each workers browser context, and keep total runtime under a budget.
Parallelize Shell Jobs with xargs -P and Preserve Ordering
Fan out independent commands across CPU cores with xargs -P, keep outputs attributable, and recombine results in input order.
Parallelize Vitest Across Threads
Tune the Vitest pool and per-file isolation so a large suite finishes faster without flaky shared-state failures.
Parametrize JUnit 5 Tests with a Method Source
Drive JUnit 5 parameterised tests from a method source or CSV so edge cases stay explicit and addable without new methods.
Parse CLI Flags Correctly in POSIX Shell with getopts
Handle short flags with arguments, distinguish missing from empty values, and produce actionable errors instead of silent defaults.
Parse a YAML Config in a CLI
Load a YAML config with schema validation and helpful error messages so a malformed file fails clearly rather than silently.
Write Partitioned Parquet Datasets
Write Parquet partitioned by a low-cardinality column so downstream queries prune partitions and scan far less data.
Pin Docker Base Images by Digest, Not by Tag
Resolve mutable tags to immutable digests, record them in the Dockerfile, and verify every rebuild starts from the exact same bytes.
Diagnose and Break a Postgres Lock Wait Chain
Query pg_locks and pg_stat_activity to expose the blocking session and its waiting victims, then decide to terminate, wait, or fix the transaction scope.
Prefetch Critical Resources with Resource Hints
Use preconnect and prefetch hints for the next likely navigation so critical resources arrive before they are requested.
Preflight Check Cluster Capacity
Compare requested resources against allocatable capacity so a deployment does not land pods in a permanently pending state.
Profile Column Cardinality Before Designing Storage
Measure distinct counts, null rates, and frequency skew per column, then let the data choose between enum, index, and partition designs.
Profile MongoDB Slow Queries and Read the Plan
Enable the profiler at slowms, read explain output for scanStage and index use, and add the compound index the plan says is missing.
Profile a Python Hot Function with cProfile
Use cProfile and pstats to rank functions by cumulative time and fix the real hot path instead of guessing.
Profile the Slowest Tests with Reporters
Rank tests by duration with a reporter so optimising the few slowest cases shortens the whole suite the most.
Protect Against CSRF with Double Submit
Use a same-site cookie plus a double-submit token so state-changing requests cannot be forged from another origin.
Protect a Redis Cache Against Stampede and Penetration
Guard a hot key with a mutex lock and stale-while-revalidate, and neutralize cache penetration for missing keys with short negative TTLs.
Prove SQL Injection Safeguards with Attack Tests
Inventory every query construction site, attack each with canonical payloads, and add regression tests that keep parameterization honest.
Quarantine Flaky Tests and Fix Them for Real
Detect flaky tests with repeat runs, move them to a quarantine suite that does not gate, diagnose the root cause, and graduate them back.
Unmask Flaky Tests by Rerunning the Suite
Run the suite repeatedly with shuffled order and fixed seeds, rank tests by failure variance, and quarantine only the proven offenders.
Read a Postgres Execution Plan and Fix the Slow Node
Run EXPLAIN ANALYZE, walk the plan tree node by node, compare estimated versus actual rows, and act on the node where the cost concentrates.
Rebuild a MongoDB Index Online
Rebuild a fragmented MongoDB index without blocking writes by leveraging rolling index builds on a replica set.
Redact PII in Application Logs
Add structured log redaction for emails, tokens, and card numbers so sensitive data never lands in log storage.
Reduce CLS by Measuring Shifts Before Fixing Them
Record layout-shift entries with sources, rank which elements move and when, then reserve exact space instead of guessing at CSS.
Reduce N+1 Queries with a DataLoader
Batch and cache per-request lookups with a DataLoader so list endpoints stop issuing one query per item.
Reduce Render-Blocking CSS
Inline critical CSS, defer the rest, and split stylesheets so the first paint is not blocked by a large global stylesheet.
Record and Replay HTTP Traffic with mitmproxy
Capture real client traffic into a flow file with mitmproxy, edit selected requests, and replay them deterministically against staging to reproduce bugs.
Reproduce an API Timeout with curl Trace
Break a slow API call into DNS, connect, TLS, and first-byte timings so you can prove which phase consumes the latency budget.
Restore a Single Table from a Full Database Dump
Extract one table from a pg_dump archive with pg_restore, land it in staging, verify counts and checksums, then move only the needed rows.
Restrict CORS to an Origin Allowlist
Replace wildcard CORS with a strict origin allowlist that also handles credentials and preflight safely.
Enforce Pod Security Admission
Apply the restricted Pod Security Standard namespace by namespace so privileged pods are rejected at admission.
Review and Slim an Overgrown Snapshot Suite
Audit snapshot sizes and update frequency, convert intent-bearing cases to explicit assertions, and keep snapshots only where structure is the contract.