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 scale() { | |
return document.body.clientWidth / window.innerWidth; | |
} |
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
/* | |
truncate text within HTML | |
does not work with malformed html | |
*/ | |
function html_truncate(elem, num_words, truncate_string) { | |
// local state | |
var original = elem, | |
current = elem.childNodes[0], | |
count = 0; |
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
/** | |
* not so simple check for object equality | |
*/ | |
var equal = function(a, b) { | |
function check(a, b) { | |
for (var attr in a) { | |
if (a.hasOwnProperty(attr) && b.hasOwnProperty(attr)) { | |
if (a[attr] != b[attr]) { | |
switch (a[attr].constructor) { | |
case Object: |
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 detect(obj, attr, exact) { | |
var results = [], | |
re = new RegExp(attr, 'i'); | |
// helper function for the recursion | |
function detectHelper(obj, attr, exact, path, results) { | |
for (var a in obj) { | |
// sanity check | |
if (!obj.hasOwnProperty(a)) | |
continue; |
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
# lines words bytes | |
# 5 17 102 | |
def rfib(n): | |
if n == 0 or n == 1: | |
return 1 | |
else: | |
return rfib(n-1) + rfib(n-2) | |
# 8 23 113 |
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
def load_datetime(value): | |
from datetime import datetime | |
if type(value) is str: | |
import re | |
JAVASCRIPT_DATE = re.compile(r'^\d{4}(?:-\d{2}){2}T(?:\d{2}:){2}\d{2}$') | |
PYTHON_DATE = re.compile(r'^\d{4}(?:-\d{2}){2}\s(?:\d{2}:){2}\d{2}$') | |
PYTHON_DATE_MICROSECONDS = re.compile(r'^\d{4}(?:-\d{2}){2}\s(?:\d{2}:){2}\d{2}\.\d+$') | |
STRING_NUMBER = re.compile(r'^\d+(\.\d+)?$') | |
if JAVASCRIPT_DATE.match(value): | |
return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S') |
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
dict((k, v[0] if len(v) == 1 else v) for k, v in [(k, [z[1] for z in v]) for k, v in itertools.groupby(sorted([x.split('=') for x in qs.split('&')], key=lambda x: x[0]), key=lambda x: x[0])]) |
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
/** | |
* When element is visible (has non-zero height), execute callback | |
*/ | |
function whenVisible(elem, cb) { | |
(function() { | |
if (elem.height() !== 0) { | |
cb(); | |
} else { | |
setTimeout(arguments.callee, 250); | |
} |
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
this.decay = function(feat, time, callback) { | |
var steps = 100; | |
var ts = time / steps; | |
for (var i = 0; i < steps; ++i) { | |
var opacity = 1 - ((i / steps)*.5); | |
(function(i, opacity){setTimeout(function() { | |
feat.style.fillOpacity = opacity; | |
feat.style.pointRadius = 4 * opacity; | |
commentsLayer.drawFeature(feat); | |
if (i == steps - 1) { |
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
import re | |
import pprint | |
import os | |
path = os.path.join(os.path.dirname(__file__), 'words.txt') | |
vowel_pattern = re.compile('[aeiou]', re.IGNORECASE) | |
def run(): | |
"""runs the program""" | |
input = raw_input('>') |
OlderNewer