Skip to content

Instantly share code, notes, and snippets.


Ryan Baumann ryanfb

View GitHub Profile
ryanfb /
Created March 17, 2023 13:38
Undo accidentally running id3tag on an M4A or M4B audio file. Assumes GNU grep and head are available at ggrep and ghead respectively (`brew install coreutils` on macOS).
OFFSET=$(ggrep --only-matching --byte-offset --max-count=1 --binary --text --perl-regexp "\x00\x00\x00\x1c" "$1" | head -1 | cut -d':' -f1)
tail -c +$(( $OFFSET + 1 )) "$1" | ghead -c -128 > untagged.m4b
if ffprobe -loglevel quiet untagged.m4b ; then
echo "Untagging succeeded for: $1"
mv untagged.m4b "$1"
echo "Untagging failed for: $1"
ryanfb / bookmarks_export.rb
Last active November 21, 2022 22:13
Export your Twitter Bookmarks to JSON. This will also delete all your Twitter Bookmarks, 50 Bookmarks at a time, to get around API limits. Now at:
View bookmarks_export.rb
#!/usr/bin/env ruby
# Based on:
# See:
require 'json'
require 'typhoeus'
require 'twitter_oauth2'
# First, you will need to enable OAuth 2.0 in your App’s auth settings in the Developer Portal to get your client ID.
# Inside your terminal you will need to set an enviornment variable
# export CLIENT_ID='your-client-id'
ryanfb / mbox-size.rb
Created July 11, 2022 21:49
Get the total number of bytes used for each sender in an Mbox email file
View mbox-size.rb
#!/usr/bin/env ruby
emails = {}
email_length = 0
last_email_from = nil[0], "r:ASCII-8BIT").each_line do |line|
if line.start_with?('From ')
unless last_email_from.nil?
emails[last_email_from] ||= 0
ryanfb /
Created May 31, 2022 13:06
Command Line Script for Downloading a Manuscript from the British Library using dezoomify-rs
wget -O - "$1" | fgrep 'id="PageList"' | sed -e 's/^.*value="//' -e 's/" \/>.*//' -e "s/||/\n/g" | grep -v '^##$' | sort | uniq | while read i; do echo "$i"; dezoomify-rs -l "${i}.xml" "${i}.jpg"; done
ryanfb / wait_for_deploy.rb
Created July 9, 2021 14:24
Run from a Git repository with a properly configured Rapporteur ( status endpoint as the first argument, this script will wait until the live revision matches the latest local revision
View wait_for_deploy.rb
#!/usr/bin/env ruby
require 'json'
require 'shellwords'
unless ARGV.length == 1
$stderr.puts "Usage: wait_for_deploy.rb"
exit 1
ryanfb /
Last active December 22, 2021 17:01
Short shell script for concatenating video files with ffmpeg's "concat" demuxer, using command line arguments.
# Usage:
# ./ input1.mp4 input2.mp4 input3.mp4 output.mp4
# See:
for input in "${@:1:$#-1}"; do echo "file '$input'"; done > filelist.txt
ffmpeg -f concat -safe 0 -i filelist.txt -c copy "${@: -1}"
echo "Concatenated:" && cat filelist.txt && rm -f filelist.txt
ryanfb /
Last active June 12, 2020 14:33
Set MP3 id3v2 duration from actual MP3 duration
for i in *.mp3; do
duration=`echo "$(( $(sox "$i" -n stat 2>&1|fgrep 'Length'|cut -d':' -f2|xargs) * 1000 ))"| awk '{printf("%d\n",$0+=$0<0?0:0.9)}'`
echo "$i: $duration"
id3v2 --TLEN "$duration" "$i"
ryanfb /
Created May 21, 2020 12:48
Blender Python script for converting a mesh to GLB with Draco compression
# Blender Python script for converting a mesh to GLB with Draco compression.
# Tested on Blender 2.82
# Usage:
# blender --background --factory-startup --addons io_scene_gltf2 --python -- -i #{source_path} -o #{out_path}
from os import path
from contextlib import redirect_stdout
from sys import argv
import argparse
import io
import bpy
ryanfb / last-modified.js
Created April 27, 2020 15:39
snippet for setting the last modified date on a GitHub Pages post using the GitHub API
View last-modified.js
function setModifiedDate() {
if (document.getElementById('last-modified')) {
fetch("{{ site.github.owner_name }}/{{ site.github.repository_name }}/commits?path={{ page.path }}")
.then((response) => {
return response.json();
.then((commits) => {
var modified = commits[0]['commit']['committer']['date'].slice(0,10);
if(modified != "{{ | date: "%Y-%m-%d" }}") {
document.getElementById('last-modified').textContent = "Last Modified: " + modified;