Skip to content

Instantly share code, notes, and snippets.

View tobie's full-sized avatar

Tobie Langel tobie

View GitHub Profile
// Two options for writing transportable custom assertions (for both
// options, the only API the runner needs to provide is an assert
// function). Guess which one I prefer.
//
// Option 1
// API
assert(someHelperfunc(expected, actual), message);
// Implementation
// JSON.stringify(require('uglify-js').parser.parse('{1 + ""} + 10;'), null, 2);
[
"toplevel",
[
[
"block",
[
[
"stat",
@tobie
tobie / modulr-node-test.js
Created December 13, 2011 08:33 — forked from dandean/modulr-node-test.js
modulr-node search paths
require('modulr').buildFromPackage(__dirname, function(e, result) {
if (e) {
throw e;
}
console.log(result);
});
var url = 'http://dev.w3.org/html5/spec/Overview.html',
options = { runScripts: false },
t0 = new Date();
require('zombie').visit(url, options, function (err, browser) {
console.log('That took', (new Date() - t0) / 1000, 'seconds!!!');
});
// Killed the process after having it ran for > 1 hour
// For comparison, visiting google.com took ~ 2.5 seconds.
@tobie
tobie / gist:1001359
Created May 31, 2011 21:53
NPM installs stuff locally if there's a package file, globally when there isn't.
---:test-npm $ mkdir package
---:test-npm $ cd package
---:package $ echo '{"name":"foo","version":"0.1.0"}' > package.json
---:package $ npm install async
async@0.1.9 ./node_modules/async
---:package $ cd ..
---:test-npm $ mkdir no-package
---:test-npm $ cd no-package/
---:no-package $ npm install async
async@0.1.9 ../../../../node_modules/async
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
@tobie
tobie / _html.html
Created February 28, 2011 12:11
errors in callbacks
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>untitled</title>
<script type="text/javascript" charset="utf-8">
alReady = function( n, t, ready ) {
ready = function(){ for ( t = 0; ready && t < n; ) ready[ t++ ](); ready = 0 }
document.addEventListener && document.addEventListener( "DOMContentLoaded", ready, false )
process.nextTick = function (callback) {
if (arguments.length == 1) {
nextTickQueue.push(callback);
} else {
var args = Array.prototype.slice.call(arguments, 1);
nextTickQueue.push(function() {
callback.apply(null, args);
});
}
process._needTickCallback();
win.$script.domReady = function(fn) {
doc[readyState].exec(/in/) ? timeout(function() { win.$script.domReady(fn); }, 50) : fn();
}
@tobie
tobie / gist:842085
Created February 24, 2011 11:53
Moar smallest DOMReady code, EVAR!
function r(f){setTimeout(/in/(document.readyState)?r:f,9,f)}