More in Python
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.
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.
Parse arguments without a dependency
Python
argparse covers subcommands, types and help text, which is more than most scripts ever need.
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.
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.
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.
Random picks
Generate a strong random secret
Security
For session keys and tokens. Never reach for a password generator or a UUID for this.
Parameterised tests in Python
Testing
One test body, many cases, and a failure that names the case that broke.
Find the largest files with PowerShell
Shell
The Windows counterpart to du | sort | head.
Pretty-print and query JSON
Text Processing
jq for the common cases: reformat, pick a path, filter an array, and reshape.
RAII file handling in C++
Systems
The stream closes itself when it leaves scope, whether the function returns normally or throws.
Find the commit that introduced a bug
Git
Binary search across history. Mark a known good and a known bad commit and git narrows it down for you.
Show which process is holding a port
Shell
Answers 'address already in use' without guessing.
Table-driven tests in Go
Testing
The idiomatic Go pattern: a slice of cases and a subtest per entry, each named so failures are readable.