Skip to content

Instantly share code, notes, and snippets.

@clausreinke
clausreinke / node-gyp-hello-world-fail.log
Created June 30, 2016 10:44
node-gyp build on android fails, due to ˋ-pieˋ flag counteracting ˋ-rdynamicˋ flag. intended for the [commit discussion](https://github.com/nodejs/node/commit/271201fea935cdf85336736e87c06104ce185f61).
$ ls
binding.gyp hello.cc
$ echo ~/.node*
/data/data/com.termux/files/home/.node*
$ node-gyp configure build |& tee build.log
gyp info it worked if it ends with ok
gyp verb cli [ '/data/data/com.termux/files/usr/bin/node',
gyp verb cli '/data/data/com.termux/files/usr/bin/node-gyp',
gyp verb cli '-v',
@clausreinke
clausreinke / yield.js
Created July 24, 2013 19:59
playing with generators
// node v0.11.4 --harmony
function forof(g,cb) { // non-generator callbacks only
var r;
while(true) {
r = g.next();
if (r.done) break; // skip return value?
cb(r.value);
}
}
@clausreinke
clausreinke / bind-for-arrows.html
Created July 12, 2013 21:11
using _this=this to emulate arrow functions is fast but error-prone, requiring non-trivial analysis for use in transpilers. using .bind to emulate arrow functions is simpler, but slow in current engines. using an apply-based partial polyfill (bind) for .bind is fast in v8, slow in other engines.
// <script>
/* sample output
$ node ../bind-for-arrows.html
_this: 4ms
.bind: 25ms
bind: 4ms
_this, calls only: 1ms
.bind, calls only: 4ms
bind, calls only: 0ms
@clausreinke
clausreinke / monadic.ts
Created July 12, 2013 14:26
monadic javascript/typescript: promises and generators
declare function setImmediate(cb);
declare function setTimeout(cb,n);
declare var process;
function nextTick(cb) {
if (typeof setImmediate == "function") {
setImmediate(cb);
} else if (typeof process == "object" && typeof process.nextTick == "function") {
process.nextTick(cb);
} else if (typeof setTimeout == "function") {
@clausreinke
clausreinke / simple-promises.ts
Created May 7, 2013 21:33
// simple monad-like promises, with examples
declare function setImmediate(cb);
declare function setTimeout(cb,n);
declare var process;
function nextTick(cb) {
if (typeof setImmediate == "function") {
setImmediate(cb);
} else if (typeof setTimeout == "function") {
setTimeout(cb,0);
} else if (typeof process == "object" && typeof process.nextTick == "function") {
@clausreinke
clausreinke / interfaces.html
Created February 20, 2013 17:23
JavaScript: generic methods, programming to interfaces, classes implementing interfaces; a sketch (load in browser or run with nodejs)
// see console output <script>
// quick hack of classes implementing interfaces, just to give the idea; for a
// proper design, feel free to use better syntax, (Weak)Maps, unique symbols, ..;
//
// the core idea is to relate interfaces to classes that implement them, in
// such a way that the relevant implementations of interface methods can be
// extracted systematically in generic code
var Mappable = {}; // interface, to be implemented by classes;
@clausreinke
clausreinke / escodegen.js
Created July 21, 2012 21:30
map symbolic infix ops '(x .<op> y)' to 'Operation[".<op>"](x,y)'
/*
Copyright (C) 2012 Ariya Hidayat <[email protected]>
Copyright (C) 2012 Mathias Bynens <[email protected]>
Copyright (C) 2012 Joost-Wim Boekesteijn <[email protected]>
Copyright (C) 2012 Kris Kowal <[email protected]>
Copyright (C) 2012 Yusuke Suzuki <[email protected]>
Copyright (C) 2012 Arpad Borsos <[email protected]>
Copyright (C) 2011 Ariya Hidayat <[email protected]>
Redistribution and use in source and binary forms, with or without
@clausreinke
clausreinke / basil.js
Created June 22, 2012 15:02
basil - bridging ASI and layout
// basil (bridging ASI and layout)
//
// unfinished sketch; Claus Reinke 2012
//
// $ node basil.js sample.js
// ASI at line 5(2), before indented line 6(8)
// no ASI at line 12(2), before non-indented line 13(2)
// ASI at line 25(2) before indented line 26(11)
// no ASI at line 35(2), before non-indented line 36(2)
// no ASI at line 39(2), before non-indented line 40(2)