Skip to content

Instantly share code, notes, and snippets.

View AndreasMadsen's full-sized avatar

Andreas Madsen AndreasMadsen

View GitHub Profile
@AndreasMadsen
AndreasMadsen / test.js
Created June 15, 2011 10:02
Forever – listen to emit
/*jslint white: true, devel: true, debug: true, onevar: true,
node: true, undef: true, nomen: true, regexp: false,
plusplus: false, bitwise: true, unparam: false, es5: true,
newcap: true, on: true, strict: true */
(function (global, undefined) {
"use strict";
require.paths = [ '/Users/Andreas/.node_modules', '/usr/local/lib/node_modules' ];
@AndreasMadsen
AndreasMadsen / emitter.js
Created June 15, 2011 10:04
Simpel http server
var http = require('http');
http.createServer(function (req, res) {
res.end();
}).listen(1337, "127.0.0.1");
console.log('emitter.js running');
@AndreasMadsen
AndreasMadsen / Terminal
Created June 15, 2011 11:41
Forever - living dead processors
Andreas-Madsens-MacBook-Pro:~ Andreas$ cd Sites/WebNodes/interface/
Andreas-Madsens-MacBook-Pro:interface Andreas$ node test.js
Output forever list:
Number of open processors: 0
null
start emitter.js
emitter.js is started
Output forever list:
Number of open processors: 1
[0] node /Users/Andreas/Sites/WebNodes/interface/emitter.js [4483, 4482] /Users/Andreas/Sites/WebNodes/interface/log/S9H7.log 0:0:0:0.38
@AndreasMadsen
AndreasMadsen / test.js
Created June 15, 2011 13:23
forever – load return undefined
/*jslint white: true, devel: true, debug: true, onevar: true,
node: true, undef: true, nomen: true, regexp: false,
plusplus: false, bitwise: true, unparam: false, es5: true,
newcap: true, on: true, strict: true */
(function (global, undefined) {
"use strict";
//get the forever module
var forever = require("forever"),
@AndreasMadsen
AndreasMadsen / UDPdebug.js
Created July 6, 2011 13:18
something is wrong when I send a UDP message
console.log('Version: ' + process.version);
var dgram = require('dgram'),
path = require("path");
var server = dgram.createSocket("unix_dgram"),
datagramPath = path.join(process.cwd(), "datagram_socket.udp");
server.on("message", function (message) {
console.log("message event fired");
@AndreasMadsen
AndreasMadsen / test-methods.js
Created November 5, 2011 17:03 — forked from dominictarr/test-methods.js
node-http-proxy methods not working
var http = require('http')
, httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
@AndreasMadsen
AndreasMadsen / test-methods.js
Created November 5, 2011 17:03 — forked from dominictarr/test-methods.js
node-http-proxy methods not working
var http = require('http')
, httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
@AndreasMadsen
AndreasMadsen / cluster.js
Created November 14, 2011 15:56
SIGTERM issue
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
@AndreasMadsen
AndreasMadsen / cluster.js
Created November 14, 2011 20:08
SIGCHLD emit when worker rescive SIGTERM
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
@AndreasMadsen
AndreasMadsen / test.js
Created November 14, 2011 20:09
Debug file
var cluster = require('cluster');
var http = require('http');
console.log(cluster.isMaster ? "master" : "worker" + " :: " + process.pid);
if (cluster.isMaster) {
// Fork workers.
cluster.setupMaster({workers: 1});
cluster.on('fork', function (worker) {