Skip to content

Instantly share code, notes, and snippets.

Avatar

Zheng Jia zhengjia

  • Sport Ngin
  • Minneapolis
View GitHub Profile
View sql_log.rb
~/.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
View gist:395021
# 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'
View 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
View spec.opts
--colour
--format specdoc
--loadby mtime
--reverse
@zhengjia
zhengjia / env.rb
Created May 27, 2010
env.rb for selenium
View env.rb
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'
View rubyclosure.rb
# 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:
View array_comparison.rb
#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:
View jquery_contents.js
$('.container').contents().filter(function() {
return this.nodeType == 3;
})
.wrap('<p></p>')
.end()
.filter('br')
.remove();
#http://api.jquery.com/contents/
View .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 Jun 4, 2010
built-in webrat steps for cucumber cheatsheet
View built-in web_step 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 |
You can’t perform that action at this time.