Skip to content

Instantly share code, notes, and snippets.

@jt
jt / merge.md
Created Aug 23, 2011
Merge a forked gist
View merge.md

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
    
@jt
jt / populate.rb
Created Aug 23, 2011
Rails populate script
View populate.rb
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 / deploy.rb
Created Aug 23, 2011
Heroku deploy script
View deploy.rb
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 / regext.txt
Created Aug 22, 2011
Regular expression notes
View regext.txt
- 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 / phone_number_regex.rb
Created Jun 5, 2011
Phone number regular expression pattern
View phone_number_regex.rb
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 / tabular_steps.rb
Created May 31, 2011
Cucumber tabular steps for tables and lists
View tabular_steps.rb
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