Consider the following scenario
function invert(color) {
var lookup = {
black: 'white',
white: 'black'
}
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
from Crypto.Cipher import AES | |
from Crypto import Random | |
from libmproxy.flow import decoded | |
BS = 16 | |
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) | |
unpad = lambda s : s[0:-ord(s[-1])] | |
def decrypt( enc, key ): | |
iv = enc[:16] |
var fs = require('fs'); | |
var rfs = fs.readFileSync; | |
var wfs = fs.writeFileSync; | |
var path = require('path'); | |
var yaml = require('js-yaml'); | |
var inquirer = require('inquirer'); | |
var program = require('commander'); | |
var version = require('./package.json').version; | |
program |
{ | |
"cmd": ["/usr/local/bin/node", "$file"], | |
"selector": "*.js" | |
} |
// Y-combinator with memoization | |
var Yc = function (f, x) { | |
x = x || {}; | |
return function () { | |
var y = JSON.stringify([].slice.call(arguments)); | |
return x[y] || (x[y] = f(function (z) { | |
return Yc(f, x)(z); | |
}).apply(this, arguments)); |
// Another useful reducer | |
// | |
// Get unique values of a 1d array | |
function unique (a, b) { | |
if (a.indexOf(b) < 0) a.push(b) | |
return a | |
} | |
// Very simple use case | |
var arr = [1, 5, 7, 2, 2, 3, 3, 4, 5, 5, 52, 4, 1, 2, 9, 1, 3, 5] |
// Found myself needing to do this the other day... | |
// | |
// Map an array of objects down to a single object in one pass | |
function distill (a, b) { | |
a[b.name] = b.value; | |
return a; | |
} | |
// Say you have objects that follow this format | |
var obj1 = { |
/*global document*/ | |
//a function to get DOM nodes by nodeType property. | |
//If you do not supply a value I will give you every DOM node. | |
// | |
//example: | |
// var allComments = document.getNodesByType(8); | |
// or | |
// var allComments = document.getNodesByType("COMMENT_NODE"); | |
// | |
//The accepted string values are the actual node type names, so that the |
stopBefore(document, 'getElementById')
stopBefore('document.getElementById') // the same as the previous
stopBefore(Element.prototype, 'removeChild')