Skip to content

Instantly share code, notes, and snippets.

@robmiller
robmiller / refresh-skim.scpt
Created June 14, 2021 11:15
AppleScript for refreshing Skim PDF
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 / enable-rs-db-root.rb
Created February 4, 2016 21:34
A script for easily enabling the root account on a Rackspace cloud database instance, something that's inexplicably impossible to do via the GUI
#!/usr/bin/env ruby
#
# enable-rs-db-root
#
# Enables the root account on a Rackspace cloud database instance.
#
# Usage:
#
# enable-rs-db-root name.of.your.instance.example.com
#
@robmiller
robmiller / fixes.sh
Last active February 19, 2021 13:52
Stuff that happened to me when migrating to an M1 Mac
# 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
@robmiller
robmiller / sqlite-distance.rb
Last active February 3, 2021 16:33
Ruby/SQLite code for finding places within a certain distance from another place. In other words, Ruby code that adds a "DISTANCE(lat1, lon1, lat2, lon2)" to SQLite, allowing you to select records based on the distance between two points of latitude and longitude. Magic! Adapted from the ObjectiveC version here: http://daveaddey.com/?p=71
db = SQLite3::Database.new ":memory:"
# A sample SQLite table; all that's necessary is the lat and log fields
db.execute <<-SQL
CREATE TABLE users (
email VARCHAR(255),
lat FLOAT,
lon FLOAT
)
SQL
<?php
function register()
{
if (!empty($_POST)) {
$msg = '';
if ($_POST['user_name']) {
if ($_POST['user_password_new']) {
if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
if (strlen($_POST['user_password_new']) > 5) {
if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
#!/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("-")
#!/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.
#
# --
#
@robmiller
robmiller / .gitconfig
Last active May 20, 2020 13:45
Want to find out what changes were introduced by a particular merge commit? Hey, so do I! ALL THE TIME. These aliases will do that.
# `git merge-log` shows the commits that were introduced in a given merge
# `git merge-diff` shows the actual changes that were introduced by a given merge
# Both commands accept an optional commitish; if ommitted, the last merge commit is used
merge-span = "!f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f"
merge-log = "!git log `git merge-span .. $1`"
merge-diff = "!git diff `git merge-span ... $1`"
merge-difftool = "!git difftool `git merge-span ... $1`"
/* 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];
}
#!/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 }