More in PHP
Random picks
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.
Const assertion for a lookup table
TypeScript
`as const` keeps the literal types, so the derived union is the actual keys rather than string.
Tail a log and colour only what matters
Shell
Follows a growing file and highlights errors and warnings, leaving the rest readable but quiet.
A starting Content-Security-Policy
Security
Blocks inline script and restricts everything to the origin. Tighten from here rather than loosening from nothing.
Group rows into a JSON array
Databases
Returns one row per author with their posts nested, instead of a join that repeats the author on every row.
Pin a dependency to an exact version
Build & CI
Caret ranges are how a build that passed last week fails today. Exact versions plus a lockfile remove the surprise.
A GitHub Actions workflow for a Node project
Build & CI
Caches the dependency install, runs on a matrix of versions, and fails the build on a lint error.
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.