shaky.sh

TIL, Developer Edition

I do as much as possible on the command line, so this is my (growing) cheat sheet of commands I frequently have to look up. This page is for me, but if you find it useful, great!

Recursively find all files with extension:

find . -name "*.txt"

Benchmarking from the command line with hyperfine:

hyperfine 'node fib.js' 'bun fib.js'

Update a forked repo with the latest from upstream:

git fetch upstream
git rebase upstream/main
git push origin main

How to update Drop Alt keyboard qmk firmware:

vim $QMK_FIRMWARE/keyboards/massdrop/alt/keymaps/personal1/keymap.c
qmk compile -kb massdrop/alt -km personal1
mdloader --first --download .build/massdrop_alt_personal1.hex --restart
# then hold <Fn-b> for 0.5s

Replace text in Bash variable (and remove spaces from file name):

ls | while read file do
  mv "$file" "${file/ /-}"
done

Move branch B to branch off master instead of branch A, now that branch A has been merged into master:

git rebase --onto master branch-a branch-b

Remove a commit from a branch when it's not the last commit. There are other ways, but this is the easiest:

git rebase -i <hash-from-before-the-offending-commit>
# manually delete the commit line, and save

Use the Nerd Font Cheat Sheet to include icons in your shell scripts.

Get a random integer between min and max (inclusive):

function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}