Skip to content

Instantly share code, notes, and snippets.

View zhengjia's full-sized avatar

Zheng Jia zhengjia

  • Sport Ngin
  • Minneapolis
View GitHub Profile
~/.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
@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'
@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 / spec.opts
Created May 16, 2010 06:54
spec.opts
--colour
--format specdoc
--loadby mtime
--reverse
@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 / 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:
#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 / jquery_contents.js
Created June 2, 2010 20:02
jquery content()
$('.container').contents().filter(function() {
return this.nodeType == 3;
})
.wrap('<p></p>')
.end()
.filter('br')
.remove();
#http://api.jquery.com/contents/
@zhengjia
zhengjia / .bashrc
Created June 3, 2010 03:18
.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
@zhengjia
zhengjia / built-in web_step cheatsheet
Created June 4, 2010 00:00
built-in webrat steps for cucumber cheatsheet
Given I am on "[page_name]"
When I go to "[page_name]"
When I press "[button]"
When I follow "[link]"
When I follow "[link]" within "[parent]"
When I fill in "[field]" with "[value]"
When I fill in "[value]" for "[field]"
When I fill in the following:
| field | value |