More in Databases
Add a column without locking the table
Databases
On Postgres 11 and later a nullable column with a default is a metadata-only change. Adding NOT NULL afterwards is the part that needs care.
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.
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.
Find slow queries in Postgres
Databases
Ranks statements by total time spent. Needs the pg_stat_statements extension enabled.
Delete duplicate rows, keeping the oldest
Databases
Uses a window function to number the duplicates and removes everything but the first of each group.
Which indexes is nobody using?
Databases
Lists indexes that have never been scanned, which are pure write cost. Check against a long uptime before dropping any.
Table sizes, largest first
Databases
Where the disk actually went, including indexes and TOAST.
Random picks
Make some properties optional
TypeScript
Composes the built-in helpers rather than writing a second interface that will drift from the first.
Generate a strong random secret
Security
For session keys and tokens. Never reach for a password generator or a UUID for this.
Undo the last commit but keep the changes
Git
Moves HEAD back one commit and leaves everything staged, which is what you usually want after committing too early.
Safe navigation and fetch in Ruby
Ruby
&. stops at nil; fetch raises rather than returning nil when a key is genuinely required.
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.
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.
Worker pool with a wait group in Go
Systems
Fixed number of goroutines draining a channel, with the group ensuring main waits for all of them.
Sum a column with awk
Text Processing
Adds the third field of every line and prints the total, ignoring anything non-numeric.