Skip to content

Instantly share code, notes, and snippets.

View oggy's full-sized avatar

George Ogata oggy

  • Rhino
  • New York, NY
View GitHub Profile
#!/bin/sh
######################################################################
#
# switch_bundler_environment OLD-BRANCH NEW-BRANCH
#
# Swap out the old branch's Bundler environment, and swaps in the new
# branch's. Arguments may be branch names or SHAs.
#
# For best results, add this to .git/hooks/post-checkout:
@oggy
oggy / redis
Created April 19, 2011 20:16
Script to start redis using command line options, rather than a config file
#!/usr/bin/env ruby
#
# Run redis-server with settings taken from the command line.
#
# Source: https://gist.github.com/929513
#
require 'optparse'
require 'fileutils'
@oggy
oggy / parallel_process_barriers.rb
Created June 7, 2012 01:54
Parallel process barriers in Ruby
#
# Runs two blocks in parallel, yielding a barrier to each for
# synchronization. The barrier may be called multiple times in each
# block to establish multiple synchronization points.
#
# parallel do
# process do |barrier|
# ...
# barrier.call
# ...
@oggy
oggy / gist:4237218
Created December 7, 2012 22:56
Make ActiveRecord ignore columns, so you can drop them without downtime.
ActiveRecord::Base.class_eval do
def self.ignore_columns(*names)
extend ColumnIgnorance
ignored_columns.merge names.map(&:to_s)
end
module ColumnIgnorance
def columns
return @columns if @columns
@columns = super.reject do |column|
class Person
attr_reader :full_name, :age, :profession, :favorite_food
def initialize(full_name, age, profession, favorite_food)
@full_name = full_name
@age = age
@profession = profession
@favorite_food = favorite_food
end
end
@oggy
oggy / goliath-vs-unicorn
Created February 21, 2013 22:31
Demonstrates the superiority of Goliath over Unicorn for a single-process app handling file uploads. Also a fine excuse to use gems named Unicorn, Thor, and Goliath in a single ruby script.
#!/usr/bin/env ruby
# Demonstrates the superiority of Goliath over Unicorn for a single-process app
# handling file uploads.
#
# This program runs in 3 modes:
#
# ./goliath-vs-unicorn goliath - Runs the goliath server on the default port (9000)
# ./goliath-vs-unicorn unicorn - Runs the unicorn server on the default port (8080)
# ./goliath-vs-unicorn upload - Upload 5 files in parallel to the port given by -p
@oggy
oggy / aquamacs
Created March 6, 2014 18:08
Command line program for Aquamacs
#!/usr/bin/env ruby
######################################################################
#
# Open the given file names in Aquamacs.
#
# If the user already has an Aquamacs process open, use it.
# Otherwise, fire up a new one. Only Aquamacs instances without a
# controlling terminal (i.e., those running in a window) will be
# selected.
@oggy
oggy / git-delete-merged-branches
Created June 5, 2014 18:30
Script to delete merged git branches, and preserve ones you care about
#!/usr/bin/env ruby
keep = `git config git-delete-merged-branches.persist`.strip.split(',')
puts "preserving: #{keep.join(', ')}"
current_branch = `git rev-parse --abbrev-ref HEAD`.strip
`git branch --merged`.lines.each do |line|
next if line =~ /\A\* /
branch, target = line.strip.split(' -> ', 2)
next if keep.include?(branch) || keep.include?(target)
@oggy
oggy / r.rb
Created May 16, 2015 11:29
Homebrew formula for R 3.1.2
class RDownloadStrategy < SubversionDownloadStrategy
def stage
quiet_safe_system "cp", "-r", @clone, Dir.pwd
Dir.chdir cache_filename
end
end
class R < Formula
homepage "http://www.r-project.org/"
url "http://cran.rstudio.com/src/base/R-3/R-3.1.2.tar.gz"
@oggy
oggy / git-delete-merged-branches
Created October 8, 2015 18:26
Command to delete git branches that have been merged into the current branch
#!/usr/bin/env ruby
keep = `git config git-delete-merged-branches.persist`.strip.split(',')
puts "preserving: #{keep.join(', ')}"
current_branch = `git rev-parse --abbrev-ref HEAD`.strip
`git branch --merged`.lines.each do |line|
next if line =~ /\A\* /
branch, target = line.strip.split(' -> ', 2)
next if keep.include?(branch) || keep.include?(target)