Snippets
SNP 001–153
Loosely organized collection of code snippets. Maybe you'll find something useful here.
Showing 20 of 153 snippets
-
SNP073
Add markdown-it plugins to Stati
Footnotes, containers and emoji, and the plugin that has to go through configure instead.
26 lines of sh, ts and md in 3 blocks, 12 lines of explanation with 4 notes.
#513 -
SNP072
Do something when an element scrolls into view
Lazy loading, fade-ins and "read" markers without a scroll listener.
12 lines of js in 1 block, 7 lines of explanation.
#935 -
SNP071
Find and replace text in many files with sed
Rename a function across a project from the terminal.
2 lines of sh in 2 blocks, 7 lines of explanation.
#426 -
SNP070
Disable SSH password login on a server
Once your key works, close the door the bots keep knocking on.
5 lines of sh in 3 blocks, 6 lines of explanation.
#15A -
SNP069
Highlight code with Shiki in Stati
Build-time syntax highlighting with Shiki, ready before Stati's synchronous markdown.configure runs.
27 lines of sh, js and ts in 3 blocks, 11 lines of explanation with 3 notes.
#2B4 -
SNP068
Exhaustive switch in TypeScript
Make the compiler complain when you add a case to a union and forget to handle it.
14 lines of ts in 1 block, 3 lines of explanation.
#B26 -
SNP067
Redirect from a route middleware in Nuxt
Send people who aren't logged in to the login page before the page even renders.
10 lines of js and vue in 2 blocks, 6 lines of explanation.
#694 -
SNP066
Serve Stati's clean URLs from nginx
/about is about.html. The try_files line, the trailing slash redirect and the 404 page.
18 lines of nginx and ts in 2 blocks, 12 lines of explanation.
#742 -
SNP065
Check if a port is open from the terminal
Is it the firewall, the service, or me?
2 lines of sh in 2 blocks, 4 lines of explanation.
#513 -
SNP064
Stop tracking a file without deleting it
You committed .env or a build folder. Get it out of git but keep it on disk.
4 lines of sh in 2 blocks, 5 lines of explanation.
#A42 -
SNP063
Class names with stati.propValue
Stati's own classnames, for class lists with conditions in them.
13 lines of eta in 1 block, 13 lines of explanation with 4 notes.
#13B -
SNP062
Find the processes eating your memory
The server is swapping. Who's responsible?
3 lines of sh in 3 blocks, 6 lines of explanation.
#295 -
SNP061
Format dates without a library
Intl.DateTimeFormat does most of what you used moment or date-fns for.
12 lines of js in 2 blocks, 4 lines of explanation.
#351 -
SNP060
Custom template filters in Stati
A date format and a reading time, registered once in the config and called like functions.
22 lines of ts and eta in 2 blocks, 12 lines of explanation with 5 notes.
#495 -
SNP059
Sign your commits with your SSH key
Verified badges on GitHub without setting up GPG.
6 lines of sh in 2 blocks, 4 lines of explanation.
#64B -
SNP058
Send JSON with curl
POST a JSON body to an API from the terminal, and read the answer.
5 lines of sh in 2 blocks, 4 lines of explanation.
#B12 -
SNP057
Pick a layout per page in Stati
How Stati finds a page's layout, and the typo it won't tell you about.
12 lines of yaml and text in 2 blocks, 18 lines of explanation with 3 notes.
#641 -
SNP056
Group an array by a key
Object.groupBy is finally a thing. Here it is, with the fallback for older runtimes.
9 lines of js in 2 blocks, 3 lines of explanation.
#496 -
SNP055
Pixel-perfect settings in Godot 4
The project settings that keep pixel art sharp when the window is scaled.
9 lines of ini in 1 block, 13 lines of explanation with 5 notes.
#539 -
SNP054
Different git identity for work and personal projects
Stop committing to work repos with your personal email, automatically.
9 lines of ini in 2 blocks, 6 lines of explanation.
#1B3
No snippets match this filter.