More in Shell
Find the largest files with PowerShell
Shell
The Windows counterpart to du | sort | head.
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.
Serve the current directory over HTTP
Shell
Three ways to put a folder on localhost when you need to test something quickly.
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.
Show which process is holding a port
Shell
Answers 'address already in use' without guessing.
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.
Random picks
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.
A test that fails for the right reason
Testing
Assert on the message, not merely that something threw. A typo raising TypeError would otherwise pass.
Find what is taking up space in an image
Containers
Prints the size each layer adds, which usually points straight at the offending RUN line.
Follow redirects and show only the headers
Networking
Traces a redirect chain to its destination without downloading the body.
A README that people actually read
Data Formats
The order matters more than the length: what it is, how to run it, how to develop on it.
Read a file into a string in Go
Systems
os.ReadFile replaced ioutil.ReadFile in 1.16 and is the one-liner for small files.
Context with a timeout in Go
Systems
Cancels the request and everything downstream of it after two seconds. The defer is not optional.
Amend a commit without changing its message
Git
Adds forgotten files to the previous commit and leaves the message exactly as it was.