Snippets

SNP 001–148

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

Showing 20 of 148 snippets

  1. SNP 068 #B26

    Exhaustive switch in TypeScript

    Make the compiler complain when you add a case to a union and forget to handle it.

  2. SNP 067 #694

    Redirect from a route middleware in Nuxt

    Send people who aren't logged in to the login page before the page even renders.

  3. SNP 066 #742

    Serve Stati's clean URLs from nginx

    /about is about.html. The try_files line, the trailing slash redirect and the 404 page.

  4. SNP 065 #513

    Check if a port is open from the terminal

    Is it the firewall, the service, or me?

  5. SNP 064 #A42

    Stop tracking a file without deleting it

    You committed .env or a build folder. Get it out of git but keep it on disk.

  6. SNP 063 #13B

    Class names with stati.propValue

    Stati's own classnames, for class lists with conditions in them.

  7. SNP 062 #295

    Find the processes eating your memory

    The server is swapping. Who's responsible?

  8. SNP 061 #351

    Format dates without a library

    Intl.DateTimeFormat does most of what you used moment or date-fns for.

  9. SNP 060 #495

    Custom template filters in Stati

    A date format and a reading time, registered once in the config and called like functions.

  10. SNP 059 #64B

    Sign your commits with your SSH key

    Verified badges on GitHub without setting up GPG.

  11. SNP 058 #B12

    Send JSON with curl

    POST a JSON body to an API from the terminal, and read the answer.

  12. SNP 057 #641

    Pick a layout per page in Stati

    How Stati finds a page's layout, and the typo it won't tell you about.

  13. SNP 056 #496

    Group an array by a key

    Object.groupBy is finally a thing. Here it is, with the fallback for older runtimes.

  14. SNP 055 #539

    Pixel-perfect settings in Godot 4

    The project settings that keep pixel art sharp when the window is scaled.

  15. SNP 054 #1B3

    Different git identity for work and personal projects

    Stop committing to work repos with your personal email, automatically.

  16. SNP 053 #359

    Partials with props in Stati

    A card component that takes data, and the one line that keeps it from breaking every page.

  17. SNP 052 #25A

    Fetch with a timeout

    fetch() waits forever by default. Give up after a few seconds.

  18. SNP 051 #941

    Crontab cheat sheet

    The five fields, the shortcuts and the two mistakes everybody makes.

  19. SNP 050 #B14

    Eta tags in Stati templates

    The three tags, the one variable, and the comment that breaks a template.

  20. SNP 049 #624

    Named stashes

    stash@{3} means nothing to anyone. Give your stashes names.