Skip to content

Instantly share code, notes, and snippets.

@MIB1700
MIB1700 / gist:b4c19f5ce5c13784a036e1c3b34f4830
Last active January 27, 2022 21:04
Restart Mac OS X coreaudio daemon. Useful when using bluetooth devices and things go wrong...
sudo launchctl kickstart -kp system/com.apple.audio.coreaudiod
git rm -r --cached .
git add .
git commit -m "removed useless files after .gitignore update"

ZSH CheatSheet

This is a cheat sheet for how to perform various actions to ZSH, which can be tricky to find on the web as the syntax is not intuitive and it is generally not very well-documented.

Strings

Description Syntax
Get the length of a string ${#VARNAME}
Get a single character ${VARNAME[index]}
@MIB1700
MIB1700 / gitCommitSizes.sh
Created May 10, 2021 09:00
git committed sizes
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
cut -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
#from https://stackoverflow.com/questions/10622179/how-to-find-identify-large-commits-in-git-history
@MIB1700
MIB1700 / GITcheckoutSpecificCommit.md
Last active April 28, 2021 09:44
checkout a single file from a specific commit

#Git: checkout a single file from a specific commit

When we need to retrieve a single file from an old commit, because the current one got deleted or broken and then commited by mistake, use:

git checkout <COMMIT#> <path/to/the/messed/up/file>

To get the COMMIT#:

@MIB1700
MIB1700 / safari-PIP.js
Created April 22, 2021 21:18
a little js to force safari into PIP
function startPiP() {
var videos = document.getElementsByTagName('video');
for(vid in videos) {
if(videos[vid].src) videos[vid].webkitSetPresentationMode("picture-in-picture");
}
}
startPiP();
@MIB1700
MIB1700 / crossfade_audio.sh
Last active April 20, 2021 11:43
ffmpeg crossfade 2 audio files
ffmpeg -y -i "$file1" -i "$file2" -filter_complex acrossfade=ns="$crossFormat":c1=hsin:c2=hsin output.aiff
#crossFormat = num samples to use in crossfade
@MIB1700
MIB1700 / extractVideo.sh
Last active April 20, 2021 11:40
FFmpeg extract portion of file
ffmpeg -y -i "$file" -ss "$startTime" -to "$endTime" -ar 44100 "$newFile"
@MIB1700
MIB1700 / pngAddShadow.sh
Last active April 20, 2021 19:55
add shadow to all pngs using convert by imagemagick
for f in *
do
if [[ $f == *.png ]]
then
#name of current file
name="${f%.png}"
convert "${f}" -bordercolor white -border 10 \
\( +clone -background black -shadow 75x25+10+10 \) \
+swap -background none -layers merge +repage \
@MIB1700
MIB1700 / toMp3.sh
Last active April 20, 2021 11:41
ffmpeg convert all files in folder to mp3s
for f in *
do
ffmpeg -i "$f" -c:a mp3 -ab 192k "${f%.*}".mp3
done
#assumes that all files in the folder are audio files or video files containing audio!