Enable up-arrow history auto-complete
This is really simple:
nano ~/.inputrc
Paste in:
"\e[A": history-search-backward
"\e[B": history-search-forward
Run:
bind -f ~/.inputrc
This is really simple:
nano ~/.inputrc
Paste in:
"\e[A": history-search-backward
"\e[B": history-search-forward
Run:
bind -f ~/.inputrc
To run cron jobs with your user env so that it's actually possible for them to run anything, add this to the top of your cron file (edit with crontab -e
):
SHELL=/bin/bash
HOME=/home/<username>
BASH_ENV=$HOME/.bashrc
Then look at your ~/.bashrc
file and make sure to remove any code (usually at the top) that exits early if found in a non-interactive shell.
It's really hard to get new Worker()
from node:worker_threads
to work when running code via tsx
. I finally got an example working. Here's how to do it:
import {Worker} from 'node:worker_threads';
const workerPath = import.meta.resolve('./sample-worker.js');
const worker = import.meta.filename.endsWith('.ts')
? new Worker(
`import('tsx/esm/api').then(({ register }) => { register(); import('${workerPath}') })`,
{
eval: true,
},
)
: new Worker(workerPath);
It's super easy to write your own daemon, so here's how.
CJS Node.js scripts have always been able to detect if they're running directly through the CLI or imported from another JS script through various means (the most recent being require.main === module
).
However, ESM scripts have not been so lucky. For years the answer to this in ESM has simply been no.
Now it's in Node.js v24! You use it like this:
if (import.meta.main) {
// executed from CLI
} else {
// imported into another JS module
}
I noticed recently that running frontend Playwright tests on macOS via GitHub Actions is noticeably faster than on Ubuntu. This is because macOS ships with more browser dependencies out of the box, whereas the base Ubuntu image needs to install them all every run, which takes time. But Playwright has an image with these dependencies already installed! In the end it saves about 30 seconds on Ubuntu.
This command will recursively find all OGG files in the currently directory and nested directories and convert them to MP3.
find . -type f -name '*.ogg' -exec bash -c 'for f; do ffmpeg -i "$f" -c:v copy -q:a 2 -map_metadata 0:s:0 "${f%.ogg}.mp3"; done' bash {} +
I can't use macOS anymore without SoundSource. However, it frequently freezes, hangs, crashes, etc. This requires a not-too-lengthy but still annoying manual flow of opening up Activity Monitor to force kill it, then opening it again. So I made it easier and automated.
A step-by-step guide on how to setup a fresh Windows 11 installation for web development. These steps should also work on Windows 10 without much variation.
I couldn't find a single consolidated place that explains how to setup pm2 from scratch (assuming you've already installed Node.js), and their own "quick start" didn't help. I was finally able to piece together how to get it working.