Skip to content

Instantly share code, notes, and snippets.

@mmrwoods
mmrwoods / mongod
Created October 26, 2010 16:11
Mongo DB init script for Linux and OSX
#!/bin/bash
# Nasty, intentionally verbose script to start/stop mongod
# Mark Woods - March 2010
RUNTIME_USER='nobody' # only applicable on Linux, otherwise runs as current user
LOGPATH='/var/log/mongodb/mongod.log'
CONFIGFILE='/etc/mongod.conf'
DBPATH='/opt/mongodb/data/db'
BINPATH='/opt/mongodb/bin/mongod'
@mmrwoods
mmrwoods / example_migration.rb
Created October 26, 2010 16:38
Rails migration helper for dealing with large tables in MySQL
require "mysql_big_table_migration_helper"
class AddIndexOnSomeColumnToSomeTable < ActiveRecord::Migration
extend MySQLBigTableMigrationHelper
def self.up
add_index_using_tmp_table :some_table, :some_column
end
@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.
@mmrwoods
mmrwoods / pseudo_long_opts.sh
Created August 25, 2011 12:54
pseudo long opts for use with getopts
# Allow pseudo long options based on naming convention.
# Long opts are converted to short opts by simply discarding all but
# the first character, which does nothing more than allow for more
# readable argument lists.
set -- `echo " $@ " | sed s/\ "-\{1,\}\([a-zA-Z]\)[-a-z]\{1,\}[=\ ]/\ -\1\ /g"`