More in Shell
Find the largest files with PowerShell
Shell
The Windows counterpart to du | sort | head.
Watch a command until it succeeds
Shell
Retries every two seconds and stops the moment the command exits zero. Useful while waiting for a service to come up.
Rename a batch of files with a pattern
Shell
Strips a prefix from every file in a directory using shell parameter expansion, no rename utility required.
Serve the current directory over HTTP
Shell
Three ways to put a folder on localhost when you need to test something quickly.
Find the largest files under a directory
Shell
Sorts everything beneath the working directory by real disk usage and shows the twenty worst offenders.
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.
Count lines of code by extension
Shell
A quick census of a repository without installing a tool for it.
Tail a log and colour only what matters
Shell
Follows a growing file and highlights errors and warnings, leaving the rest readable but quiet.
Random picks
Sort and deduplicate lines by a field
Text Processing
Sorts on the second column and keeps the first row of each group.
An RSS feed skeleton
Data Formats
The minimum a reader needs. Dates must be RFC 822, which is the part most generators get wrong.
Replace text across a whole project
Text Processing
ripgrep finds the files, sed edits them in place. The dry run first is not optional.
Records and pattern matching in Java
Systems
A record plus a switch pattern removes most of the ceremony this used to take.
Check a malloc result in C
Systems
The allocation that nobody checks is the one that fails in production.
Async/await with a task group in Swift
Systems
Runs the downloads concurrently and collects them, with cancellation propagating to all of them.
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.
Reset a Postgres sequence after a bulk import
Databases
Copying rows with explicit ids leaves the identity sequence behind, so the next insert collides with an existing row.