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.

~30 min
performance · go · memory

Serve Responsive Images with srcset

Provide width descriptors and modern formats so devices download the smallest adequate image.

~30 min
frontend · performance · images

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.

~25 min
performance · frontend · web-vitals

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.

~25 min
cli · nodejs · packaging

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.

~30 min
testing · e2e · playwright

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.

~20 min
cli · shell · parallelism

Parallelize Vitest Across Threads

Tune the Vitest pool and per-file isolation so a large suite finishes faster without flaky shared-state failures.

~30 min
testing · performance · ci

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.

~30 min
testing · java · junit

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.

~25 min
cli · shell · argument-parsing

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.

~30 min
cli · configuration · yaml

Write Partitioned Parquet Datasets

Write Parquet partitioned by a low-cardinality column so downstream queries prune partitions and scan far less data.

~30 min
data · parquet · analytics

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.

~20 min
deploy · docker · supply-chain

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.

~25 min
database · postgres · operations

Prefetch Critical Resources with Resource Hints

Use preconnect and prefetch hints for the next likely navigation so critical resources arrive before they are requested.

~25 min
performance · frontend · web

Preflight Check Cluster Capacity

Compare requested resources against allocatable capacity so a deployment does not land pods in a permanently pending state.

~25 min
kubernetes · ops · capacity

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.

~30 min
data · schema-design · profiling

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.

~30 min
database · mongodb · performance

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.

~30 min
performance · python · profiling

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.

~30 min
testing · performance · ci

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.

~30 min
security · web · csrf

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.

~35 min
database · redis · resilience

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.

~35 min
security · database · testing

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.

~35 min
testing · ci · flakiness

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.

~40 min
testing · ci · flaky-tests

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.

~30 min
database · postgres · performance

Rebuild a MongoDB Index Online

Rebuild a fragmented MongoDB index without blocking writes by leveraging rolling index builds on a replica set.

~45 min
mongodb · database · maintenance

Redact PII in Application Logs

Add structured log redaction for emails, tokens, and card numbers so sensitive data never lands in log storage.

~30 min
security · logging · privacy

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.

~30 min
performance · frontend · web-vitals

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.

~35 min
performance · database · graphql

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.

~30 min
performance · frontend · css

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.

~35 min
api · debugging · testing

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.

~25 min
http · performance · debugging

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.

~40 min
database · postgres · operations

Restrict CORS to an Origin Allowlist

Replace wildcard CORS with a strict origin allowlist that also handles credentials and preflight safely.

~25 min
security · cors · api

Enforce Pod Security Admission

Apply the restricted Pod Security Standard namespace by namespace so privileged pods are rejected at admission.

~35 min
kubernetes · security · hardening

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.

~30 min
testing · snapshots · vitest