More in Shell
Serve the current directory over HTTP
Shell
Three ways to put a folder on localhost when you need to test something quickly.
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'.
Tail a log and colour only what matters
Shell
Follows a growing file and highlights errors and warnings, leaving the rest readable but quiet.
Find the largest files under a directory
Shell
Sorts everything beneath the working directory by real disk usage and shows the twenty worst offenders.
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.
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.
Show which process is holding a port
Shell
Answers 'address already in use' without guessing.
Find the largest files with PowerShell
Shell
The Windows counterpart to du | sort | head.
Random picks
Show what a merge will do before doing it
Git
Lists the commits and the files a merge would bring in, so a surprise is less likely.
Freeze time in a test
Testing
Node's mock timers make anything date-dependent deterministic without injecting a clock everywhere.
Responsive grid without media queries
Web & CSS
auto-fill with minmax reflows on its own, so the column count follows the container rather than a breakpoint list.
A starting Content-Security-Policy
Security
Blocks inline script and restricts everything to the origin. Tighten from here rather than loosening from nothing.
Multi-stage Dockerfile for a Node service
Containers
Builds with the full toolchain, ships only production dependencies, and runs as a non-root user.
Escape output in a PHP template
PHP
htmlspecialchars with the flags spelled out, because the defaults have changed between versions.
Undo the last commit but keep the changes
Git
Moves HEAD back one commit and leaves everything staged, which is what you usually want after committing too early.
Relative time without a date library
JavaScript
Turns a timestamp into 'three days ago' using the built-in formatter.