Skip to content

Instantly share code, notes, and snippets.

View therealklanni's full-sized avatar
👨‍💻
Learning Rust

Kevin Lanni therealklanni

👨‍💻
Learning Rust
View GitHub Profile
@therealklanni
therealklanni / accessors.md
Last active January 20, 2016 13:23
Demystifying Property Accessors

Examining the Object property accessor behavior

Consider the following scenario

function invert(color) {
  var lookup = {
    black: 'white',
    white: 'black'
 }
@therealklanni
therealklanni / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// 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
@therealklanni
therealklanni / Node.sublime-build
Last active August 29, 2015 14:01
Sublime Text Node.js Buildtool
{
"cmd": ["/usr/local/bin/node", "$file"],
"selector": "*.js"
}
@therealklanni
therealklanni / yc.js
Last active August 29, 2015 14:00
Memoized Y-combinator
// 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));
@therealklanni
therealklanni / unique.js
Created March 29, 2014 04:30
Get unique elements of an Array
// 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]
@therealklanni
therealklanni / distill.js
Created March 29, 2014 04:13
Array of Objects distiller
// 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.js

2min screencast

Examples

stopBefore(document, 'getElementById')
stopBefore('document.getElementById') // the same as the previous
stopBefore(Element.prototype, 'removeChild')