Skip to content

Instantly share code, notes, and snippets.

Avatar

Colin Bartlett cbartlett

View GitHub Profile
View shit.rb
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)
View novalentine.js
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";
}
}
}
View gist:799418
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
View config-initializers-setup_mail.rb
Mail.register_interceptor(StagingMailInterceptor) if Rails.env.staging? || Rails.env.acceptance?
View gist:3698644
find . -not \( -name .svn -prune -o -name .git -prune \) -type f -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"
@cbartlett
cbartlett / gist:3700171
Created Sep 11, 2012
Better hash match
View gist:3700171
# 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}"
@cbartlett
cbartlett / gist:3997549
Created Nov 1, 2012
git merge strategy
View gist:3997549
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 Nov 3, 2012
List remote branches by last updated date
View gist:4008195
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