More in Shell
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'.
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.
Find the largest files with PowerShell
Shell
The Windows counterpart to du | sort | head.
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.
Tail a log and colour only what matters
Shell
Follows a growing file and highlights errors and warnings, leaving the rest readable but quiet.
Delete files older than thirty days
Shell
Prunes an archive directory without touching anything recent. Run it with -print first to see what would go.
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.
Random picks
A semantic, accessible form field
Web & CSS
The label is tied to the input by id, and the hint is announced with it via aria-describedby.
Delete duplicate rows, keeping the oldest
Databases
Uses a window function to number the duplicates and removes everything but the first of each group.
Debounce without pulling in a library
JavaScript
Twelve lines covering the case most projects add a dependency for, including cancelling a call that has not fired yet.
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.
Deep clone a value
JavaScript
structuredClone handles Dates, Maps, Sets and cycles, which JSON round-tripping quietly destroys.
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.
Make some properties optional
TypeScript
Composes the built-in helpers rather than writing a second interface that will drift from the first.