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 Undo / Redo System | |
/* | |
* @author joshua koo / http://joshuakoo.com | |
* | |
* There are usually 2 different ways to handle undo / redo | |
* 1. you snapshot and store the states, so you can load them anytime | |
* 2. you store the deltas, actions, events or commands between save points. | |
* | |
* Method 1 is simplistic. But it works. It's a lot like git. |
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
// TODO Use the DOM Mutation API! | |
(function switchText(node) { | |
var nodes = node.childNodes; | |
for (var n = 0; n < nodes.length; n++) { | |
if (nodes[n].nodeName.match(/(script|style)/i)); else | |
if (nodes[n].nodeType == 3) { | |
if (!/^\s+$/.test(nodes[n].value)) { | |
nodes[n].data = nodes[n].data.replace(/[a-zA-Z]+/g, function(w) { | |
return (w.match(/^(the|on|are|if|is|and|or|you|your|a|an)$/i)) | |
? w |
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
var c = document.createElement('canvas'); | |
c.width = innerWidth; | |
c.height = innerHeight; | |
var ctx = c.getContext('2d'); | |
document.body.appendChild(c); | |
var last = performance.now(); | |
var delay = 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
var c = document.createElement('canvas'); | |
c.width = innerWidth; | |
c.height = innerHeight; | |
var ctx = c.getContext('2d'); | |
document.body.appendChild(c); | |
var last = performance.now(); | |
var delay = 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 Histogram() { | |
this.reset(); | |
} | |
Histogram.prototype.reset = function() { | |
this.counts = []; | |
this.types = {}; | |
}; |
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 format_numbers(n) { | |
return (n / 1024 / 1024).toFixed(3) + 'MB'; | |
} | |
function mem() { | |
if (performance && performance.memory) { | |
console.log('used heap', format_numbers(performance.memory.usedJSHeapSize)) | |
console.log('total heap', format_numbers(performance.memory.totalJSHeapSize)) | |
console.log('heap limit', format_numbers(performance.memory.jsHeapSizeLimit)) | |
} |
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
if (!document.styleSheets.length) document.head.appendChild(document.createElement('style')); | |
var sheet = document.styleSheets[document.styleSheets.length - 1]; | |
var rules = {}; | |
function cssRule(selector, styles) { | |
var index; | |
if (selector in rules) { | |
index = rules[selector]; | |
sheet.deleteRule(index); | |
} else { | |
index = rules[selector] = sheet.cssRules.length; |
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
{ | |
"requireCurlyBraces": ["while", "do", "try", "catch"], | |
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], | |
"requireSpacesInFunctionExpression": { | |
"beforeOpeningCurlyBrace": true | |
}, | |
"requirePaddingNewlinesInBlocks": true, | |
"requireSpacesInsideObjectBrackets": "all", | |
"requireSpacesInsideArrayBrackets": "allButNested", | |
"requireSpaceBeforeBlockStatements": 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
/* | |
* @author zz85 / https://github.com/zz85 | |
* | |
* Related Readings | |
* | |
* http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/ | |
* http://www.sunsetlakesoftware.com/2013/10/21/optimizing-gaussian-blurs-mobile-gpu | |
* http://xissburg.com/faster-gaussian-blur-in-glsl/ | |
* https://github.com/manuelbua/blur-ninja | |
* |
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 id="toon" type="frag/shader"> | |
// Based on http://coding-experiments.blogspot.sg/2011/01/toon-pixel-shader.html | |
uniform float width; | |
uniform float height; | |
uniform sampler2D tDiffuse; | |
varying vec2 vUv; | |
#define HueLevCount 6 | |
#define SatLevCount 7 |