Recipes
Step-by-step solutions for real development tasks.
699 published
Page 20 of 20
Add a Health Check Endpoint
Expose a liveness and readiness endpoint that checks critical dependencies with a timeout, so orchestrators can restart or remove unhealthy instances.
Add Idempotency Keys to a Write Endpoint
Accept an Idempotency-Key header, store the request fingerprint and response, and replay the original result for retries instead of creating duplicates.
Add Pre-commit Hooks for Lint and Tests
Install the pre-commit framework, run lint and fast tests before every commit, and keep hooks reproducible across the team instead of relying on manual discipline.
Propagate Request IDs Through Logs
Generate or accept a traceable request ID, attach it to every log line and response, and propagate it to downstream calls so one user action can be followed end to end.
Add a Content Security Policy with Nonces
Ship a restrictive Content Security Policy that blocks inline script injection, uses per-request nonces, and is verified without breaking legitimate assets.
Configure CORS with an Origin Allowlist
Allow only trusted browser origins, handle preflight requests correctly, and avoid the insecure combination of wildcard origins with credentials.
Recover a Deleted Git Branch
Use the reflog to find the last commit of a deleted local branch and recreate the branch before garbage collection removes the commit.
Undo a Bad Commit with git revert
Undo a commit on a shared branch by creating a new inverse commit, preserving history and avoiding the disruption of a force-push.
Implement Stable Cursor Pagination
Paginate a changing dataset with an encoded cursor instead of offsets, keeping results stable when rows are inserted or deleted between requests.
Resolve a Merge Conflict Without Losing Work
Inspect both sides of a conflict, choose or combine the intended changes, stage the result, and verify with tests before completing the merge.
Rotate a Leaked Secret Safely
Revoke a leaked credential, issue a replacement, deploy it through a secret manager, and purge the old value from history where your threat model requires it.
Set HTTP Cache Headers for Static Assets and HTML
Give fingerprinted assets a long immutable cache while forcing browsers and CDNs to revalidate HTML, preventing stale deployments without sacrificing repeat-visit performance.
Clean Up Local Commits with Interactive Rebase
Rewrite local commit history using git rebase --interactive to squash, reorder, or edit commits before sharing. Use this when preparing a clean pull request from messy WIP commits.
Speed Up Slow Queries with SQL Indexes
Diagnose slow SQL queries using EXPLAIN and add targeted indexes to reduce row scans from millions to dozens. Covers B-tree indexes, composite ordering, and when indexes hurt performance.
Create a Multi-Stage Dockerfile for Smaller Images
Use multi-stage Docker builds to compile your application in one stage and copy only the runtime artifacts into the final small image. This pattern can reduce image sizes by 10x or more.