Skip to content

Instantly share code, notes, and snippets.

View jt's full-sized avatar

JT Marino jt

View GitHub Profile
@jt
jt / tabular_steps.rb
Created May 31, 2011 03:07
Cucumber tabular steps for tables and lists
Then /^(?:|I )should see the following table:$/ do |table|
table.diff! tableish("table tr", "td,th")
end
Then /^(?:|I )should see the following list:$/ do |table|
table.raw.each_with_index do |element, i|
page.should have_xpath("//li[#{i+1}][contains(normalize-space(.), '#{element.first}')]")
end
end
@jt
jt / phone_number_regex.rb
Created June 5, 2011 19:49
Phone number regular expression pattern
def match(number)
/\+?(\d)?[-|\.|\s]?\(?(\d{3})\)?[-|\.|\s]?(\d{3})[-|\.|\s]?(\d{4})/.match number
end
# test match and captures against possibilities
[
['3335557777', nil, '333', '555', '7777'],
['333-555-7777', nil, '333', '555', '7777'],
['333.555.7777', nil, '333', '555', '7777'],
['333 555 7777', nil, '333', '555', '7777'],
@jt
jt / regext.txt
Created August 22, 2011 18:41
Regular expression notes
- any character you use it will literally match it except special characters
^ $ ? . / \ [ ] { } ( ) + * - all the special characters that will need escaping if you don't want them to be special
// - regexp ruby class
Common Patterns (I authored)
/[\w+\.~-]+@[\w~-]+.[\w\.]+/ - match emails, conforms to RFC 3986 section 3.3
/\+?(\d)?[-|\.|\s]?\(?(\d{3})\)?[-|\.|\s]?(\d{3})[-|\.|\s]?(\d{4})/ - match phone numbers, https://gist.github.com/1009331
Strategies
@jt
jt / deploy.rb
Created August 23, 2011 14:53
Heroku deploy script
namespace :deploy do
desc 'Deploy to staging'
task :staging do
push_to('johmas-staging')
`heroku run rake db:populate --app johmas-staging`
end
desc 'Deploy to production'
task :production do
@jt
jt / populate.rb
Created August 23, 2011 14:55
Rails populate script
namespace :db do
desc 'Populate test data'
task :populate => ['db:reset'] do
populate 'users' do
['john', 'jane'].each do |name|
Fabricate(:user, email: name+'@example.com')
end
end
@jt
jt / merge.md
Created August 23, 2011 18:47
Merge a forked gist

If someone forks a gist and you'd like to merge their changes. Do this:

  1. clone your repo, I use the name of the gist

     git clone git://gist.github.com/1163142.git gist-1163142
    
  2. add a remote for the forked gist, I'm using the name of my fellow developer

     git remote add aaron git://gist.github.com/1164196.git