Skip to content

Instantly share code, notes, and snippets.

@sappharx
sappharx / build.sh
Created January 6, 2020 05:30
create bootable macOS catalina disk image (for building VMs in VMWare Fusion)
# source: https://communities.vmware.com/thread/573025 (I basically just modified for Catalina)
hdiutil create -o Catalina -size 10G -layout SPUD -fs HFS+J -type SPARSE
hdiutil attach Catalina.sparseimage -noverify -mountpoint /Volumes/install_build
sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/install_build
hdiutil detach "/Volumes/Install macOS Catalina"
hdiutil convert Catalina.sparseimage -format UDZO -o Catalina.dmg
@sappharx
sappharx / terminal-colors.sh
Created July 10, 2018 17:05
terminal colors
tput colors
for i in {0..255} ; do
printf "\x1b[38;5;${i}m${i} "
done
@sappharx
sappharx / cli.sh
Created May 30, 2018 15:15
some random cli magic stuff
https://twitter.com/DCoderLT/status/996049864495648768
cd $(mktemp -d) # get an instant temporary directory
@sappharx
sappharx / install-docker.sh
Last active April 25, 2018 02:39
mac set up scripts
#!/usr/bin/env bash -e
# download disk image
cd ~/Downloads
curl -O https://download.docker.com/mac/stable/Docker.dmg
# attach disk image
hdiutil attach Docker.dmg
# copy app folder to Applications directory
@sappharx
sappharx / string-bit-manipulation.js
Created March 12, 2017 22:06
use bit manipulation to change letter case
const toLower = (char) => {
const code = char.charCodeAt(0)
return String.fromCharCode(code > 64 && code < 91 ? code | 0b100000 : code)
}
const toUpper = (char) => {
const code = char.charCodeAt(0)
return String.fromCharCode(code > 96 && code < 123 ? code ^ 0b100000 : code)
}
@sappharx
sappharx / rebase.sh
Created January 24, 2017 01:12
rebase your last few commits onto a different branch
git rebase --onto master head~4 # or how every many commits you need
const msd = n => Math.floor(n / Math.pow(10, Math.floor(Math.log10(n))))
const accumulator = (histogram, value) => (histogram[value - 1]++, histogram)
const scale = (num, idx, arr) => num / arr.reduce((count, val) => count + val, 0)
const benford = list => list
.map(msd)
.reduce(accumulator, Array(9).fill(0))
.map(scale)
const msd = n => Math.floor(n / 10 ** Math.floor(Math.log10(n)))
const accumulator = (histogram, value) => (histogram[value - 1]++, histogram)
const scale = (num, idx, arr) => num / arr.reduce((count, val) => count + val, 0)
const benford = list => list
.filter(Boolean)
.map(Math.abs)
.map(msd)
.reduce(accumulator, Array(9).fill(0))
.map(scale)
@sappharx
sappharx / .vimrc
Created November 23, 2016 19:25
map jj to escape in vim
inoremap jj <ESC>
@sappharx
sappharx / fizzbuzz.fs
Last active March 6, 2017 01:09
FizzBuzzer
let (|Both|Three|Five|Neither|) n =
if n % 15 = 0 then Both
elif n % 3 = 0 then Three
elif n % 5 = 0 then Five
else Neither
let fizzbuzz n =
match n with
| Both -> "FizzBuzz"
| Three -> "Fizz"