More in Python
Merge dictionaries
Python
The | operator returns a new dict; |= updates in place. Later keys win in both.
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.
Walk a directory tree lazily
Python
pathlib keeps the paths as objects rather than strings, so joining and suffix checks stay readable.
A dataclass with validation
Python
__post_init__ runs after the generated constructor, which is where cheap invariants belong.
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.
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
Fetch with a timeout
JavaScript
fetch has no timeout of its own. AbortSignal.timeout is the short way to give it one.
Find slow queries in Postgres
Databases
Ranks statements by total time spent. Needs the pg_stat_statements extension enabled.
Async/await with a task group in Swift
Systems
Runs the downloads concurrently and collects them, with cancellation propagating to all of them.
A Makefile that documents itself
Build & CI
Running make with no arguments prints every target that carries a comment.
Run a command on every file changed in a commit
Shell
Lints only what a commit touched, which is usually all you need in a pre-commit hook.
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.
Undo the last commit but keep the changes
Git
Moves HEAD back one commit and leaves everything staged, which is what you usually want after committing too early.
Inspect a TLS certificate from the command line
Networking
Prints the subject, issuer and validity dates without opening a browser.