More in Databases
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.
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.
Find slow queries in Postgres
Databases
Ranks statements by total time spent. Needs the pg_stat_statements extension enabled.
Table sizes, largest first
Databases
Where the disk actually went, including indexes and TOAST.
Upsert a row in SQLite
Databases
Inserts, or updates the existing row when the unique column already holds that value.
Delete duplicate rows, keeping the oldest
Databases
Uses a window function to number the duplicates and removes everything but the first of each group.
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.
Random picks
Walk a directory tree lazily
Python
pathlib keeps the paths as objects rather than strings, so joining and suffix checks stay readable.
Compose file with a healthcheck and dependency order
Containers
Makes the app wait until Postgres actually answers, not merely until its container has started.
Result and the question mark operator in Rust
Systems
? propagates the error to the caller, which is why Rust functions rarely need explicit error branches.
Relative time without a date library
JavaScript
Turns a timestamp into 'three days ago' using the built-in formatter.
Truncate text to a number of lines
Web & CSS
Ellipsis after two lines. The -webkit- prefixes are still required despite being supported everywhere.
Serve the current directory over HTTP
Shell
Three ways to put a folder on localhost when you need to test something quickly.
Hash and verify a password in PHP
PHP
password_hash picks the algorithm and the salt. Never store anything a hash function can reverse.
Stop tracking a file without deleting it
Git
For the config file that should never have been committed. Add it to .gitignore afterwards.