Skip to content

Instantly share code, notes, and snippets.

View cbartlett's full-sized avatar

Colin Bartlett cbartlett

View GitHub Profile
Shoes.setup do
gem "mime-types"
gem "open4"
source "http://gems.github.com/"
gem "mojombo-grit"
end
require 'mojombo-grit'
repo = Grit::Repo.new(Dir.pwd)
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:
@cbartlett
cbartlett / gist:4008195
Created November 3, 2012 18:27
List remote branches by last updated date
for k in `git branch -r|awk '{print $1}'`;do echo `git show --pretty=format:"%Cgreen%ci %Cblue%cr %Cred%cn %Creset" $k|head -n 1`$k;done|sort -r