Skip to content

Instantly share code, notes, and snippets.

'''
redis_search.py
Written by Josiah Carlson July 3, 2010
Released into the public domain.
This module implements a simple TF/IDF indexing and search algorithm using
Redis as a datastore server. The particular algorithm implemented uses the
@micho
micho / gist:728639
Created December 5, 2010 00:40
Throttle and debounce examples
// Run the function as soon as it's called, but prevent further calls during `delay` ms
// Example: function.throttle(200) will only run function() once every 200 ms.
// Useful, for example, to avoid constant processing while typing in a live search box.
Function.prototype.throttle = function(delay) {
var fn = this
return function() {
var now = (new Date).getTime()
if (!fn.lastExecuted || fn.lastExecuted + delay < now) {
fn.lastExecuted = now
fn.apply(fn, arguments)
@pamelafox
pamelafox / countryinfo.py
Last active October 20, 2024 23:41
Python list of country codes, names, continents, capitals, and pytz timezones
countries = [
{'timezones': ['Europe/Andorra'], 'code': 'AD', 'continent': 'Europe', 'name': 'Andorra', 'capital': 'Andorra la Vella'},
{'timezones': ['Asia/Kabul'], 'code': 'AF', 'continent': 'Asia', 'name': 'Afghanistan', 'capital': 'Kabul'},
{'timezones': ['America/Antigua'], 'code': 'AG', 'continent': 'North America', 'name': 'Antigua and Barbuda', 'capital': "St. John's"},
{'timezones': ['Europe/Tirane'], 'code': 'AL', 'continent': 'Europe', 'name': 'Albania', 'capital': 'Tirana'},
{'timezones': ['Asia/Yerevan'], 'code': 'AM', 'continent': 'Asia', 'name': 'Armenia', 'capital': 'Yerevan'},
{'timezones': ['Africa/Luanda'], 'code': 'AO', 'continent': 'Africa', 'name': 'Angola', 'capital': 'Luanda'},
{'timezones': ['America/Argentina/Buenos_Aires', 'America/Argentina/Cordoba', 'America/Argentina/Jujuy', 'America/Argentina/Tucuman', 'America/Argentina/Catamarca', 'America/Argentina/La_Rioja', 'America/Argentina/San_Juan', 'America/Argentina/Mendoza', 'America/Argentina/Rio_Gallegos', 'America/Argentina/Ushuai
@addyosmani
addyosmani / visibly.js
Created August 3, 2011 12:44
Cross-browser Page Visibility API polyfill
/*!
* isVis - v0.5.5 Aug 2011 - Page Visibility API Polyfill
* Copyright (c) 2011 Addy Osmani
* Dual licensed under the MIT and GPL licenses.
*/
(function () {
window.visibly = {
b: null,
q: document,
@xnzac
xnzac / gist:1229941
Created September 20, 2011 18:47
R function for calculating A/B testing sample size from Ian Clarke(of 37signals)'s
# ref: http://37signals.com/svn/posts/3004-ab-testing-tech-note-determining-sample-size
#
# p1 = Variable A results. e.g. conversion rate from test A
# p2 = Variable B results
# power = chance of false negative (A power of 0.80 means that there is an 80% chance that if there was an effect, we would detect it )
# sig.level = chance of false positive (0.05 = 5%)
power.prop.test(p1=0.1, p2=0.11, power=0.8, alternative='two.sided', sig.level=0.05)
# Output will be a number signifying minimal sample size that meets the above criteria
@enriqueaf
enriqueaf / gist:1317935
Created October 26, 2011 21:28
First try for middleman and pjax
paths_for_url('/guides/*').each do |url|
get(url) do |p|
page "/pjax/guides/#{p}", :proxy=>"/guides/#{p}",:layout=>"pjax"
end
end
@seutje
seutje / _rgba.scss
Created November 4, 2011 15:17
rgba mixin
@mixin rgba-ie($color, $alpha) {
$rgba: rgba($color, $alpha);
$ie-hex-str: ie-hex-str($rgba);
background-color: transparent;
background-color: $rgba;
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#{$ie-hex-str},endColorstr=#{$ie-hex-str});
zoom: 1;
}
@agius
agius / json_diff.rb
Created May 8, 2012 00:52
Ruby JSON Diff
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
unless ARGV.count > 1
puts "Usage: json_diff.rb json_file_1.json json_file_2.json"
exit
end
def different?(a, b, bi_directional=true)
@danshearmur
danshearmur / gist:3653869
Last active October 10, 2015 07:18
Conditionally load zepto or jQuery with yepnope
var zep = "__proto__" in window;
yepnope([{
test: zep,
yep: '/static/js/zepto.js',
nope: '//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js',
complete: function () {
!zep && !window.jQuery && yepnope('/static/js/jquery-1.8.1.min.js');
}
});
@jonathantneal
jonathantneal / README.md
Created September 19, 2012 06:34
Polyfill the EventListener interface in IE8

EventListener Polyfill

Is IE8 your new IE6? Level the playing field with polyfills.

This script polyfills addEventListener, removeEventListener, and dispatchEvent. It is less than half a kilobyte minified and gzipped.

addEventListener

addEventListener registers a single event listener on a single target.