More in Python
Time a block of code
Python
A context manager that prints how long its body took, without scattering time.perf_counter calls through the function.
Parse arguments without a dependency
Python
argparse covers subcommands, types and help text, which is more than most scripts ever need.
Retry with exponential backoff and jitter
Python
Backs off on each failure and spreads retries out, so a recovering service is not hit by every client at once.
Read a large file without loading it into memory
Python
Iterating a file object yields one line at a time, which is the difference between a constant footprint and an OOM.
A dataclass with validation
Python
__post_init__ runs after the generated constructor, which is where cheap invariants belong.
Merge dictionaries
Python
The | operator returns a new dict; |= updates in place. Later keys win in both.
Chunk an iterable into fixed-size batches
Python
itertools.batched on 3.12 and later; the islice version works everywhere and never materialises the whole input.
Random picks
Group and count in Ruby
Ruby
tally does the counting; group_by keeps the members when you need them.
Table sizes, largest first
Databases
Where the disk actually went, including indexes and TOAST.
Multi-stage Dockerfile for a Node service
Containers
Builds with the full toolchain, ships only production dependencies, and runs as a non-root user.
Check a malloc result in C
Systems
The allocation that nobody checks is the one that fails in production.
A README that people actually read
Data Formats
The order matters more than the length: what it is, how to run it, how to develop on it.
Amend a commit without changing its message
Git
Adds forgotten files to the previous commit and leaves the message exactly as it was.
Open an SSH tunnel to a remote database
Networking
Forwards a local port through a bastion so a client can connect as if the database were local.
A GitHub Actions workflow for a Node project
Build & CI
Caches the dependency install, runs on a matrix of versions, and fails the build on a lint error.