Snippets

SNP 001–153

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

Showing 20 of 153 snippets

  1. SNP093

    Search a Stati site in the browser

    Stati writes the search index at build time. A few dozen lines of TypeScript search it.

    39 lines of ts and html in 2 blocks, 11 lines of explanation with 3 notes.

  2. SNP092

    Run TypeScript directly with Node

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

    2 lines of sh and ts in 2 blocks, 7 lines of explanation.

  3. SNP091

    LLM prompt for writing commit messages

    Paste a diff, get a commit message that follows the conventions and says why, not just what.

    12 lines of md in 1 block, 3 lines of explanation.

    #35B llm prompt git
  4. SNP090

    Anchors hidden under a sticky header

    Clicking a table of contents link scrolls the heading right under your fixed header. One property fixes it.

    9 lines of css in 2 blocks, 4 lines of explanation.

    #B13 css
  5. SNP089

    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.

    11 lines of yaml and ts in 2 blocks, 12 lines of explanation.

    #26B stati seo
  6. SNP088

    Pick a random element in GDScript

    Random loot, random lines, random enemies. Godot 4 has it built in.

    6 lines of gd in 2 blocks, 5 lines of explanation.

    #245 godot gamedev
  7. SNP087

    Delete all branches that are already merged

    Thirty old feature branches in git branch? Clean house in one line.

    1 line of sh in 1 block, 6 lines of explanation.

    #694 git
  8. SNP086

    Sync a folder to S3

    Upload a built site to a bucket, sending only what changed.

    5 lines of sh in 2 blocks, 5 lines of explanation.

    #3B1 aws cmd
  9. SNP085

    An RSS feed for one folder in Stati

    Why contentPatterns needs a **/ in front, and the link Stati doesn't add for you.

    14 lines of ts and html in 2 blocks, 14 lines of explanation with 4 notes.

    #349 stati rss
  10. SNP084

    __dirname in ES modules

    It's gone in ESM. Here is the replacement, and the newer, nicer one.

    9 lines of js in 3 blocks, 4 lines of explanation.

    #45A js node
  11. SNP083

    Tunnel to a remote database over SSH

    Use your local database tools on a server's database that isn't exposed to the internet.

    2 lines of sh in 2 blocks, 7 lines of explanation.

    #962 ssh sql cmd
  12. SNP082

    Fluid font sizes with clamp

    A heading that grows with the viewport between a minimum and a maximum, no media queries.

    3 lines of css in 1 block, 8 lines of explanation.

    #135 css
  13. SNP081

    Your own title format with Stati's SEO tags

    Write the <title> yourself and let Stati fill in the rest of the head.

    10 lines of eta and yaml in 2 blocks, 12 lines of explanation.

    #152 stati seo
  14. SNP080

    List listening ports on linux

    What is this server actually exposing to the world?

    1 line of sh in 1 block, 9 lines of explanation with 4 notes.

  15. SNP079

    v-model on your own component with defineModel

    Vue 3.4 made two-way binding on custom components a one-liner.

    8 lines of vue in 2 blocks, 5 lines of explanation.

    #B41 js vue
  16. SNP078

    A nested table of contents in Stati

    stati.page.toc is a flat list. A few lines of Eta turn it into nested lists.

    28 lines of eta in 1 block, 8 lines of explanation.

    #A47 stati eta
  17. SNP077

    Delete duplicate rows but keep one

    Clean up a table after finding the duplicates, keeping the oldest of each.

    10 lines of sql in 3 blocks, 6 lines of explanation.

    #396 sql mariadb
  18. SNP076

    Environment variables in Nuxt

    Runtime config, the NUXT_ prefix and which values end up in the browser.

    10 lines of ts and sh in 2 blocks, 7 lines of explanation.

    #614 js nuxt
  19. SNP075

    Callout boxes in Stati Markdown

    GitHub's > [!NOTE] syntax as a small markdown-it rule.

    39 lines of js, ts, md and css in 4 blocks, 4 lines of explanation.

  20. SNP074

    Upscale pixel art with ImageMagick without blur

    Turn a 32 px sprite into a 256 px image where every pixel stays a square.

    2 lines of sh in 2 blocks, 7 lines of explanation.