Skip to content

Instantly share code, notes, and snippets.

View cbartlett's full-sized avatar

Colin Bartlett cbartlett

View GitHub Profile
#!/usr/bin/env ruby
require 'json'
if ARGV.length < 3 then
puts "Usage: squirt <filename> <channel> <comment>"
exit
end
token = ENV['TOKEN'] || ""
#! /bin/bash
# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/postgres"
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR/$YMD"
mkdir -p $DIR
cd $DIR
# make database backup
var banList = ["valentine", "Valentine", "Valentine's","Valentines","valentine's","valentines","v-day","V-day","V-Day","vday","Vday","VDay","VALENTINE","VALENTINE'S"];
var allUpdates = document.getElementsByTagName('h3');
for (phrases in banList) {
for (eachUpdate in allUpdates) {
if (allUpdates[eachUpdate].innerHTML.match(banList[phrases])) {
allUpdates[eachUpdate].parentNode.parentNode.style.display = "none";
}
}
}
Given /^that ([^"]*) has (\d+) ([^"]*)$/ do |parent, count, child|
parent = parent.gsub(/\W+/,'_').downcase.sub(/^_/, '')
parent_instance = instance_variable_get("@#{parent}")
child = child.gsub(/\W+/,'_').downcase
child_class = Fabrication::Support.class_for(child.singularize)
if child_class && !child_class.new.respond_to?("#{parent}=")
parent = parent.pluralize
parent_instance = [parent_instance]
end
Mail.register_interceptor(StagingMailInterceptor) if Rails.env.staging? || Rails.env.acceptance?
@cbartlett
cbartlett / gist:3698644
Created September 11, 2012 13:51
Kill whitespace!
find . -not \( -name .svn -prune -o -name .git -prune \) -type f -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"
@cbartlett
cbartlett / gist:3700171
Created September 11, 2012 17:42
Better hash match
# I want to have better messaging, diffs, etc. here
RSpec::Matchers.define :include_hash do |expected|
match do |actual|
binding.pry
!expected.map {|k,v| actual[k] == v }.include?(false)
end
failure_message_for_should do |actual|
"expected that #{actual} would include all the key/values of #{expected}"
this
is
a
test
this
is
a
test
@cbartlett
cbartlett / gist:3997549
Created November 1, 2012 23:36
git merge strategy
Pull in the latest commits:
$ git fetch
Rebase your branch on top of the remote master:
$ get rebase origin/master
Go back to master:
$ git checkout master
Fetch pulls down commits but doesn't apply them. So you need to put those commits on master: