Skip to content

Instantly share code, notes, and snippets.

View markysharky70's full-sized avatar

Mark Wilson markysharky70

View GitHub Profile
@matthewbednarski
matthewbednarski / postal-codes.json
Last active May 3, 2024 14:52
Global postal codes regex formats
[{ "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":
@drush
drush / delayed_job_threads.rb
Last active July 13, 2020 13:17
Run Delayed Job Worker as a Thread in Web Process
# 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]}"
@flomotlik
flomotlik / Gemfile
Last active April 6, 2021 13:17
Puma on Heroku
gem 'foreman'
gem 'puma'
@ddonahue99
ddonahue99 / token_input_helpers.rb
Last active December 20, 2015 10:31 — forked from jtanium/token_input_helpers.rb
jquery.tokeninput.js cucumber helper, updated with capybara 2.1 and theme support
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
@subelsky
subelsky / puma_rails_heroku.rb
Created October 31, 2012 13:51
Setting up Puma and Rails on Heroku
# 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:
@fixr
fixr / heroku_scaler.rb
Created October 4, 2012 22:12 — forked from JustinLove/heroku_scaler.rb
Sidekiq Herkou autoscaler with heroku-api gem
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
(function($) {
function parseImagesFromCSS(doc) {
var i, j,
rule,
image,
pattern = /url\((.*)\)/,
properties = ['background-image', '-webkit-border-image'],
images = {};
if (doc.styleSheets) {
@jtanium
jtanium / token_input_helpers.rb
Created September 20, 2011 17:11
TokenInput Cucumber Helper
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
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
@robhurring
robhurring / app.rb
Created November 23, 2010 17:03
ActiveRecord query caching with Sinatra
# 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