Skip to content

Instantly share code, notes, and snippets.

@gildean
gildean / index.html
Created March 4, 2013 07:09
socket.io & connect echo-server
<!DOCTYPE html>
<html>
<head>
<title>socket.io echo</title>
<style>
body { font: 120% 'Open Sans', sans-serif; padding: 1em 2em 0; }
input, button { font-size: 110%; padding: 0.4em}
</style>
</head>
@gildean
gildean / callback.js
Created February 10, 2013 18:46
a callback example
function firstFunc(somevalue, callback) {
// pass the values, error as null (no possibility of error here) and the value is the new string
// this is the normal node convention
callback(null, somevalue += ' ok');
}
// call the function with the string and an anon function that get's the values from the callback
firstFunc('this should be', function (error, callbackvalue) {
if (!error) {
// if the callback didn't pass an error, then things should be ok
@gildean
gildean / requester.js
Created January 19, 2013 21:54
recursion
var httprequest = require('request');
var page = 1;
(function repeat() {
var req = httprequest("http://www.google.com", function (error, response, body) {
console.log(response.statusCode);
if (page < 2) {
page += 1;
repeat();
} else {
console.log('done');
@gildean
gildean / index.js
Created January 15, 2013 17:42
express fileshare
module.exports = function (port, path) {
"use strict";
var http = require('http'),
express = require('express'),
app = express(),
server = http.createServer(app),
path = path || __dirname,
port = port || 8555;
app.use(express.static(path));
@gildean
gildean / server.js
Created September 26, 2012 19:40
Streaming echoserver.
var net = require('net'),
bro = '....Cool story bro.\r\n',
Stream = require('stream'),
stream = new Stream,
server = net.createServer(function (socket) {
socket.setEncoding('utf8');
socket.pipe(stream).pipe(socket);
});
stream.readable = true;
@gildean
gildean / gist:3774377
Created September 24, 2012 05:26
node-http-proxy-example
var httpProxy = require('http-proxy'),
httpOptions = {
router: {
'someservername' : '127.0.0.1:3001',
'otherservername' : '127.0.0.1:3002',
'/*' : '127.0.0.1:3000'
}
},
httpProxyServer = httpProxy.createServer(httpOptions);