Snippets
SNP 001–153
Loosely organized collection of code snippets. Maybe you'll find something useful here.
Showing 20 of 153 snippets
-
SNP133
Export a sprite sheet from Aseprite's command line
Put the export in a script so every save of the .aseprite file can rebuild the sheet.
3 lines of sh in 2 blocks, 9 lines of explanation with 4 notes.
#246 -
SNP132
Lerp and clamp
Two one-liners every game and animation ends up needing.
5 lines of js in 3 blocks, 8 lines of explanation.
#935 -
SNP131
YAML multi-line strings
The pipe, the greater-than sign and the "chomping" indicators, once and for all.
13 lines of yaml in 2 blocks, 6 lines of explanation.
#4B2 -
SNP130
Find the slowest pages in a Stati build
Build metrics, the HTML report, and two jq one-liners.
8 lines of sh in 2 blocks, 13 lines of explanation.
#316 -
SNP129
Crisp pixel art on a canvas
The canvas smooths scaled sprites too. Turn it off, in two places.
9 lines of js and css in 2 blocks, 6 lines of explanation.
#513 -
SNP128
Find the commit that broke things with git bisect
Binary search through history, so 200 commits take 8 steps.
7 lines of sh in 4 blocks, 7 lines of explanation.
#294 -
SNP127
LLM prompt for reviewing a pull request
A second pair of eyes before you ask a human for theirs.
22 lines of md in 1 block, 3 lines of explanation.
#53B -
SNP126
Pages from a CMS in Stati
Write the CMS's posts as Markdown before the build starts. A hook is too late.
31 lines of js and json in 2 blocks, 8 lines of explanation.
#A25 -
SNP125
Run a throwaway container with the current folder mounted
Try a tool, a Node version or a Python version without installing anything.
2 lines of sh in 2 blocks, 10 lines of explanation with 4 notes.
#A45 -
SNP124
Rerun a command whenever a file changes
A poor man's watch mode for anything that doesn't have one.
3 lines of sh in 3 blocks, 6 lines of explanation.
#316 -
SNP123
Update a table from another table
Copy values across tables with a join, in MySQL, MariaDB and PostgreSQL.
9 lines of sql in 2 blocks, 5 lines of explanation.
#952 -
SNP122
Load .env files in Node without a package
dotenv is built into Node now.
2 lines of sh in 2 blocks, 7 lines of explanation.
#42A -
SNP121
Compute page data in beforeAll, not beforeRender
A Stati hook that writes front matter in beforeRender makes those pages rebuild on every build.
20 lines of js in 2 blocks, 12 lines of explanation.
#471 -
SNP120
Reverse proxy a Node app with nginx
Your app listens on 3000, the world talks to nginx on 443.
18 lines of nginx and sh in 2 blocks, 3 lines of explanation.
#593 -
SNP119
Copy your public key to a server
One command instead of pasting into authorized_keys by hand.
3 lines of sh in 3 blocks, 5 lines of explanation.
#1B5 -
SNP118
Lazy load images without JavaScript
Two attributes and the browser handles it.
2 lines of html in 2 blocks, 7 lines of explanation.
#639 -
SNP117
Keep Stati's build cache between CI runs
Cache .stati and dist together, or the next build starts from nothing anyway.
15 lines of yaml in 1 block, 11 lines of explanation.
#235 -
SNP116
Mermaid sequence diagram quick reference
The handful of arrows and blocks I keep looking up.
14 lines of mmd in 1 block, 7 lines of explanation with 5 notes.
#4B1 -
SNP115
chmod numbers explained
What 755 and 644 actually mean, so you stop copying them blindly.
3 lines of sh in 1 block, 16 lines of explanation.
#26B -
SNP114
Rename files in bulk with Python
A pathlib loop beats fighting with the shell's rename command every time.
9 lines of py in 1 block, 5 lines of explanation.
#942
No snippets match this filter.