This is now an actual repo:
This file contains hidden or 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
param: function (obj, prefix) { | |
var arr = []; | |
for (var key in obj) { | |
var __prefix = prefix ? prefix + '[' + key + ']' : key, | |
value = obj[key]; | |
arr.push(typeof value == 'object' ? | |
param(value, __prefix) : | |
encodeURIComponent(__prefix) + '=' + encodeURIComponent(value)); | |
} |
This file contains hidden or 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 camelCase (string, separator) { | |
return string.split(separator).map((word, index) => word.substr(0,1)[index ? 'toUpperCase' : 'toLowerCase']() + word.substr(1) ).join(''); | |
} | |
console.log(camelCase('metal gear solid', ' ')); | |
// metalGearSolid | |
function undoCamelCase (string, separator) { | |
return string.split('').map((letter) => letter.toLowerCase() !== letter ? separator + letter.toLowerCase() : letter).join(''); | |
} |
This file contains hidden or 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
/** | |
* flattens a nested array | |
* 1. takes an array and optional destination array | |
* 2. iterates through the array | |
* 3. if an item in the array is an array | |
* run through flatten with the second argument | |
* as the destination array | |
* this will add every item within the passed array | |
* into the destination array |
This file contains hidden or 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
requestAnimationFrame(function () { | |
setTimeout(function () { | |
fn() | |
}, 0) | |
}) |
This file contains hidden or 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 memory(obj) { | |
var bytes = 0; | |
function size (obj) { | |
if (obj !== null && obj !== undefined) { | |
switch (typeof obj) { | |
case 'number': bytes += 8; break; | |
case 'string': bytes += obj.length * 2; break; | |
case 'boolean': bytes += 4; break; | |
case 'object': |
This file contains hidden or 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
/** @param {Node|HTMLElement} node */ | |
function toJSON(node) { | |
if(!node) | |
node = this; | |
var obj = { nodeType: node.nodeType }; | |
if(node.tagName) | |
obj.tagName = node.tagName.toLowerCase(); | |
else if(node.nodeName) |
This file contains hidden or 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
// model | |
function Model () { | |
this._state = {} | |
return this | |
} | |
Model.prototype.get = function (key) { | |
return this._state[key] | |
} |
This file contains hidden or 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
/* | |
* Simple Pub/Sub Implementation for jQuery | |
* | |
* Inspired by work from Peter Higgins (https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js) | |
* | |
* This is about the simplest way to write a pubsub JavaScript implementation for use with jQuery. | |
*/ | |
(function( $ ) { | |
// Cache of all topics |