This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com | |
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below) | |
module Player | |
describe MovieList, "with optional description" do | |
it "is pending example, so that you can write ones quickly" | |
it "is already working example that we want to suspend from failing temporarily" do | |
pending("working on another feature that temporarily breaks this one") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ActiveRecord refuses to enable query caching _unless_ you have the following setup | |
# 1) you _must_ use ActiveRecord::Base.configurations to store your auth details | |
# 2) you _must_ include the ActiveRecord::QueryCache middleware | |
# 3) you _must_ inherit from the _Base_ connection -- abstract models don't | |
# cache without a bit of hacking, it only query caches anything from AR::Base | |
require 'sinatra' | |
require 'active_record' | |
# query caching requires that you use AR::Base.configurations to store your |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "nokogiri" | |
class PlainTextExtractor < Nokogiri::XML::SAX::Document | |
attr_reader :plaintext | |
# Initialize the state of interest variable with false | |
def initialize | |
@interesting = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TokenInputHelpers | |
def token_input(locator, options) | |
raise "Must pass a hash containing 'with'" unless options.is_a?(Hash) && options.has_key?(:with) | |
field = _find_fillable_field(locator) # find the field that will ultimately be sent to the server, the one the user intends to fill in | |
# Delete the existing token, if present | |
begin | |
# This xpath is finds a <ul class='token-input-list'/> followed by a <input id="ID"/> | |
within(:xpath, "//ul[@class='token-input-list' and following-sibling::input[@id='#{field[:id]}']]") do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
function parseImagesFromCSS(doc) { | |
var i, j, | |
rule, | |
image, | |
pattern = /url\((.*)\)/, | |
properties = ['background-image', '-webkit-border-image'], | |
images = {}; | |
if (doc.styleSheets) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'heroku-api' | |
module Background | |
class HerokuScaler | |
def initialize( | |
type = 'worker', | |
app = ENV['HEROKU_APP']) | |
@client = Heroku::API.new # ENV['HEROKU_API_KEY'] must be present | |
@type = type | |
@app = app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
gem "puma" | |
# Procfile | |
web: bundle exec puma -p $PORT -e $RACK_ENV -C config/puma.rb | |
# add to config block config/environments/production.rb | |
config.threadsafe! | |
# get rid of NewRelic after_fork code, if you were doing this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TokenInputHelpers | |
THEME = '' # set to 'facebook' or 'mac' if using themes | |
def token_input(locator, options) | |
raise "Must pass a hash containing 'with'" unless options.is_a?(Hash) && options.has_key?(:with) | |
theme = THEME.present? ? "-#{THEME}" : "" | |
field = _find_fillable_field(locator) # find the field that will ultimately be sent to the server, the one the user intends to fill in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'foreman' | |
gem 'puma' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Only run in server process, not console or rake tasks | |
if !Rails.const_defined?('Console') && !($0 =~ /rake$/) && !Rails.env.test? | |
Rails.application.config.after_initialize do | |
(1..2).each do |thread_id| | |
Thread.new { | |
Thread.current[:thread_name] = "DJ Web Worker Thread #{thread_id}" | |
ActiveRecord::Base.connection_pool.with_connection do |conn| | |
dj = Delayed::Worker.new | |
Rails.logger.warn "Starting #{Thread.current[:thread_name]}" |
OlderNewer