Skip to content

Instantly share code, notes, and snippets.

View pvdz's full-sized avatar

Peter van der Zee pvdz

View GitHub Profile
@pvdz
pvdz / gist:9121615
Created February 20, 2014 19:41
for-in rewrite rules.
// var version, can only have one var with a limited initializer
// can safely reuse the new var because it can't have side effects
for (var key=init in o) stmt;
// =>
var key = init, _γ_keys = [], _γ_expro = expr;
for (key in _γ_expro) _γ_keys.push(key);
while (_γ_keys.length) if (expro.hasOwnProperty(key = _γ_keys.shift())) stmt;
// non-var version, lhs can be any single expression
// we have to create our own temp var because lhs is not "safe"
@pvdz
pvdz / gist:9121613
Created February 20, 2014 19:41
for-in rewrite rules.
// var version, can only have one var with a limited initializer
// can safely reuse the new var because it can't have side effects
for (var key=init in o) stmt;
// =>
var key = init, _γ_keys = [], _γ_expro = expr;
for (key in _γ_expro) _γ_keys.push(key);
while (_γ_keys.length) if (expro.hasOwnProperty(key = _γ_keys.shift())) stmt;
// non-var version, lhs can be any single expression
// we have to create our own temp var because lhs is not "safe"
@pvdz
pvdz / gist:9120576
Created February 20, 2014 18:50
regular-for-to-while transformation :)
function* f(){
for(var i=0;;++i) {
yield i;
}
}
// =>
function* f(){
{var i=0;while(true) {
@pvdz
pvdz / gist:9082105
Created February 18, 2014 22:49
POC, simple transformation :)
function * foo() {
a();
yield x;
b();
}
// =>
function * foo() {
var started = false;
@pvdz
pvdz / gist:9000941
Last active August 29, 2015 13:56
Selection api why you so verbose? :(
function f_rel(el, start, end) {
// end may be < 0 and is relative to start, start must be >=0
f_abs(el, start, start + end);
}
function f_abs(el, start, end){
// end may be 0 < end < start, start must be >=0
var s = getSelection();
s.removeAllRanges();
@pvdz
pvdz / gist:8972923
Created February 13, 2014 10:31
Fugly angular
<!doctype html>
<html ng-app="app">
<head>
<script defer src="bootstrap/js/jquery.2.1.0.js"></script>
<script src="angular/angular.1.2.11.min.js"></script>
</head>
<body>
<script>
var app = angular.module('app', [])
.factory('Model', function(){ return {foo: {bar: 'initial'}}; })
Original:
<table id=t><script>with(t)A=function(){for(a=h='';9>a;a++)for(h+="<tr>",c=0;d=" ABCDE"[c];)h+="<td>"+(c++?a?t[d+=a]=t[d]?eval("top[d][V='value']="+(l[d]||"''").replace(/^=/,'')):"<input id=D onfocus=D[V]=[l.D] onblur=A(l.D=D[V])>".replace(/D/g,d):d:a)},A(A(l=localStorage),innerHTML=h)</script>
Innermost for-body could be in loop-part (potential 1b gain but nothing to put there) (+1)
<table id=t><script>with(t)A=function(){for(a=h='';9>a;a++)for(h+="<tr>",c=0;d=" ABCDE"[c];h+="<td>"+(c++?a?t[d+=a]=t[d]?eval("top[d][V='value']="+(l[d]||"''").replace(/^=/,'')):"<input id=D onfocus=D[V]=[l.D] onblur=A(l.D=D[V])>".replace(/D/g,d):d:a));},A(A(l=localStorage),innerHTML=h)</script>
Cache the empty string (0)
<table id=t><script>with(t)A=function(){for(x=a=h='';9>a;a++)for(h+="<tr>",c=0;d=" ABCDE"[c];)h+="<td>"+(c++?a?t[d+=a]=t[d]?eval("top[d][V='value']="+(l[d]||"x").replace(/^=/,x)):"<input id=D onfocus=D[V]=[l.D] onblur=A(l.D=D[V])>".replace(/D/g,d):d:a)},A(A(l=localStorage),innerHTML=h)</script>
Make
var t = setInterval(function(){
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 1, 0, 0, 300, 400, false, false, false, false, 0, null);
document.getElementById('bigCookie').dispatchEvent(evt);
}, 20);
var c = setInterval(function(){
if (document.getElementById('goldenCookie').style.display !== 'none') {
console.log("Clicking gold");
var evt = document.createEvent("MouseEvents");
@pvdz
pvdz / gist:6263206
Last active December 21, 2015 06:19
This is the ignore-whitespace of https://github.com/qfox/zeparser2/commit/86313d79ffafc21a3a71a4b8f1505d3269e0735b This diff is causing my parser to slow down by about 100% (in Chrome, at least) ... Crazy.
diff --git a/src/par.js b/src/par.js
index 2a3507e..bef9db8 100644
--- a/src/par.js
+++ b/src/par.js
@@ -1,4 +1,7 @@
-if (typeof Tok === 'undefined') var Tok = require(__dirname+'/tok.js').Tok;
+
+
+(function(exports){
+ var Tok = exports.Tok || require(__dirname+'/tok.js').Tok;
/[\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