Skip to content

Instantly share code, notes, and snippets.

View AndreasMadsen's full-sized avatar

Andreas Madsen AndreasMadsen

View GitHub Profile
'use strict';
const asyncWrap = process.binding('async_wrap');
const fs = require('fs');
//
// Track
//
// 1. Setup a global variable to track the context of the async_hook_init_function
let callbackContext = 'root';
process.nextTick(function () {
filename configuration rate (op/sec) time (sec)
arrays/var-int.js n=25 type=Array 78.16202877261836 0.319848402
arrays/var-int.js n=25 type=Buffer 99.43471365288336 0.25142125
arrays/var-int.js n=25 type=Int8Array 100.60232908154222 0.248503193
arrays/var-int.js n=25 type=Uint8Array 102.13162342880813 0.244782166
arrays/var-int.js n=25 type=Int16Array 98.14023778327551 0.254737512
arrays/var-int.js n=25 type=Uint16Array 100.94187449908857 0.247667285
arrays/var-int.js n=25 type=Int32Array 92.78983388047601 0.269426067
arrays/var-int.js n=25 type=Uint32Array 90.27754042307774 0.276923805
arrays/var-int.js n=25 type=Float32Array 73.60696037781192 0.339641793
var dgram = require('dgram');
console.log('step 1');
dummy(function () {
console.log('step 2');
tester(function () {
console.log('step 3');
});
});
Hi David
Do you plan to attend to this event: http://meetup.mathiasbuus.eu/ ?

In order to get the piccolo framework intro a more stable state I'm refactoring major and minor parts intro standalone modules.

A major part is the node-like module system. The system should be broken down intro two modules. A client-side and a server-side module. The server-side seams necessary, since the node-core alternative is totally blocking (not ideal in dynamic server resource loading) and there might be security concerns, where a localized module system is important. The client-side is necessary since no module system exists.

The thought is to provide two modules (in result one almost-isomorfic-api-only module). They would have the following API:

var http = require('http');

var ServerModuleSystem = require('ServerModuleSystem');
var net = require('net');
var mdns = require('mdns');
var serviceKey = mdns.tcp('custom-name');
var discover = mdns.createBrowser(serviceKey);
discover.on('serviceUp', function (service) {
console.log({
port: service.port,
var net = require('net');
var mdns = require('mdns');
var serviceKey = mdns.tcp('custom-name');
var discover = mdns.createBrowser(serviceKey);
discover.on('serviceUp', function (service) {
console.log({
port: service.port,
@AndreasMadsen
AndreasMadsen / hack.js
Created October 27, 2012 18:46
Hack javascript - delete
var log = typeof print === 'undefined' ? console.log : print;
// get v8 internal DELETE
var DELETE;
delete ({}[{ toString: function x(){ DELETE = x.caller; } }]);
// try it out
var obj = {hi: true};
DELETE.call(obj, 'hi', 0); // BUG: hack.js:5: RangeError: Maximum call stack size exceeded
Andreas-Madsen-MacBook-Pro:GitHub Andreas$ unlink
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
Andreas-Madsen-MacBook-Pro:GitHub Andreas$ rm
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
Andreas-Madsen-MacBook-Pro:GitHub Andreas$
@AndreasMadsen
AndreasMadsen / toBit.js
Created October 6, 2012 11:32
to bit one liner
var toBits = function (num) { return num.toString(2).split('').map(Number).reverse(); };
toBits(1) // [1]
toBits(2) // [1, 0]
toBits(4) // [1, 0, 0]
toBits(7) // [1, 1, 1]
toBits(8) // [1, 0, 0, 0]