Snippets
SNP 001–148
Loosely organized collection of code snippets. Maybe you'll find something useful here.
Showing 20 of 148 snippets
-
SNP 108
#3B6
Purge the Cloudflare cache from the terminal
After a deploy, make Cloudflare forget the old pages, without clicking through the dashboard.
-
SNP 107
#149
Open external links in a new tab the right way
What target="_blank" needs next to it, and whether it needs anything anymore.
-
SNP 106
#B25
Make some properties optional in TypeScript
Partial makes everything optional, which is rarely what you want. Here is the targeted version.
-
SNP 105
#591
Breadcrumbs from stati.nav
getBreadcrumbs() starts at the page's own folder. findNode() gives the whole trail.
-
SNP 104
#64B
Run a Node app as a systemd service
Start on boot, restart on crash, logs in journalctl. No pm2 needed.
-
SNP 103
#359
Scale pixel art video without blur in ffmpeg
Recording a 320 × 180 game and uploading it at 1080p without the smear.
-
SNP 102
#512
Seeded random numbers in JavaScript
Math.random() can't be seeded. For procedural levels you need one that can.
-
SNP 101
#B63
Dynamic Tailwind classes in Stati
A class built from a variable never reaches Tailwind's scanner, unless stati.propValue() writes it down.
-
SNP 100
#2B6
tmux basics
Start a long job on a server, close the laptop, come back to it later.
-
SNP 099
#A51
Clean up event listeners in useEffect
The resize listener that stayed alive after the component was gone, and how to not do that.
-
SNP 098
#42A
Load a script only on some pages in Stati
Stati's TypeScript bundles with include and exclude, and how their patterns match.
-
SNP 097
#935
Switch AWS CLI profiles
Work and personal accounts in one terminal without mixing them up.
-
SNP 096
#163
Resume a broken download with curl or wget
The 8 GB ISO died at 97%. Don't start over.
-
SNP 095
#4B2
jq basics
Read, filter and reshape JSON in the terminal.
-
SNP 094
#591
Upsert in PostgreSQL
Insert a row, or update it if it already exists, in one statement.
-
SNP 093
#9B5
Search a Stati site in the browser
Stati writes the search index at build time. A few dozen lines of TypeScript search it.
-
SNP 092
#A24
Run TypeScript directly with Node
No build step, no ts-node, for scripts and quick experiments.
-
SNP 091
#35B
LLM prompt for writing commit messages
Paste a diff, get a commit message that follows the conventions and says why, not just what.
-
SNP 090
#B13
Anchors hidden under a sticky header
Clicking a table of contents link scrolls the heading right under your fixed header. One property fixes it.
-
SNP 089
#26B
Keep a page out of search engines in Stati
noindex, the sitemap and the site's own search, from the page's front matter and one config line.
No snippets match this filter.