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 safe_eval(code, ctx) { | |
return (new Function (["window", "undefined"], "try { " + code + " } catch (e){ return e; }"))(ctx); | |
} | |
function restrict (base, perm) { | |
var out = {}, k = null, | |
READ = 'read', | |
WRITE = 'write', | |
RW = 'readwrite'; | |
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 (window, document, undefined) { | |
var m = window.micro = {}, | |
whiteSpaceRxp = /[\r\n\t\s]/g, | |
quotesRxp = /['"]/g, | |
attrRxp = /<%=\s*([\w_\$\.]+)\s*%>/ig; | |
// Convert template to use consistent quotes, remove unnecessary whitespace | |
// returns: the normalized template string | |
function normalizeTemplate(tpl) { | |
return tpl.replace(whiteSpaceRxp, ' ').replace(quotesRxp, "'"); |
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
/* Just define a simple is_a fn and populate it with functions | |
* that correspond to the primary JS objects; interface is | |
* | |
* is_a.array([]) >> true | |
*/ | |
;(function (window, undefined){ | |
var upFirst = /^(\w)/, | |
toS = Object.prototype.toString, | |
builtIns = ['Array', 'Object', 'Number', 'String', 'Window', 'RegExp', 'Function']; | |
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 (window) { | |
if (window.top !== window.self) { | |
killFrame(); | |
} | |
var _frame_ = "<html><head><title>Not Allowed</title>\ | |
</head><body><h1>We don't allow This</h1></body></html>"; | |
function killFrame() { | |
document.open(); |
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
// space complexity: O(n) -- the hashmap | |
// time complexity: ~O(2n); iterate both strings once | |
// worse case: O(2n) | |
function areAnagrams(a, b) { | |
var len = a.length, chars = {}, i = 0; | |
if (len !== b.length) return false; | |
for(; i < len; i++) { | |
chars[a[i].toLowerCase()] = true; | |
} |
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
#!/bin/bash | |
# Parallelize the execution of a command | |
###### | |
CHUNK_COUNT=0 | |
parallel_configure () { | |
if [ $# -eq 0 ]; then | |
echo "usage: <tmp dir> <tmp prefix> <num chunks>" | |
fi |
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
// inefficient because you call append multiple times | |
// this causes a reflow on each call (https://developer.mozilla.org/en-US/docs/Notes_on_HTML_Reflow) | |
$('#my-el').append('<div>hi</div>').append('<div>two</div>').append('<div>three</div>'); | |
// you could just make 1 string of HTML | |
var to_append = '<div>hi</div><div>two</div><div>three</div>'; | |
$('#my-el').append(to_append); | |
// or you can use documentFragment; | |
// documentFragment is a container for DOM elements that, when you eventually attach it to the DOM, disappears so |
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
# Script Template | |
# @author nickjacob | |
require 'pp' | |
def print_json json | |
pp json | |
end | |
def perform argv | |
while line = gets.chomp |
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
__deep = (obj, prop) -> | |
for p in prop.split '.' | |
if not (p in obj and obj = obj[p]) | |
return undefined | |
obj() if typeof obj is 'function' else obj | |
getEscape = (tpl) -> | |
qq = "\'" if '"' in tpl else "\"" | |
(str) -> qq + str + qq | |
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
inputRe = /input|select|textarea/i # some browsers do uppercase tagNames; also faster than 3 strcmp | |
cache = {} | |
elByName = (el) -> | |
cache[el.name] ?= document.getElementsByName el.name | |
document.addEventListener 'load', (e) -> | |
document.addEventListener 'change', (e) -> | |
target = e.target | |