More in Security
A starting Content-Security-Policy
Security
Blocks inline script and restricts everything to the origin. Tighten from here rather than loosening from nothing.
Compare secrets in constant time
Security
A plain === leaks how much of the token matched through its timing. This does not.
Generate a strong random secret
Security
For session keys and tokens. Never reach for a password generator or a UUID for this.
Check a file's checksum
Security
Verifies a download actually matches what the publisher signed, rather than trusting the transfer.
Security headers for an Express app
Security
The handful worth setting even when you are not using a framework that sets them for you.
Random picks
Upsert a row in SQLite
Databases
Inserts, or updates the existing row when the unique column already holds that value.
Async/await with a task group in Swift
Systems
Runs the downloads concurrently and collects them, with cancellation propagating to all of them.
Context with a timeout in Go
Systems
Cancels the request and everything downstream of it after two seconds. The defer is not optional.
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.
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.
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.
Check a malloc result in C
Systems
The allocation that nobody checks is the one that fails in production.
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.