Grimoire

Inspired by the grimoire of Fred Bednarski, this is my place to put assorted snippets of code (which may or may not be cursed, so use at your own risk). Have fun, poke around, but remember that this information may be totally borked.

To change the extensions of audio files in a directory:

Bash

for file in *.m4a; do ffmpeg -i "${file}" "${file/%m4a/ogg}" && rm $file; done

More generally, to do something to some files:

Bash

for file in $(ls | grep "something"); do echo "match: ${file}"; done

To download the mp3 audio (or the best audio if that fails) of a youtube video:

Bash

youtube-dl --add-metadata -i -x -f mp3/bestaudio "video_link"

To download a playlist of music from youtube (more stable for playlists than youtube-dl):

Bash

youtube-dlc -o '%(playlist_index)s - %(title)s.%(ext)s' -x -f mp3/bestaudio "[playlist url]"

To forward your port 8388 to a server's port 8384 (can be used to get the web interface for syncthing remotely):

Bash

ssh -L 127.0.0.1:8388:127.0.0.1:8384 username@yourserver

To sanitize a file name (the .opus can be any extension):

Bash

mv "$file" "$(echo "${file%.opus}" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g").opus"

To sanitize everything in a directory, preserving extensions:

Fish

function sanitize for file in * set ext (string match -r "\.\w*\$" $file | \ string trim --chars=.) set new (echo "{$file}" | \ iconv -cf UTF-8 -t ASCII//TRANSLIT | \ tr -d '[:punct:]' | \ tr '[:upper:]' '[:lower:]' | \ tr ' ' '-' | \ sed "s/-\+/-/g;s/\(^-\|-\$\)//g"); set final (string replace "$ext" ".$ext" "$new") if [ "$file" != "$final" ] mv "$file" "$final" end end end

To push file changes over ssh:

Bash

rsync -azP --delete ~/Folder/ user@123.456.8.910:/home/name/Folder

To dither and shrink an image (courtesy of Thomasorus with some modification for personal preference):

Bash

mogrify -format gif -filter Triangle -define filter:support=2 -thumbnail $size -monochrome -unsharp 0.25x0.08+8.3+0.045 -dither FloydSteinberg -colors 2 -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace gray -normalize $from

To simply dither of an image:

Bash

convert image.png -colorspace gray -ordered-dither o8x8 image_dithered.png

Super simple, but to make a div element take up the whole height of a veiwport

CSS

height: 100vh;

This is something pretty specific (and simple), but this is how I fixed my audio continuously muting in Manjaro i3:

Bash

alsactl restore

To play a streaming file

Bash

mplayer -prefer-ipv4 -playlist kexp128.mp3.m3u

Grab some html from the Noita wiki

Bash

curl "https://noita.gamepedia.com/Oil_(Spell)" | awk '/table class="spell"/ {for(i=1; i<=69; i++) {getline; print}}'

Find all files which match a given regex

Bash

grep -rnw 'dir/' -e 'pattern'