Skip to content

Instantly share code, notes, and snippets.

View AndreasMadsen's full-sized avatar

Andreas Madsen AndreasMadsen

View GitHub Profile
@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]
@AndreasMadsen
AndreasMadsen / testcase.js
Created September 22, 2012 10:07
Domain.active offset
var http = require('http');
var domain = require('domain');
var server = new http.createServer(function (req, res) {
res.end('Not implemented');
});
server.listen(9222);
Error: error in route
at /Users/Andreas/Sites/Admazely/director-wrapper/test.js:15:15
at Domain.bind.b (domain.js:201:18)
at Domain.run (domain.js:141:23)
at Server.<anonymous> (/Users/Andreas/Sites/Admazely/director-wrapper/test.js:10:7)
at Server.EventEmitter.emit (events.js:91:17)
at HTTPParser.parser.onIncoming (http.js:1793:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
at Socket.socket.ondata (http.js:1690:22)
at TCP.onread (net.js:402:27)
@AndreasMadsen
AndreasMadsen / server.js
Created October 8, 2015 14:28
AsyncWrap tcp events example
'use strict';
const net = require('net');
const server = net.createServer(function (socket) {
socket.write('hallo world');
});
server.listen('127.0.0.1', 8080);
Andreass-MacBook-Pro:node Andreas$ npm install -g vock@0.1.2
npm http GET https://registry.npmjs.org/vock/0.1.2
npm http 304 https://registry.npmjs.org/vock/0.1.2
npm http GET https://registry.npmjs.org/node-gyp
npm http GET https://registry.npmjs.org/msgpack-js
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/colors
npm http GET https://registry.npmjs.org/pripub
npm http GET https://registry.npmjs.org/prompt
@AndreasMadsen
AndreasMadsen / bench.js
Created August 5, 2012 16:07
Ahh, that ARGUMENTS thing - is loop really faster than slice, oohhh !#%
if (process.argv[2] === 'bench') {
var pre = process.hrtime();
if (process.argv[3] === '1') {
(function () {
var args = Array.prototype.slice.call(arguments);
})(1, 2.0, "string", {"foo": true});
}
else if (process.argv[3] === '2') {
var fs = require('fs');
var util = require('util');
var Stream = require('stream');
var file = fs.createReadStream('file.csv');
var parser = new CSV();
// values will be emitted
parser.on('value', function (value) {
console.log(value);
@AndreasMadsen
AndreasMadsen / index.html
Created October 7, 2015 18:19
dprof dump of HTTP issue
<!DOCTYPE html>
<meta charset="utf8">
<title>dprof visualizer</title>
<style>
/* general page layout */
html, body {
margin: 0;
height: 100%;
}
@AndreasMadsen
AndreasMadsen / test_http.js
Created October 7, 2015 18:14
HTTP kills handle context in async_wrap
'use strict';
const asyncWrap = process.binding('async_wrap');
const http = require('http');
const fs = require('fs');
//
// Track
//
// 1. Setup a global variable to track the context of the async_hook_init_function
make apf
cd node_modules/packager; node package.js projects/apf_cloud9.apr
10:19:43.267 Start parsing main application
using file: /Users/Andreas/GitHub/cloud9/node_modules/packager/projects/projects/apf_cloud9.apr
path.existsSync is now called `fs.existsSync`.
10:19:43.287 Start parsing
10:19:43.289 Parsing settings
10:19:43.290 Parsing files
10:19:43.398 Getting filelist done.
10:19:43.398 Parsing defines