Skip to content

Instantly share code, notes, and snippets.

View pvdz's full-sized avatar

Peter van der Zee pvdz

View GitHub Profile
/[\u0030-\u0039\u0041-\u005a\u005f\u0061-\u007a\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0300-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u0483-\u0487\u048a-\u0524\u0526\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f2\u0610-\u061a\u0621-\u065e\u0660-\u0669\u066e-\u06d3\u06d5-\u06dc\u06df-\u06e8\u06ea-\u06fc\u06ff\u0710-\u074a\u074d-\u07b1\u07c0-\u07f5\u07fa\u0901-\u0939\u093c-\u094d\u0950-\u0954\u0958-\u0963\u0966-\u096f\u0971\u0972\u097b-\u097f\u0981-\u0983\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bc-\u09c4\u09c7\u09c8\u09cb-\u09ce\u09d7\u09dc\u09dd\u09df-\u09e3\u09e6-\u09f1\u0a01-\u0a03\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a59-\u0a5c\u0a5e\u0a66-\u0a75\u0a81-\u0a83\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0
@pvdz
pvdz / gist:5983822
Last active December 19, 2015 16:29
function J() { with (K) return caller.caller(true); }
function K() { return J(); }
function L() { return K(); }
function M(stop) { if (stop) return this; return L(); }
// without running it, what is the result of M() ?
var call = Function.prototype.call;
var apply = Function.prototype.apply;
call.call = call;
call.apply = apply;
apply.call = call;
apply.apply = apply;
var hop = Object.prototype.hasOwnProperty;
var hasOwnProperty = function(obj, prop){
return call.call(hop, obj, prop);
};
@pvdz
pvdz / x.js
Last active December 17, 2015 18:19
// original: https://gist.github.com/qfox/5652198
// this rewrite tries to use globals for any local vars
// you'll have the burden of extra scopes, but it beats dynamic vars (https://gist.github.com/qfox/5652201)
// step1: change var
var $start_foo;
function start(x){
$start_foo = 0;
if (x === 1) $start_foo = 1;
// original: https://gist.github.com/qfox/5652198
// this would use dynamic variable access to store vars from different funcs
// dynamic prop access could very well kill optimizations though
// step1: change var
var $state = {};
function start(x){
$state['start:foo'] = 0;
@pvdz
pvdz / x.js
Last active December 17, 2015 18:19
Original example Rewrite to dynamic var: https://gist.github.com/qfox/5652201 Rewrite to global var: https://gist.github.com/qfox/5652207
// Rewrite to dynamic var: https://gist.github.com/qfox/5652201
// Rewrite to global var: https://gist.github.com/qfox/5652207
// original
function start(x){
var foo = 0;
if (x === 1) foo = 1;
else if (x === 2) foo = 2;
else if (x === 3) foo = 3;
@pvdz
pvdz / gist:5531788
Created May 7, 2013 10:50
Welcome to my (new) world
for (a in b);
for (location in b);
for (a in location);
for (location in parent);
for (var a in b);
for (var location in b);
for (var a in location);
for (var location in parent);
@pvdz
pvdz / gist:5433721
Created April 22, 2013 10:08
jsgif foo
var encoder = new GIFEncoder();
encoder.setRepeat(0); // number of times the movie should loop, 0 = forever
encoder.setDelay(Math.floor(1000/settings.fps)); // ms delay between frames
encoder.start();
encoder.addFrame(canvas.getContext('2d'));
encoder.finish();
var binary_gif = encoder.stream().getData();
var data_url = 'data:image/gif;base64,'+Base64.encode(binary_gif);
@pvdz
pvdz / gist:5128700
Created March 10, 2013 14:07
requirejs fooky wat Why won't it just work as the example says?
// using requirejs 2.1.5
// see second example after http://requirejs.org/docs/plugins.html#apiload
define({
load: function (name, req, onload, config) {
if (name.slice(0,7) === 'js/user') {
var parse = function(err, source){
if (err) return console.error(err), onload.error(err); // error ajax?
// process source
var par = toTree(source);
@pvdz
pvdz / gist:4756132
Last active December 12, 2015 09:59
- removed whitespace - made a start with var name normalization - refactored $m into a single return statement (added $_ to help, but since the fingerprint falls away in expression, the overhead is minor) - refactored $n into a single "return" statement. the return value is not used, but it allows for making it look the same as other funcs - ref…

Unconed's failrail : http://jsbin.com/edepor/1/edit

This is a minification attempt by me. See gist history for a few in-between commits. End result is 1452 bytes by jscrush (http://www.iteral.com/jscrush/), that's where I leave it.

I've not even tested this code, I don't care myself if it doesn't even run anymore (but would be pretty sweet if it did! ;)).

The dollar signs allow you to find usages of a variable. The dollar sign itself is not used in the program, so you can remove all of them for "production" minification. As long as they're there, you can figure out where a variable is used (use case sensitive search) very easy this way.