Skip to content

Instantly share code, notes, and snippets.

View zz85's full-sized avatar

Joshua Koo zz85

View GitHub Profile
@zz85
zz85 / undo.js
Last active July 26, 2022 20:18
Simple Undo / Redo System
// 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.
@zz85
zz85 / pootify.js
Last active August 29, 2015 14:06 — forked from alisaifee/pootify.js
Pootify Bookmarklet
// 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
@zz85
zz85 / test_canvas_strokes.js
Created September 7, 2014 11:10
benchmark 2d canas strokes
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;
@zz85
zz85 / test.js
Created September 3, 2014 11:59
test bezier
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;
@zz85
zz85 / histogram.js
Last active August 29, 2015 14:05
Simple Histogram Stats
function Histogram() {
this.reset();
}
Histogram.prototype.reset = function() {
this.counts = [];
this.types = {};
};
@zz85
zz85 / mem.js
Last active August 29, 2015 14:05
Print Memory
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))
}
@zz85
zz85 / cssRule.js
Created June 27, 2014 16:18
Easy way for creating and modifying CSS Rules in JS
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;
@zz85
zz85 / mrdoob.json
Last active February 22, 2020 17:49
mrdoob style guide with jscs config
{
"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,
@zz85
zz85 / gist:10542662
Created April 12, 2014 15:54
Coefficients Generation for Optimized Gaussian Blurs using Linear Sampling
/*
* @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
*
@zz85
zz85 / toon.js
Created March 11, 2014 23:30
Toon Pixel Shader (for Three.js Composer)
<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