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
[{ "Note": "The first two digits (ranging from 10–43) correspond to the province, while the last two digits correspond either to the city/delivery zone (range 01–50) or to the district/delivery zone (range 51–99). Afghanistan Postal code lookup", "Country": "Afghanistan", "ISO": "AF", "Format": "NNNN", "Regex": "^\\d{4}$" }, { "Note": "With Finland, first two numbers are 22.", "Country": "Åland Islands", "ISO": "AX", "Format": "NNNNN", "Regex": "^\\d{5}$" }, { "Note": "Introduced in 2006, gradually implemented throughout 2007.", "Country": "Albania", "ISO": "AL", "Format": "NNNN", "Regex": "^\\d{4}$" }, { "Note": "First two as in ISO 3166-2:DZ", "Country": "Algeria", "ISO": "DZ", "Format": "NNNNN", "Regex": "^\\d{5}$" }, { "Note": "U.S. ZIP codes (range 96799)", "Country": "American Samoa", "ISO": "AS", "Format": "NNNNN (optionally NNNNN-NNNN or NNNNN-NNNNNN)", "Regex": "^\\d{5}(-{1}\\d{4,6})$" }, { "Note": |
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]}" |
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
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
# 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
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
(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
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
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
# 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 |
NewerOlder