Snippets
SNP 001–148
Loosely organized collection of code snippets. Maybe you'll find something useful here.
Showing 20 of 148 snippets
-
SNP 048
#31B
Truncate text after a few lines
Clamp a description to three lines with an ellipsis, in CSS only.
-
SNP 047
#459
Copy files with rsync over SSH
Like scp, but it only sends what changed, and it can resume.
-
SNP 046
#B27
Open a shell in a running container
Poke around inside a container to see what it actually looks like in there.
-
SNP 045
#164
Respect prefers-reduced-motion
Some people get dizzy from your fancy animations. The browser tells you who, so listen.
-
SNP 044
#A35
Latest row per group in SQL
The newest order of every customer, in one query.
-
SNP 043
#591
Create a new user with sudo rights on Ubuntu
Stop working as root on a fresh server.
-
SNP 042
#2B4
Shuffle an array properly
The sort(() => Math.random() - 0.5) trick is biased. Fisher-Yates is just as short and actually random.
-
SNP 041
#369
Create a swap file on Ubuntu
Small VPS, no swap, and npm install gets killed. Give it some room.
-
SNP 040
#14B
Hide the scrollbar but keep scrolling
For horizontal carousels and tab bars where the scrollbar is just noise.
-
SNP 039
#952
MariaDB in Docker for local development
A database for the project that you can throw away and recreate in a second.
-
SNP 038
#416
Read a JSON file in Node
Two ways, one of them without any fs code at all.
-
SNP 037
#529
Redirect www and http to https in nginx
One canonical address for your site, everything else gets a 301.
-
SNP 036
#B63
Sleep in Node without writing a timeout function
Node ships a promise-based setTimeout, so the little helper from my old snippet isn't needed there.
-
SNP 035
#397
Trim a video without re-encoding with ffmpeg
Cut a clip out of a long recording in a second, with no quality loss.
-
SNP 034
#6B1
Watch a nested property in Vue
Your watcher doesn't fire when something deep inside an object changes. Here is why and what to do.
-
SNP 033
#953
Dump and restore a MariaDB database
Backups, moving a database to another server, or copying production to your machine.
-
SNP 032
#42B
Generate a random password in the terminal
No password generator website needed.
-
SNP 031
#592
Copy text to the clipboard
The modern clipboard API in three lines, with the gotchas.
-
SNP 030
#13A
Delete a branch locally and on the remote
The feature is merged, the branch can go.
-
SNP 029
#269
Follow a log file live
Watch a log as it is being written, with and without systemd.
No snippets match this filter.