More in Testing
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.
Table-driven tests in Go
Testing
The idiomatic Go pattern: a slice of cases and a subtest per entry, each named so failures are readable.
Freeze time in a test
Testing
Node's mock timers make anything date-dependent deterministic without injecting a clock everywhere.
Random picks
Reset a Postgres sequence after a bulk import
Databases
Copying rows with explicit ids leaves the identity sequence behind, so the next insert collides with an existing row.
Compare secrets in constant time
Security
A plain === leaks how much of the token matched through its timing. This does not.
An RSS feed skeleton
Data Formats
The minimum a reader needs. Dates must be RFC 822, which is the part most generators get wrong.
Find the largest files under a directory
Shell
Sorts everything beneath the working directory by real disk usage and shows the twenty worst offenders.
Const assertion for a lookup table
TypeScript
`as const` keeps the literal types, so the derived union is the actual keys rather than string.
Centre a box, two ways
Web & CSS
Grid is one line. Flex is three and gives you control over the axes separately.
Shell into a running container
Containers
Falls back to sh, since slim images often have no bash.
Table sizes, largest first
Databases
Where the disk actually went, including indexes and TOAST.