Skip to content

Instantly share code, notes, and snippets.

def within_list(css_class)
css_selector = css_class.gsub(/ /, '.') #stack the css classes for selection
list = current_dom.at("ol.#{css_selector}") || current_dom.at("ul.#{css_selector}") # Could add an opt param to the method to make this explicit - for now we don't care
assert_not_nil(list, "Expected to find a ul or li tag matching the css class '#{css_class}'")
yield list
end
Then /^I should see the text "(.*)" in the "(.*)" list$/ do |text, css_class| #"
within_list(css_class) do |list|
matching_list_items = list.search("li").select{ |li| strip_html_tags_from(li.inner_html) =~ escape_text_for_regexp(text) }
@xnzac
xnzac / Guardfile
Created August 29, 2011 20:16
Guard file for running test unit / spec files
# More info at https://github.com/guard/guard#readme
# Instructions:
# 1) gem install guard guard-shell
# 2) run guard in root
# run test with 'redgreen' gem(for colour) if available otherwise with plain ruby
guard "shell" do
watch(%r{^(.+)/.+\.rb$}) do |m|
if File.exists?("#{m[1]}/#{m[1]}_test.rb")
@xnzac
xnzac / gist:1229941
Created September 20, 2011 18:47
R function for calculating A/B testing sample size from Ian Clarke(of 37signals)'s
# ref: http://37signals.com/svn/posts/3004-ab-testing-tech-note-determining-sample-size
#
# p1 = Variable A results. e.g. conversion rate from test A
# p2 = Variable B results
# power = chance of false negative (A power of 0.80 means that there is an 80% chance that if there was an effect, we would detect it )
# sig.level = chance of false positive (0.05 = 5%)
power.prop.test(p1=0.1, p2=0.11, power=0.8, alternative='two.sided', sig.level=0.05)
# Output will be a number signifying minimal sample size that meets the above criteria
@xnzac
xnzac / gist:1264178
Created October 5, 2011 11:01
Load javascript onto an existing web page
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= '/js-file.js';
document.head.appendChild(script);
@xnzac
xnzac / .tmux.conf
Created April 6, 2012 15:19 — forked from while0pass/.tmux.conf
My .tmux.conf set up based on http://pragprog.com/book/bhtmux/tmux
# Set prefix command to Ctrl-i; one of the easiest keys to reach
set -g prefix C-b
unbind C-a
# Reduce tmux delay for more responsiveness
set -sg escape-time 1
# Window and pane index count starts in 1 rather tan 0
set -g base-index 1
setw -g pane-base-index 1
@xnzac
xnzac / gist:3664238
Created September 7, 2012 08:00
北京欢迎你
北京欢迎你
作曲:小柯
作词:林夕
演唱:谭晶&谭智元
歌词制作:刘荣华(2008 8 26)
迎接另一个晨曦 带来全新空气
气息改变情味不变 茶香飘满情谊
我家大门常打开 开放怀抱等你
拥抱过就有了默契 你会爱上这里
@xnzac
xnzac / rgeo.rb
Created August 27, 2013 09:22
Add as_georss / as_kml methods as used by GeoRuby to RGeo::Cartesian::PointImpl
# add to config/initializers/
module GeoPointConversion
def as_georss
"<georss:point>#{y} #{x}</georss:point>\n"
end
def as_kml
"<Point>\n<coordinates>#{y},#{x}</coordinates>\n</Point>\n"
end
end
@xnzac
xnzac / github-fetch-forks
Last active December 25, 2015 16:09
Fetch all forks of github repository. Uses gems 'github_api' and 'hub'
#!/usr/bin/env ruby
# Install gems:
# gem install github_api
# gem install hub
#
# Then run script in github repo
require 'github_api'
g = Github.new
@xnzac
xnzac / how-to-search-in-forks
Created October 16, 2013 07:19
Search in forks for a fix/feature/anything good in commits from fork authors
# Motivation: you want to search in forks for an urgent fix
# I've wanted to do this a few times but couldn't find any other way to,
# so wrote this.
# 1) git clone main repo
# 2) in cloned folder, fetch all commits using script from https://gist.github.com/zaczheng/7003545
# 3) search in forks(excluding main author) for patterns in
@xnzac
xnzac / bundle_install_taobao.sh
Created November 18, 2013 07:51
Simple script to replace first line of Gemfile with taobao's rubygem mirror url for faster bundle install's
# Simple script to replace first line of Gemfile with taobao's rubygem mirror url
echo "Copying Gemfile to Gemfile_taobao using ruby.taobao.org"
echo
taobao="'source http\:\/\/ruby.taobao.org'"
sed "1s/.*/$taobao/" Gemfile > Gemfile_taobao
echo "bundle install --gemfile Gemfile_taobao --local"
bundle install --gemfile Gemfile_taobao --local