Skip to content

Instantly share code, notes, and snippets.

View mranney's full-sized avatar

Matt Ranney mranney

View GitHub Profile
return {
main: function () {
http.createServer(new_client).listen(listen_port);
sys.puts("Listening on " + listen_port);
}
};
function handle_couch_get(url, in_request, in_response) {
sys.puts("Making outbound CouchDB request: " + sys.inspect(url));
var out_request = http.createClient(couch_port, couch_hostname)
.request("GET", url.href, {
"Host": couch_hostname
});
out_request.addListener("response", function (out_response) {
in_response.sendHeader(out_response.statusCode, out_response.headers);
out_response.addListener("data", function (chunk) {
in_response.write(chunk);
var sys = require('sys'),
http = require('http'),
pool = [];
function finishTHEM(message){
var pool_size = pool.length, local_r, i;
sys.puts("Sending " + message + " to " + pool_size + " clients.");
for(i = 0; i < pool_size; i += 1) {
local_r = pool.shift();
function handle_couch_get(url, in_request, in_response) {
sys.puts(in_request.connection.remoteAddress + " CouchDB request: " + sys.inspect(url));
var out_request = http.createClient(couch_port, couch_hostname)
.request("GET", url.href, {
"Host": couch_hostname
});
out_request.addListener("response", function (out_response) {
in_response.sendHeader(out_response.statusCode, out_response.headers);
out_response.addListener("data", function (chunk) {
in_response.write(chunk);
@mranney
mranney / gist:340659
Created March 22, 2010 23:11
repltest.js
var sys = require("sys"),
net = require("net"),
repl = require("repl");
nconnections = 0;
net.createServer(function (c) {
sys.error("Connection!");
nconnections += 1;
c.close();
}).listen(5000);
@mranney
mranney / output.txt
Created March 23, 2010 05:38
setInterval test
// setInterval / clearInterval
var sys = require("sys"),
start = new Date(),
count = 10,
timer = setInterval(function () {
count -= 1;
sys.puts("Timer fired after " + (Date.now() - start) + "ms " + count + " remaining.");
if (count === 0) {
clearInterval(timer);
}
@mranney
mranney / output.txt
Created March 23, 2010 07:41
example of multi-repl
(in window 1)
rv-mjr2:~$ node repltest.js
node via stdin> foo
'stdin is fun'
(in window 2)
rv-mjr2:~$ telnet localhost 5000
Trying ::1...
var fs = require('fs'),
sys = require('sys');
fs.stat("/tmp", function(err, stat_data) {
if (err !== null) {
sys.puts(err.stack);
}
else {
sys.puts(sys.inspect(stat_data));
}
var sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
setTimeout(function () {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World');
res.close();
}, 2000);
}).listen(8000);
var sys = require("sys"),
http = require("http"),
port = 12345,
spawn = require("child_process").spawn;
function gzipStr (str, callback) {
var child = spawn("gzip", ["-c", "-f", "-n"]),
stdout = "", stderr = "";
child.stdout.addListener("data", function (chunk) {