Skip to content

Instantly share code, notes, and snippets.

@robmiller
robmiller / delete-tweets.rb
Created Jul 15, 2021
Script for deleting tweets from a Twitter data export
View delete-tweets.rb
#!/usr/bin/env ruby
gem "twitter", "~> 7.0"
gem "http", "~> 4.4"
require "twitter"
require "http"
require "json"
require "yaml"
@robmiller
robmiller / refresh-skim.scpt
Created Jun 14, 2021
AppleScript for refreshing Skim PDF
View refresh-skim.scpt
tell application "Skim"
repeat with n from (count of documents) to 1 by -1
set doc to document n
if name of doc is "book-screen.pdf" then
revert doc
end if
end repeat
end tell
@robmiller
robmiller / fixes.sh
Last active Feb 19, 2021
Stuff that happened to me when migrating to an M1 Mac
View fixes.sh
# The macOS command line tools broke, so I had to reinstall them
# (I kept getting the error "Your CLT does not support macOS 11."
# when compiling packages from Homebrew.)
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
# Homebrew had old x86 libraries and object files and god knows what
# else hanging around, which caused several packages to break during install
# (including Ruby) so I reinstalled Homebrew and all my packages
brew list > ~/homebrew.tmp.txt
View correct-horse.rb
#!/usr/bin/env ruby
#
# A "correct horse battery staple"-style password generator. Outputs
# four random, fairly common (among the 5,000 most common words) English
# words, contracted together with hyphens.
#
# Author: Rob Miller <r@robm.me.uk>
puts DATA.each_line.to_a.sample(4).map(&:chomp).join("-")
View lightroom-groups.rb
#!/usr/bin/env ruby
#
# lightroom-groups.rb
# Author: Rob Miller <r@robm.me.uk>
#
# Mass organises presets into groups in Lightroom, based on their folder
# on disk.
#
# --
#
View koala.js
/* reveals koalastothemax.com without needing to move your mouse */
var mm = new Event("mousemove");
function rand(min, max) { return Math.ceil(Math.random() * (max - min) + min); }
function sorter(c1, c2) { if ( c1[0] > c2[0] ) { return -1; } if ( c1[0] < c2[0] ) { return 1; } return 0 }
function getBiggestCircle() {
var circles = [...document.querySelectorAll("#dots circle")].map(c => [c.getBBox().width, c]).sort(sorter);
return circles[0][1];
}
View 12s.rb
#!/usr/bin/env ruby
#
# Solutions to Diamond Geezer's "the digits of the year 2019 add up to twelve" puzzles:
# http://diamondgeezer.blogspot.com/2019/01/the-digits-of-year-2019-add-up-to-twelve.html
def main
# a) How many years ago did this last happen?
a = 2019 - 2018.downto(0).find { |year| sum_digits(year) == 12 }
# b) In what year?
b = 2018.downto(0).find { |year| sum_digits(year) == 12 }
@robmiller
robmiller / spider
Created May 9, 2018
Outputs all of the URLs of pages on a given site
View spider
#!/bin/bash
#
# spider
#
# Author: Rob Miller <rob@bigfish.co.uk>
#
# Outputs all of the HTML pages on a given domain.
wget -r -nd --delete-after -w 1 "$1" 2>&1 |
@robmiller
robmiller / sort-domains.rb
Created Feb 13, 2018
Sort a list of hostnames so that www. versions show up next to non-www. versions of the same domain
View sort-domains.rb
#!/usr/bin/env ruby
#
# Sometimes you want to sort a list of hostnames/domains and want
# example.com to sort next to www.example.com. This does that.
#
# Author: Rob Miller <r@robm.me.uk>
#
# Usage:
#
# $ cat foo.txt | sort-domains
@robmiller
robmiller / smog.rb
Created Jan 5, 2018
A Ruby implementation of SMOG (Simple Measure of Gobbledygook) scoring for measuring text complexity.
View smog.rb
#!/usr/bin/env ruby
#
# Calculates the SMOG (Simple Measure of Gobbledygook) score for a given
# piece of text. A CLI utility that could very easily be adapted into
# a library if I could be be bothered.
#
# More on SMOG: https://en.wikipedia.org/wiki/SMOG
#
# Author: Rob Miller <r@robm.me.uk>
#