Skip to content

Instantly share code, notes, and snippets.

View zhengjia's full-sized avatar

Zheng Jia zhengjia

  • Sport Ngin
  • Minneapolis
View GitHub Profile
#You can just use a set difference (aka minus) to see if one array includes all elements of another
not_included = [1,2,3] - (1..9).to_a
not_included # => []
not_included = [1,2,3,'A'] - (1..9).to_a
not_included # => ["A"]
#Use intersection to test if any of the one are in the other:
@zhengjia
zhengjia / rubyclosure.rb
Created June 1, 2010 19:32
ruby closure
# http://innig.net/software/ruby/closures-in-ruby.rb
# CLOSURES IN RUBY Paul Cantrell http://innig.net
# Email: username "cantrell", domain name "pobox.com"
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments,
# then trying to guess the output of the code!
# A closure is a block of code which meets three criteria:
@zhengjia
zhengjia / env.rb
Created May 27, 2010 02:19
env.rb for selenium
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode'
require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'webrat'
@zhengjia
zhengjia / spec.opts
Created May 16, 2010 06:54
spec.opts
--colour
--format specdoc
--loadby mtime
--reverse
@zhengjia
zhengjia / cucumber.yml
Created May 16, 2010 06:54
cucumber.yml
autospec-all: --require features --require lib --format progress features
autospec: --require features --require lib features
default: --format pretty
html: --format html --out features.html
@zhengjia
zhengjia / gist:395021
Created May 9, 2010 08:29 — forked from mbulat/gist:231022
rcov rake
# From http://github.com/jaymcgavren
#
# Save this as rcov.rake in lib/tasks and use rcov:all =>
# to get accurate spec/feature coverage data
#
# Use rcov:rspec or rcov:cucumber
# to get non-aggregated coverage reports for rspec or cucumber separately
require 'cucumber/rake/task'
require 'spec/rake/spectask'
~/.irbrc
if rails_env = ENV['RAILS_ENV']
# Called after the irb session is initialized and Rails has
# been loaded (props: Mike Clark).
IRB.conf[:IRB_RC] = Proc.new do
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.instance_eval { alias :[] :find }
end
end