This is now an actual repo:
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
/** | |
* @param fn {Function} Callback function to trigger on frame | |
* @param fps {int} Target FPS | |
* @returns {{pause: pause, start: start, destroy: destroy}} | |
*/ | |
function frameLoop(fn, fps=60) { | |
let then = 0; | |
let interval = 1000 / fps; | |
let isRunning = true; | |
let currentFrameId = null; |
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
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 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 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 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 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 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 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 |