This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
N = 100_000 | |
a = [] | |
100.times { a << (rand(10) > 5 ? true : false) } | |
Benchmark.bm(35) { |x| | |
x.report("String#to_i(base)") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based of Jay Fields' implementation (http://blog.jayfields.com/2007/11/ruby-timeis.html) | |
# | |
# Usage: | |
# Time.freeze do |time| | |
# Time.now.should.equal(time) | |
# end | |
class Time | |
def self.metaclass | |
class << self; self; end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 7f6cc03fccee270ecb1848880e54b240371c7311 Mon Sep 17 00:00:00 2001 | |
From: Chris Gaffney | |
Date: Fri, 6 Feb 2009 11:49:47 -0500 | |
Subject: [PATCH] Subcontexts inherit outer context Test::Unit::TestCase by default. | |
--- | |
lib/test/spec.rb | 4 ++-- | |
test/spec_nestedcontexts.rb | 19 +++++++++++++++++++ | |
2 files changed, 21 insertions(+), 2 deletions(-) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Automatically set gateway if it is specified on the command line | |
if ARGV.detect { |g| g =~ /GATEWAY=(.*)/ } | |
set :gateway, $1 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
gem 'gaffneyc-bunny' | |
require 'bunny' | |
# Example of simple RPC using server named queues | |
Bunny.open do |amqp| | |
# Exchange definition | |
amqp.exchange('reply', :type => :direct) | |
amqp.exchange('out', :type => :direct) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source ~/.vim/common-gvimrc.vim | |
" 256 color colorscheme | |
:colorscheme vividchalk | |
" Maximize both dimensions when going fullscreen | |
:set fuopt=maxhorz,maxvert | |
":set transparency=8 | |
command -nargs=0 Zoom :macaction performZoom: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# script/server with Rails 3 support | |
ss() { | |
if [ -f ./script/rails ]; then | |
./script/rails server $@ | |
else | |
./script/server $@ | |
fi | |
} | |
# script/console with Rails 3 support |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'selenium-webdriver' | |
class Capybara::Driver::Selenium < Capybara::Driver::Base | |
def self.driver | |
unless @driver | |
@driver = Selenium::WebDriver.for :firefox, :profile => 'webdriver' | |
at_exit do | |
@driver.quit | |
end | |
end | |
@driver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Number | |
include Mongoid::Document | |
field :number, :type => Integer | |
end | |
Number.delete_all | |
Number.create(:number => 50) | |
Number.where( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:2,3s/context "\(.*\)".*/describe \1 do/ | |
:2,3s/context '\(.*\)'.*/describe \1 do/ | |
:%s/\.be\.nil/ be_nil/g | |
:%s/\.be nil/ be_nil/g | |
:%s/\.be true/ be_true/g | |
:%s/\.be(true)/ be_true/g | |
:%s/\.equal(true)/ be_true/g | |
:%s/\.be false/ be_false/g | |
:%s/\.be(false)/ be_false/g | |
:%s/\.equal(false)/ be_false/g |
OlderNewer