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 valid_first = []; | |
var valid_second = []; | |
for (var i = 0, len = 0xFFFF; i < len; i++) { | |
try{ | |
var char = String.fromCharCode(i); | |
if(char.toLowerCase() != char.toUpperCase() && valid_second.indexOf(char.toLowerCase().charCodeAt(0)) >= 0){ | |
continue; | |
} | |
document.body.setAttribute('a' + char, ''); | |
document.body.removeAttribute('a' + char); |
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
# Number of possible starting configurations of an enigma machine | |
letters = 26 | |
rotors_total = 5 | |
rotors_machine = 3 | |
cables = 10 # Must be < letters/2 | |
def f(n): # Factorial | |
s = 1; | |
for i in xrange(2, n+1): | |
s *= i |
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 makeStorage(){ | |
var keys = []; | |
var storage = Object.create(Object, { | |
getItem: {value: function(k) { | |
if(this.hasOwnProperty(k)) { | |
return this[k]; | |
} | |
}}, |
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 xml.etree.cElementTree as etree | |
def traverseEtree(tree,traverser): | |
traverser.start(tree) | |
traverser.data(tree.text) | |
for child in tree: | |
traverseEtree(child,traverser) | |
traverser.end(tree) | |
traverser.data(tree.tail) |
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
-- x-FOO-bAr -> X-Foo-Bar | |
function normalize_header(name) | |
name = upper(sub(name, 1, 1)) .. lower(sub(name, 2)) | |
while true do | |
local start,fin = find(name, '-[a-z]') | |
if start ~= nil then | |
name = sub(name, 1, start) .. upper(sub(name, fin, fin)) .. sub(name, fin+1) | |
else | |
break | |
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
function queryXPath(expr, ctx, type){ | |
ctx = ctx || document; | |
type = type || XPathResult.ANY_TYPE; | |
var doc = ctx.nodeType === Node.DOCUMENT_NODE ? ctx : ctx.ownerDocument; | |
var nsResolver = doc.createNSResolver(doc.documentElement); | |
var arr = [], i = null; | |
try { | |
expr = ("" + expr).replace(/\bhasClass\(["'](\w+)["']\)/, function(expr, className){ | |
return "contains(concat(' ', normalize-space(@class), ' '), ' " + className + " ')"; | |
}); |
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 getAllProperties(obj){ | |
var allProps = Object.getOwnPropertyNames(obj); | |
Object.getOwnPropertyNames(Object.getPrototypeOf(obj)).forEach(function add(prop){ | |
if (allProps.indexOf(prop) === -1) | |
allProps.push(prop) | |
}); | |
return allProps | |
} | |
function jsrecursivegrep(obj, value, length){ |
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
/** | |
* Levenshtein distance between two arrays or strings | |
*/ | |
function arrDistance(a, b) { | |
if(a.length === 0) { return b.length; } | |
if(b.length === 0) { return a.length; } | |
var matrix = []; | |
// increment along the first column of each row |
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
# Download every episode of How It's Made from Youtube | |
# Needs: youtube-dl | |
urlencode() { | |
python -c "import sys, urllib; print urllib.quote_plus(sys.stdin.read())" | |
} | |
dl(){ | |
q=`echo How its made $2 $3 $4 | urlencode` | |
youtube-dl --max-downloads=1 -o "HowItsMade_${1}_%(title)s_%(format)s.%(ext)s" "https://www.youtube.com/results?search_query=$q" |
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
from collections import Counter | |
import heapq | |
class SummaryDict(Counter): | |
""" | |
A counting dict that aggregates uncommon values in a "Others" key. | |
The full set of keys is kept in a separate counter, in case they need to | |
be added back to the main counter. |
OlderNewer