Skip to content

Instantly share code, notes, and snippets.

Andreas Madsen AndreasMadsen

  • Computationally Demanding
  • Copenhagen, Denmark
Block or report user

Report or block AndreasMadsen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View restart.js
var cluster = require("cluster");
cluster.restart = function (callback) {
var oldWorkers = [];
cluster.eachWorker(function (worker) {
oldWorkers.push(worker);
});
function restartWorker (oldWorker) {
View do.js
for (var i = 0; i < l; i++) {
(function (i) {
http.request(options, function () {
/* use i */
});
})(i);
}
View overview.css
/**
* Copyright (c) 2011 Andreas Madsen
* GPL License Version 3
*/
html, body, ul, figure, img {
margin: 0;
padding: 0;
font-family: sans-serif;
}
@AndreasMadsen
AndreasMadsen / result.log
Created Jan 4, 2012
stdout and stderr pipe bechmark
View result.log
$ node ./test.js
test: 262ms
GOT: 10240 KB
use pipe: no
$ node ./test.js
test: 248ms
GOT: 10240 KB
use pipe: no
$ node ./test.js
test: 257ms
View test.js
var net = require('net');
var path = require('path');
var server = net.createServer();
server.on('connect', function () {
console.log('got request');
});
server.on('error', function (err) {
@AndreasMadsen
AndreasMadsen / log.txt
Created Jan 23, 2012
process.send blocks in node.js
View log.txt
$ node test
create: 678ms
send: 4445ms
200 ms passed, or not :/
got message: 5 MB
get: 4472ms
View test.js
var fork = require('child_process').fork;
if (process.argv[2] === 'child') {
setInterval(function () {
console.log('alive ... ');
}, 200);
setTimeout(function () {
console.log('exit child');
process.exit(0);
View log.ext
> node test.js
worker ID:1 got message. message-1
worker ID:0 got message. message-1
worker ID:1 got message. message-2
worker ID:0 got message. message-2
@AndreasMadsen
AndreasMadsen / deamontest.js
Created Feb 4, 2012
Frist draft on a simple javascript deamon
View deamontest.js
var child_process = require('child_process');
function startDeamon(child, args) {
var newEnv = JSON.parse(JSON.stringify(process.env));
newEnv.deamonOptions = JSON.stringify({exec: child, args: args});
var deamonWatcher = child_process.fork(process.argv[1], ['deamon'], {
You can’t perform that action at this time.