Skip to content

Instantly share code, notes, and snippets.

robmiller / git-cleanup-repo
Last active Oct 22, 2021
A script for cleaning up Git repositories; it deletes branches that are fully merged into `origin/master`, prunes obsolete remote tracking branches, and as an added bonus will replicate these changes on the remote.
View git-cleanup-repo
# git-cleanup-repo
# Author: Rob Miller <>
# Adapted from the original by Yorick Sijsling
git checkout master &> /dev/null
# Make sure we're working with the most up-to-date version of master.
git fetch
robmiller / .gitconfig
Created Jul 17, 2013
Some useful Git aliases that I use every day
View .gitconfig
# Working with branches
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"
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 / .vimrc
Last active Jul 7, 2021
Autoload sessions created by tpope's vim-obsession when starting Vim.
View .vimrc
augroup sourcesession
autocmd VimEnter * nested
\ if !argc() && empty(v:this_session) && filereadable('Session.vim') |
\ source Session.vim |
\ endif
augroup END
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 / enable-rs-db-root.rb
Created Feb 4, 2016
A script for easily enabling the root account on a Rackspace cloud database instance, something that's inexplicably impossible to do via the GUI
View enable-rs-db-root.rb
#!/usr/bin/env ruby
# enable-rs-db-root
# Enables the root account on a Rackspace cloud database instance.
# Usage:
# enable-rs-db-root
robmiller /
Last active Feb 19, 2021
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 / sqlite-distance.rb
Last active Feb 3, 2021
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:
View sqlite-distance.rb
db = ":memory:"
# A sample SQLite table; all that's necessary is the lat and log fields
db.execute <<-SQL
email VARCHAR(255),
lat FLOAT,
View beautiful.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) {
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 <>
puts DATA.each_line.to_a.sample(4).map(&:chomp).join("-")