More in Shell
Find the largest files with PowerShell
Shell
The Windows counterpart to du | sort | head.
Serve the current directory over HTTP
Shell
Three ways to put a folder on localhost when you need to test something quickly.
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.
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'.
Find the largest files under a directory
Shell
Sorts everything beneath the working directory by real disk usage and shows the twenty worst offenders.
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.
Count lines of code by extension
Shell
A quick census of a repository without installing a tool for it.
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.
Random picks
Rewrite a CSV column with perl
Text Processing
A one-liner that upper-cases the second field of every row, leaving the rest alone.
A dataclass with validation
Python
__post_init__ runs after the generated constructor, which is where cheap invariants belong.
Generate a strong random secret
Security
For session keys and tokens. Never reach for a password generator or a UUID for this.
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.
Group rows into a JSON array
Databases
Returns one row per author with their posts nested, instead of a join that repeats the author on every row.
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.
Exhaustiveness check on a switch
TypeScript
Assigning to never makes the compiler fail the build when a new union member is added and left unhandled.
A minimal JSON Schema
Data Formats
Describes the shape of a payload so it can be validated before anything else touches it.