Skip to content

Instantly share code, notes, and snippets.

@bru
bru / cucumber_disable_gc.rb
Created February 2, 2011 17:19
GC tweak to speed up Cucumber tests
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 1.0).to_f
@@last_gc_run = Time.now
Before do
begin_gc_deferment
end
After do
reconsider_gc_deferment
@bru
bru / hash_from_xml.rb
Created January 14, 2011 12:43
Allows to create a hash out of an XML file, uses nokogiri.
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
rescue Exception => e
# raise your custom exception here
end
end
@bru
bru / env.rb
Created December 23, 2010 09:22
monkey patch to fix webrat follow redirect behaviour with rails 3
# features/support/env.rb
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rack
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
@bru
bru / post-checkout
Created October 22, 2010 16:11
switches rails environment in passenger based on the git branch
#!/bin/sh
ref=$(git symbolic-ref HEAD 2> /dev/null)
if [[ -n $ref ]]; then
if [[ $ref =~ "master" ]]; then
rm public/.htaccess
else
echo "RailsEnv ${ref#refs/heads/}" > public/.htaccess
fi
@bru
bru / mvim.sh
Created September 30, 2010 10:44
mvim
#!/bin/sh
#
# This shell script passes all its arguments to the binary inside the
# MacVim.app application bundle. If you make links to this script as view,
# gvim, etc., then it will peek at the name used to call it and set options
# appropriately.
#
# Based on a script by Wout Mertens and suggestions from Laurent Bihanic. This
# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
# Weber and Bjorn Winckler, Aug 13 2007).
@bru
bru / texmate_dot_filter
Created June 12, 2010 09:14
TextMate dotfiles filter
# TextMate dotfiles filter
# use this filter in Preferences -> Advanced -> Folder References -> File Pattern
# to show .gitignore, .gems (useful for Heroku), .bundle in your project
!(/\.(?!(htaccess|gitignore|gems|bundle))[^/]*|\.(tmproj|o|pyc)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$
@bru
bru / basic-rails-template.rb
Created June 9, 2010 20:57
Basic Rails 2.3.5 Template with Bundler gem
@app_name = File.basename(@root)
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm public/images/rails.png"
run "rm -f public/javascripts/*"
run "rm config/database.yml"
@bru
bru / "weighted" tanimoto
Created February 1, 2010 17:39
Weighted Tanimoto algorithm
# weighted tanimoto for taggables
# works with acts_as_taggable_on_steroids,
# assuming you have a weight attribute in your Tagging model
def tanimoto(a,b)
a_size = a.taggings.map { |t| t.weight}.sum
b_size = b.taggings.map { |t| t.weight}.sum
return 0 if (a_size == 0 || b_size == 0)
c_size = a.taggings.map { |t| b.tag_list.include?(t.name) ? [t.weight, b.taggings.find_by_tag_id(t.tag_id).weight].min : 0 }.sum
@bru
bru / newpost.rb
Created December 25, 2009 16:33 — forked from jrk/newpost.rb
Creates a new Jekyll post, opens it in TextMate, and adds to the git index
#!/usr/bin/env ruby
require Dir
unless ARGV[0]
puts 'Usage: newpost "the post title"'
exit(-1)
end
blog_root = "/Users/jrk/proj/blog"
@bru
bru / Deploy.tmCommand
Created December 18, 2009 17:21 — forked from henrik/Deploy.tmCommand
TextMate command to deploy a Jekyll site through a tasks/deploy shell script.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>bundleUUID</key>
<string>C9BD1ADE-4FD9-4842-A641-DFB373B7D42C</string>
<key>command</key>
<string>#!/usr/bin/env ruby