Skip to content

Instantly share code, notes, and snippets.

@onteria
onteria / hello.js
Created May 26, 2011 20:23
A hello world script
function helloWorld() {
console.log("hello world");
}
helloWorld();
@onteria
onteria / LinkedList.js
Created May 27, 2011 16:13
A preliminary implementation of a basic LinkedList
/**
* @author onteria
* @description A library of functions to handle linked lists
* @name LinkedList
*/
// Expose our objects to APIs that use require()
exports.LinkedList = LinkedList;
exports.ListNode = ListNode;
@onteria
onteria / linked_list_test.js
Created May 27, 2011 19:50
Unit Test for linked lists module
/**
* @author onteria
* @description
* @name
*/
var ll = require('./LinkedList');
var assert = require('assert');
exports.testEmptyHead = function() {
@onteria
onteria / callback_test.js
Created June 2, 2011 22:31
Fun with this and callbacks
var fs = require('fs');
var http = require('http');
function MyServer(config_file) {
this.config = {};
var obj = this;
this.StartServer = function() {
http.createServer(function (req, res) {
@onteria
onteria / bind.js
Created June 2, 2011 22:43
Using .bind
var fs = require('fs');
var http = require('http');
function MyServer(config_file) {
this.config = {};
this.StartServer = function() {
http.createServer((function (req, res) {
this.SendResponse(res);
@onteria
onteria / object-function-v-constructor.js
Created June 2, 2011 22:57
Function returning object versus object constructor
var fs = require('fs');
var http = require('http');
function MyServer(config_file) {
return {
config: {},
StartServer: function() {
http.createServer((function (req, res) {
this.SendResponse(res);
}).bind(this)).listen(this.config.port, this.config.host, function() {
@onteria
onteria / object-creation.js
Created June 2, 2011 23:36
Before Object.create()
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
@onteria
onteria / object-create-server.js
Created June 2, 2011 23:51
using Object.create()
var fs = require('fs');
var http = require('http');
var events = require('events');
function MyServer(config_file) {
var server = Object.create(new events.EventEmitter);
server.config = {};
server.StartServer = function() {
http.createServer((function (req, res) {
this.SendResponse(res);
@onteria
onteria / untrusted.js
Created June 3, 2011 19:33
Running sandboxed code using vm
server.on("response", function(response) {
fs.readFile('untrusted.js', function(err,data){
var loaded_module = vm.createScript(data, 'untrusted.js');
loaded_module.runInNewContext({response: response});
})
});
// untrusted.js
(function () {
@onteria
onteria / untrusted.js
Created June 3, 2011 19:33
Running sandboxed code using vm
server.on("response", function(response) {
fs.readFile('untrusted.js', function(err,data){
var loaded_module = vm.createScript(data, 'untrusted.js');
loaded_module.runInNewContext({response: response});
})
});
// untrusted.js
(function () {