Skip to content

Instantly share code, notes, and snippets.

# Setup the following in your heroku config vars:
# See http://blog.leshill.org/blog/2010/11/02/heroku-environment-variables.html for an idea on how to do it
HEROKU_APP: poh-dev
HEROKU_USER: [email protected]
HEROKU_PASSWORD: replace_me
# Gemfile
gem 'heroku', '>= 1.19.1'
gem 'resque'
# Use our fork until our fix is merged.
@leshill
leshill / gist:882626
Created March 23, 2011 04:41
Using brew? Want git tab completion in bash? Add to your .bashrc (or .bashrc.local)
git_completion=`brew --prefix git`/etc/bash_completion.d/git-completion.bash
if [ -f $git_completion ] ; then source $git_completion; fi
@leshill
leshill / gist:870866
Created March 15, 2011 15:17
Cucumber/Capybara JS alert handling
# Add this to more_web_steps.rb
# Selenium docs: http://code.google.com/p/selenium/wiki/RubyBindings#Javascript_Alert/Confirm today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
alert.send(action)
end
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort
def access_token
@access_token ||= begin
twitter_request = session['twitter_request']
oauth.authorize_from_request(twitter_request.token, twitter_request.secret, params['oauth_verifier'])
oauth.access_token
end
end
def oauth(opts = {})
@oauth ||= ::Twitter::OAuth.new(config.twitter_api_keys['token'], config.twitter_api_keys['secret'], opts)
RSpec.configure do |config|
config.before(:all) do
clear_database
end
end
def clear_database
Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
end
# place in features/support
require 'ephemeral_response'
EphemeralResponse.configure do |config|
config.expiration = lambda { one_day * 30 }
config.white_list = ['localhost', '127.0.0.1']
config.register('api.twitter.com') do |request|
if oauth_token_match = request['authorization'].match(/oauth_token=\"\d+-\w+"/)
"#{request.uri.to_s}#{request.method}#{oauth_token_match[0]}"
else
class Array
def method_missing(method, *args, &block)
if key_value = dynamic_mapper?(method)
map_dynamically(key_value[1], key_value[2])
else
super
end
end
def dynamic_mapper?(method)
def javascript_confirm(answer)
page.evaluate_script 'window._confirm = window.confirm'
page.evaluate_script "window.confirm = function(x) { return #{answer} }"
yield
page.evaluate_script 'window._confirm && (window.confirm = window._confirm)'
page.evaluate_script 'window._confirm = null'
end
# Ryan, the hits in the db approach is flawed (not currently atomic, and
# probably not really performant for high rates) -- but you knew that.
# So in the spirit of gets it done, I have followed along.
#
# API Example
## User Model
require 'digest/md5'
class User < ActiveRecord::Base
API_RATE_LIMIT_WINDOW = 2.minutes