Skip to content

Instantly share code, notes, and snippets.

View billywhizz's full-sized avatar
🤓
always be learning

Andrew Johnston billywhizz

🤓
always be learning
View GitHub Profile
@billywhizz
billywhizz / node-stream.js
Created February 2, 2011 17:49
stream client and server for node.js
var net = require("net");
var crypto = require("crypto");
var fs = require("fs");
var multi = null;
var _states = {
"open": "open",
"closed": "closed",
"readOnly": "readOnly",
"writeOnly": "writeOnly",
@billywhizz
billywhizz / script_test.js
Created February 6, 2011 09:42
testing vm script functionality in node.js
var vm = require('vm'),
code = 'var square = n * n;',
fn = new Function('n', code),
script = vm.createScript(code),
sandbox;
n = 5;
sandbox = { n: n };
benchmark = function(title, funk) {
@billywhizz
billywhizz / try-catch-test.js
Created February 20, 2011 22:36
testing try catch performance in v8/node.js
function test1() {
function test(j) {
var s = 0;
for (var i = 0; i < j; i++) s = i;
for (var i = 0; i < j; i++) s = i;
for (var i = 0; i < j; i++) s = i;
for (var i = 0; i < j; i++) s = i;
return s;
}
From 5f933b1df831f94f9003375a6ed578896506c3e4 Mon Sep 17 00:00:00 2001
From: Andrew Johnston <[email protected]>
Date: Mon, 21 Mar 2011 21:50:15 +0000
Subject: [PATCH] added option for tcp or unix_dgram syslogging
---
index.js | 469 ++++++++++++++++++++++++++++++++------------------------------
1 files changed, 243 insertions(+), 226 deletions(-)
diff --git a/index.js b/index.js
@billywhizz
billywhizz / php-post.js
Created April 3, 2011 01:54
testing fastcgi post to php
var net = require("net");
var fastcgi = require("fastcgi");
var reqid = 0;
var post = "fname=aaa&lname=fff";
var params = [
["REQUEST_METHOD", "POST"],
["SCRIPT_FILENAME", process.ARGV[2]],
["CONTENT_TYPE", "application/x-www-form-urlencoded"],
@billywhizz
billywhizz / vhost.js
Created April 28, 2011 19:51
Example of vhosts in node.js
var http = require("http");
/*
add following to your hosts config to test:
10.11.12.8 www.vhost1.net
10.11.12.8 www.vhost2.com
10.11.12.8 www.vhost3.test.com
10.11.12.8 static.vhost1.net
@billywhizz
billywhizz / mysql.js
Created May 10, 2011 20:24
node-mysql v php/mysqli
var mysql = require("mysql/client");
var http = require("http");
var client = mysql({
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "password"
});
@billywhizz
billywhizz / tes-ssl.js
Created May 16, 2011 23:51
ssl test for node.js
/*
generate your key and cert as follows:
openssl genrsa -out server.key.pem 1024
openssl req -new -key server.key.pem -out server.csr.pem
openssl x509 -req -in server.csr.pem -signkey server.key.pem -out server.cert.pem
*/
var http = require("https");
var fs = require("fs");
@billywhizz
billywhizz / mylib.js
Created May 19, 2011 14:41
module configuration example
// this is just a standard node.js module
exports.foo = function() {
return ("hello from " + process.ARGV[2]);
}
@billywhizz
billywhizz / f2s.js
Created May 24, 2011 00:17
sendfile to a socket
var fs = require("fs");
var constants = process.binding("constants");
exports.f2s = function(file, socket, off, len, cb, chunked) {
var twrite = 0;
var chunksize = len < 4096?len:4096;
function chunk() {
try {
if(chunked) {
if(off + chunksize > len) chunksize = len - off;