Snippets

SNP 001–153

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

Showing 20 of 153 snippets

  1. 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 cmd ssl linux
  2. 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 stati isg
  3. 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.

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

  5. 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 stati cmd
  6. 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.

  7. 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 html webdev
  8. 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 typescript
  9. 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 stati eta
  10. 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.

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

  12. 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 js gamedev
  13. 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 stati css
  14. 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 cmd tmux linux
  15. 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 js react
  16. 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.

  17. 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 aws cmd
  18. 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 cmd linux
  19. SNP095

    jq basics

    Read, filter and reshape JSON in the terminal.

    7 lines of sh in 3 blocks, 6 lines of explanation.

    #4B2 jq cmd
  20. 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 sql postgres