More in Security
Generate an SSH key and add it to the agent
Security
Ed25519 rather than RSA: shorter, faster, and no key-size decision to get wrong.
Security headers for an Express app
Security
The handful worth setting even when you are not using a framework that sets them for you.
Check a file's checksum
Security
Verifies a download actually matches what the publisher signed, rather than trusting the transfer.
Compare secrets in constant time
Security
A plain === leaks how much of the token matched through its timing. This does not.
A starting Content-Security-Policy
Security
Blocks inline script and restricts everything to the origin. Tighten from here rather than loosening from nothing.
Random picks
Make some properties optional
TypeScript
Composes the built-in helpers rather than writing a second interface that will drift from the first.
Read a large file without loading it into memory
Python
Iterating a file object yields one line at a time, which is the difference between a constant footprint and an OOM.
Group and count in Ruby
Ruby
tally does the counting; group_by keeps the members when you need them.
Replace text across a whole project
Text Processing
ripgrep finds the files, sed edits them in place. The dry run first is not optional.
Fetch with a timeout
JavaScript
fetch has no timeout of its own. AbortSignal.timeout is the short way to give it one.
Show which process is holding a port
Shell
Answers 'address already in use' without guessing.
Truncate text to a number of lines
Web & CSS
Ellipsis after two lines. The -webkit- prefixes are still required despite being supported everywhere.
Table sizes, largest first
Databases
Where the disk actually went, including indexes and TOAST.