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
var CountryCodes = (function() { | |
// Codes taken from Wikipedia as of Wed Apr 16 2014 | |
var codes = {"AFG": "AF", "ALA": "AX", "ALB": "AL", "DZA": "DZ", "ASM": "AS", "AND": "AD", "AGO": "AO", "AIA": "AI", "ATA": "AQ", "ATG": "AG", "ARG": "AR", "ARM": "AM", "ABW": "AW", "AUS": "AU", "AUT": "AT", "AZE": "AZ", "BHS": "BS", "BHR": "BH", "BGD": "BD", "BRB": "BB", "BLR": "BY", "BEL": "BE", "BLZ": "BZ", "BEN": "BJ", "BMU": "BM", "BTN": "BT", "BOL": "BO", "BES": "BQ", "BIH": "BA", "BWA": "BW", "BVT": "BV", "BRA": "BR", "IOT": "IO", "BRN": "BN", "BGR": "BG", "BFA": "BF", "BDI": "BI", "KHM": "KH", "CMR": "CM", "CAN": "CA", "CPV": "CV", "CYM": "KY", "CAF": "CF", "TCD": "TD", "CHL": "CL", "CHN": "CN", "CXR": "CX", "CCK": "CC", "COL": "CO", "COM": "KM", "COG": "CG", "COD": "CD", "COK": "CK", "CRI": "CR", "CIV": "CI", "HRV": "HR", "CUB": "CU", "CUW": "CW", "CYP": "CY", "CZE": "CZ", "DNK": "DK", "DJI": "DJ", "DMA": "DM", "DOM": "DO", "ECU": "EC", "EGY": "EG", "SLV": "SV", "GNQ": "GQ", "ERI": "ER", "EST": "EE", "ETH": "ET", |
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
# See http://stackoverflow.com/questions/11007111/ruby-whats-an-elegant-way-to-pick-a-random-line-from-a-text-file | |
class IO | |
# Selects a random "line" from a file (might not be a line if different separator is passed). | |
# @param *args Same arguments as IO.foreach | |
# @return A random line from the IO object | |
def self.random_line(*args) | |
chosen_line = nil | |
self.foreach(*args).each_with_index do |line, number| | |
chosen_line = line if rand < 1.0/(number+1) | |
end |
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
// Assumes your L.Map is called "map". Untested! | |
map.dragging.disable(); | |
map.touchZoom.disable(); | |
map.doubleClickZoom.disable(); | |
map.scrollWheelZoom.disable(); | |
map.boxZoom.disable(); | |
map.keyboard.disable(); | |
if (map.tap) { | |
map.tap.disable(); | |
} |
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
# Converts a phone number with letters to a phone number with only numbers. | |
# Leaves any other characters untouched. | |
class VanityPhoneNumberConverter | |
LETTER_TO_NUMBER = { | |
'a' => '2', 'b' => '2', 'c' => '2', | |
'd' => '3', 'e' => '3', 'f' => '3', | |
'g' => '4', 'h' => '4', 'i' => '4', | |
'j' => '5', 'k' => '5', 'l' => '5', | |
'm' => '6', 'n' => '6', 'o' => '6', | |
'p' => '7', 'q' => '7', 'r' => '7', 's' => '7', |
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
CONTENT_TYPES = {:html => 'text/html', :css => 'text/css', :js => 'application/javascript'} | |
before do | |
# instead of using case here, metaprogram it | |
request_uri = case request.env['REQUEST_URI'] | |
when /\.css$/ : :css | |
when /\.js$/ : :js | |
else :html | |
end | |
content_type CONTENT_TYPES[request_uri], :charset => 'utf-8' |
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 delegateHandler(e){ | |
var element = e.element(), elements = element.ancestors ? element.ancestors().concat([element]) : [element]; | |
((Element.retrieve(this, 'prototype_delegates') || $H()).get(e.eventName || e.type) || []).each(function(pair){ | |
if (element = Selector.matchElements(elements, pair.key)[0]) | |
pair.value.invoke('call', element, e); | |
}); | |
} | |
function delegate(element, selector, event, handler){ |
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
# List of environments and their heroku git remotes | |
ENVIRONMENTS = { | |
:staging => 'myapp-staging', | |
:production => 'myapp-production' | |
} | |
namespace :deploy do | |
ENVIRONMENTS.keys.each do |env| | |
desc "Deploy to #{env}" | |
task env 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
Element.Methods.centerIsWithinViewport = function(element) { | |
var dim = document.viewport.getDimensions(); | |
var so = document.viewport.getScrollOffsets(); | |
var co = element.cumulativeOffset(); | |
var edim = element.getDimensions(); | |
// x and y measured from upper left | |
var center = { | |
x: co.left + (edim.width / 2), | |
y: co.top + (edim.height / 2) | |
} |
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
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb | |
# and made a lot more robust by me | |
# this implementation uses erb by default. if you want to use any other template mechanism | |
# then replace `erb` on line 13 and line 17 with `haml` or whatever | |
module Sinatra::Partials | |
def partial(template, *args) | |
template_array = template.to_s.split('/') | |
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" | |
options = args.last.is_a?(Hash) ? args.pop : {} | |
options.merge!(:layout => false) |
OlderNewer