More in Shell
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.
Count lines of code by extension
Shell
A quick census of a repository without installing a tool for it.
Make a shell script fail loudly
Shell
The four lines that turn a script from 'carries on after an error' into 'stops at the first problem'.
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.
Find the largest files with PowerShell
Shell
The Windows counterpart to du | sort | head.
Tail a log and colour only what matters
Shell
Follows a growing file and highlights errors and warnings, leaving the rest readable but quiet.
Serve the current directory over HTTP
Shell
Three ways to put a folder on localhost when you need to test something quickly.
Random picks
A minimal JSON Schema
Data Formats
Describes the shape of a payload so it can be validated before anything else touches it.
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.
Amend a commit without changing its message
Git
Adds forgotten files to the previous commit and leaves the message exactly as it was.
Search the whole history for a string
Git
Finds every commit whose diff added or removed a piece of text, including in files long since deleted.
Responsive images that do not blow the bandwidth budget
Web & CSS
srcset lets the browser pick; sizes tells it how wide the image will actually be rendered.
Remove every stopped container and dangling image
Containers
Reclaims disk after a week of building. The volume flag is separate because it is the one that loses data.
Result and the question mark operator in Rust
Systems
? propagates the error to the caller, which is why Rust functions rarely need explicit error branches.
Context with a timeout in Go
Systems
Cancels the request and everything downstream of it after two seconds. The defer is not optional.