Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Find hosts matching pattern in ssh_config and run command on each.
# As pattern is an argument to egrep, but is also injected into a string
# which is evaluated, you can hack the input to do weird useful things,
# like pass options to egrep or pipe the output through another command.
usage() {
echo "Usage: $0 [pattern] [command]"
}
@mmrwoods
mmrwoods / postgres_migration_utils.rb
Last active August 29, 2015 14:04
postgres_migration_utils.rb
module PostgreSQLMigrationUtils
# Changes the type of a string or text column to citext and recreates
# indexes on that column that follow the rails naming convention, such
# that the index is on the result of the lower(col) function.
#
# Note: The citext type changes comparisons on citext columns to be on
# lower(col), but does nothing about ensuring that indexes created on
# citext columns are automatically created on the result of lower(col).
def change_column_to_citext(table_name, column_name)
@mmrwoods
mmrwoods / check_apache.sh
Last active August 29, 2015 14:07
Quick hack to check apache is running and responding, and start/restart if not
#!/bin/bash
PS_NAME=apache2
CHECK_URL=http://localhost/
MAX_TRIES=5
apache_running() {
ps -eo pid,comm | fgrep $PS_NAME > /dev/null 2>&1
}
@mmrwoods
mmrwoods / check_url
Created October 27, 2010 06:42
Monitor a URL for downtime
#!/usr/bin/env ruby
require 'rubygems'
require 'term/ansicolor'
require 'net/ping'
String.send(:include, Term::ANSIColor)
url = ARGV[0]
@mmrwoods
mmrwoods / gittest
Created October 27, 2010 06:48
Use autotest to run rails tests/specs impacted by changes shown by git-diff
#!/usr/bin/env ruby
require 'rubygems'
require 'autotest'
require 'optparse'
# exit if we're not in a git repository
exit $?.exitstatus unless system('git diff --name-only > /dev/null')
# make sure we're in the root path for the repository
@mmrwoods
mmrwoods / commit-msg
Created November 25, 2010 07:33
Commit and merge hooks for Github and Lighthouse
#!/usr/bin/env ruby
# When committing directly to master, look for lighthouse ticket number in commit msg and, if necessary, append in format recognised by github
# When committing to a topic/feature branch, barf if the branch name doesn't include a ticket number that can be parsed by the post-merge hook
# Note: this hook only applies when -m option used and can also be skipped by using --no-verify option
COMMIT_MASTER_STATE = 'coding-done'
branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1]
@mmrwoods
mmrwoods / DefaultKeyBinding.dict
Created November 25, 2010 13:28
Custom cocoa key bindings
/* save this file to ~/Library/KeyBindings/DefaultKeyBinding.dict */
/*
Prefixes for modifier keys...
------------------------------
~ Option key (⌥)
$ Shift key (⇧)
^ Control key (⌃)
@ Command key (⌘)
# keys on number pad
@mmrwoods
mmrwoods / deploy_lighthouse
Created April 6, 2011 16:51
Capistrano Lighthouse integration script
#!/usr/bin/env ruby
# this simple script takes two arguments, the rails environment we're deploying to and a commit range to be passed to git-log
# The commit range MUST be in the format <full sha of previous revision>..<full sha of current revision>, otherwise the world will end
# It looks at git commit messages between the previous and current revision, extracts lighthouse ticket numbers where they are provided
# in the commit message; updates the ticket in lighthouse, changing the state to 'resolved' for deploys to production, both changing
# state to 'uat' and re-assigning the ticket to the creator for deploys to stage; then sends an email listing the deployed tickets.
# Note: if rails environment is edge, does a dummy run as if it was deploying to stage, but doesn't save updates to tickets or send the email
@mmrwoods
mmrwoods / dumb_ass_daily_backup.rb
Created May 20, 2011 16:03
Dumb-ass Daily Backup - Better than no backup!
#!/usr/bin/env ruby
# Dumb-ass Daily Backup - Better than no backup, and so simple it can't fail!
#
# A backup directory will be created within the destination directory for each key of the sources hash.
# Values can be files, directories or glob patterns.
# Directories will be backed up as gzipped tar archives, text files are gzipped, binary files are copied.
# Create a /etc/dumb_ass_daily_backup.yml config file to override the default sources and destination.
# Nothing fancy, no incremental backups, no syncing to remote servers, just a dumb backup script.
@mmrwoods
mmrwoods / dumb_ass_remote_copy.rb
Created July 11, 2011 12:01
Copy dumb-ass daily backups to remote servers using scp, genius!
#!/usr/bin/env ruby
# Dumb-ass Remote Copy - Copy dumb-ass daily backups to remote servers using scp, genius!
#
# Copies today's sub-directory of local source directory to remote destination directory.
# Uses only ssh and scp, but requires batch mode / authorized keys.
# Does not "sync" files, today's destination directory is trashed and everything is copied.
# Copies recursively, maintaining directory structure on remote host, but does so by creating
# directories as required and executing scp once for each file to copy - slow, but robust.
# Create a /etc/dumb_ass_remote_copy.yml config file to override default configuration options.