Snippets

SNP 001–148

Loosely organized collection of code snippets. Maybe you'll find something useful here.

Showing 20 of 148 snippets

  1. SNP 108 #3B6

    Purge the Cloudflare cache from the terminal

    After a deploy, make Cloudflare forget the old pages, without clicking through the dashboard.

  2. 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.

  3. SNP 106 #B25

    Make some properties optional in TypeScript

    Partial makes everything optional, which is rarely what you want. Here is the targeted version.

  4. SNP 105 #591

    Breadcrumbs from stati.nav

    getBreadcrumbs() starts at the page's own folder. findNode() gives the whole trail.

  5. SNP 104 #64B

    Run a Node app as a systemd service

    Start on boot, restart on crash, logs in journalctl. No pm2 needed.

  6. SNP 103 #359

    Scale pixel art video without blur in ffmpeg

    Recording a 320 × 180 game and uploading it at 1080p without the smear.

  7. SNP 102 #512

    Seeded random numbers in JavaScript

    Math.random() can't be seeded. For procedural levels you need one that can.

  8. 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.

  9. SNP 100 #2B6

    tmux basics

    Start a long job on a server, close the laptop, come back to it later.

  10. 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.

  11. 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.

  12. SNP 097 #935

    Switch AWS CLI profiles

    Work and personal accounts in one terminal without mixing them up.

  13. SNP 096 #163

    Resume a broken download with curl or wget

    The 8 GB ISO died at 97%. Don't start over.

  14. SNP 095 #4B2

    jq basics

    Read, filter and reshape JSON in the terminal.

  15. SNP 094 #591

    Upsert in PostgreSQL

    Insert a row, or update it if it already exists, in one statement.

  16. 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.

  17. SNP 092 #A24

    Run TypeScript directly with Node

    No build step, no ts-node, for scripts and quick experiments.

  18. 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.

  19. 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.

  20. 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.