Snippets
SNP 001–153
Loosely organized collection of code snippets. Maybe you'll find something useful here.
Showing 20 of 153 snippets
-
SNP113
Check when an SSL certificate expires from the terminal
Before the browser warning does it for you.
4 lines of sh in 3 blocks, 6 lines of explanation.
#531 -
SNP112
ISG aging rules in Stati
Rebuild new posts often and old ones rarely, and the catch on a static host.
12 lines of ts in 1 block, 13 lines of explanation.
#61B -
SNP111
Sweetie 16 as CSS variables
The palette this site is coloured with, ready to paste into a stylesheet.
18 lines of css in 1 block, 6 lines of explanation.
#25B -
SNP110
Find which process uses a port on Windows
The Windows version of lsof -i :3000.
3 lines of ps in 3 blocks, 4 lines of explanation.
#A14 -
SNP109
stati invalidate cheat sheet
Clear Stati's build cache by tag, path, glob or age, and what each query really matches.
17 lines of sh in 1 block, 10 lines of explanation with 4 notes.
#942 -
SNP108
Purge the Cloudflare cache from the terminal
After a deploy, make Cloudflare forget the old pages, without clicking through the dashboard.
5 lines of sh in 2 blocks, 5 lines of explanation.
#3B6 -
SNP107
Open external links in a new tab the right way
What target="_blank" needs next to it, and whether it needs anything anymore.
4 lines of html in 2 blocks, 6 lines of explanation.
#149 -
SNP106
Make some properties optional in TypeScript
Partial makes everything optional, which is rarely what you want. Here is the targeted version.
13 lines of ts in 2 blocks, 3 lines of explanation.
#B25 -
SNP105
Breadcrumbs from stati.nav
getBreadcrumbs() starts at the page's own folder. findNode() gives the whole trail.
27 lines of eta in 2 blocks, 9 lines of explanation.
#591 -
SNP104
Run a Node app as a systemd service
Start on boot, restart on crash, logs in journalctl. No pm2 needed.
20 lines of ini and sh in 2 blocks, 6 lines of explanation.
#64B -
SNP103
Scale pixel art video without blur in ffmpeg
Recording a 320 × 180 game and uploading it at 1080p without the smear.
2 lines of sh in 2 blocks, 5 lines of explanation.
#359 -
SNP102
Seeded random numbers in JavaScript
Math.random() can't be seeded. For procedural levels you need one that can.
11 lines of js in 1 block, 5 lines of explanation.
#512 -
SNP101
Dynamic Tailwind classes in Stati
A class built from a variable never reaches Tailwind's scanner, unless stati.propValue() writes it down.
17 lines of eta, js and json in 3 blocks, 12 lines of explanation.
#B63 -
SNP100
tmux basics
Start a long job on a server, close the laptop, come back to it later.
3 lines of sh in 2 blocks, 7 lines of explanation.
#2B6 -
SNP099
Clean up event listeners in useEffect
The resize listener that stayed alive after the component was gone, and how to not do that.
14 lines of jsx in 2 blocks, 5 lines of explanation.
#A51 -
SNP098
Load a script only on some pages in Stati
Stati's TypeScript bundles with include and exclude, and how their patterns match.
19 lines of ts and eta in 2 blocks, 11 lines of explanation with 4 notes.
#42A -
SNP097
Switch AWS CLI profiles
Work and personal accounts in one terminal without mixing them up.
5 lines of sh in 4 blocks, 6 lines of explanation.
#935 -
SNP096
Resume a broken download with curl or wget
The 8 GB ISO died at 97%. Don't start over.
2 lines of sh in 2 blocks, 6 lines of explanation.
#163 -
SNP095
jq basics
Read, filter and reshape JSON in the terminal.
7 lines of sh in 3 blocks, 6 lines of explanation.
#4B2 -
SNP094
Upsert in PostgreSQL
Insert a row, or update it if it already exists, in one statement.
6 lines of sql in 2 blocks, 5 lines of explanation.
#591
No snippets match this filter.