Skip to content

Instantly share code, notes, and snippets.

View ryanfb's full-sized avatar

Ryan Baumann ryanfb

View GitHub Profile
@ryanfb
ryanfb / bl-dl.sh
Created May 31, 2022 13:06
Command Line Script for Downloading a Manuscript from the British Library using dezoomify-rs
#!/bin/bash
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 "http://www.bl.uk/manuscripts/Proxy.ashx?view=${i}.xml" "${i}.jpg"; done
@ryanfb
ryanfb / wait_for_deploy.rb
Created July 9, 2021 14:24
Run from a Git repository with a properly configured Rapporteur (https://github.com/envylabs/rapporteur) status endpoint as the first argument, this script will wait until the live revision matches the latest local revision
#!/usr/bin/env ruby
require 'json'
require 'shellwords'
unless ARGV.length == 1
$stderr.puts "Usage: wait_for_deploy.rb https://example.com/status.json"
exit 1
end
@ryanfb
ryanfb / clone_github_network.rb
Created October 31, 2013 19:53
Clone all forks in a GitHub repository's network.
#!/usr/bin/env ruby
require 'json'
require 'open-uri'
require 'fileutils'
def clone_repo(repo)
puts repo['full_name']
owner, path = repo['full_name'].split('/')
FileUtils.mkdir_p(owner)
@ryanfb
ryanfb / id3v2len.sh
Last active June 12, 2020 14:33
Set MP3 id3v2 duration from actual MP3 duration
#!/bin/bash
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"
done
#!/bin/bash
PREFIX=$(basename "$1" .pdf)
if [ ! -z "$TESSERACT_FLAGS" ]; then
echo "Picked up TESSERACT_FLAGS: $TESSERACT_FLAGS"
fi
echo "Prefix is: $PREFIX"
echo "Converting to TIFF..."
if command -v parallel >/dev/null 2>&1; then
LAST_PAGE=$(($(pdfinfo "$1"|grep '^Pages:'|awk '{print $2}') - 1))
@ryanfb
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
function setModifiedDate() {
if (document.getElementById('last-modified')) {
fetch("https://api.github.com/repos/{{ 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 != "{{ page.date | date: "%Y-%m-%d" }}") {
document.getElementById('last-modified').textContent = "Last Modified: " + modified;
@ryanfb
ryanfb / fusion-tables-migration.md
Created November 26, 2019 15:23
Fusion Tables Migration Alternatives
  • Datasette on Heroku
  • Heroku Postgres
  • Google Bigtable - $.65/hr
  • Google BigQuery - $5/TB of queried data, $.02/GB/mo stored
  • Google Cloud Datastore - 1GB free, .18GB/month above
  • Google Cloud Firestore - similar to Datastore
  • Google Sheets
  • Google Cloud SQL (MySQL/PostgreSQL)
  • AWS DynamoDB - NoSQL, 25GB free, $0.25/1M read request units
  • AWS Athena - costs per TB scanned, reads data from S3 buckets
#!/usr/bin/env ruby
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
require 'nokogiri'
pdf_filename = ARGV[0]
xml_filename = File.basename(pdf_filename,'.pdf') + '.xml'
@ryanfb
ryanfb / ancientgreekspeak.rb
Last active May 9, 2019 18:26
Ruby script for transliterating Ancient Greek to Apple phonemes for text-to-speech synthesis - updates at https://github.com/ryanfb/ancientgreekspeak/
#!/usr/bin/env ruby
require 'i18n'
Encoding.default_external = Encoding::UTF_8
# Usage: Takes Unicode Polytonic Greek on STDIN or as arguments, outputs
# phonetic pronunciation on STDOUT designed to be piped into the Mac `say` command.
# e.g.:
# echo 'ἄγω ἄξω ἤγαγον ἦχα ἤγμαι ἤχθην' | ./ancientgreekspeak.rb | say