This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A simple way to extend the EventEmitter to classes with the class.extend module in NodeJS | |
*/ | |
var Class = require('class.extend'), | |
events = require('events'); | |
var Events = Class.extend({ | |
init: function() { events.EventEmitter.call(this); } | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Guvna(options) { | |
// error checking | |
if (!options.list || !options.callback || !options.done) { | |
console.log('ERROR: missing required option - { list: [], callback: fn(), done: fn() }'); | |
return false; | |
} | |
// assign vars | |
this.list = options.list; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************/ | |
/* insert random delays to simulate latency */ | |
/********************************************/ | |
function delay(callback, n) { | |
var r = Math.floor(Math.random()*(n || 5000)); | |
setTimeout(function() { callback(); }, r); | |
} | |
// specify a max on the delay timer range | |
delay(function() { console.log('BLARGH!'); }, 10000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = fs.readFileSync('configFile.txt').toString(); | |
var interfaces = config.match(/interface .+[\r]*\n [\s\S]+?[^\ ]!/g); | |
console.log(interfaces): | |
/* | |
[ | |
"interface Vlan1\n description ...\n!", | |
"interface Vlan2\n description ...\n!", | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************** | |
* Inspired by https://github.com/joshuah/insert-coin/blob/master/printer.js * | |
****************************************************************************/ | |
var net = require('net'); | |
var printers = [ | |
{ ip: '192.168.1.10', lcdRows: 2, lcdCols: 16 } | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* http://en.wikipedia.org/wiki/Varan */ | |
var Faye = require('faye'), | |
express = require('express'), | |
ping = require('ping'); | |
var bayeux = new Faye.NodeAdapter({ mount: '/faye', timeout: 45 }), | |
client = bayeux.getClient(), | |
app = express(); | |
app.configure(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ 0, 1, 2, 3, 4, 5 ].forEach(function(y) { var z = --y || 'wut!?'; console.log(z); }) | |
/* output: | |
-1 | |
"wut!?" | |
1 | |
2 | |
3 | |
4 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* npm insatll -g mocha | |
* npm install express | |
* node ./<this> | |
* put tests in ./test/ and they can be called by hitting http://localhost:3030/test/:file | |
* you can test all tests by hitting http://localhost:3030/test/all | |
*/ | |
var express = require('express'), | |
app = express(); | |
var spawn = require('child_process').spawn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var server = net.createServer(); | |
server.on('connection', function(socket) { | |
console.log('connected!'); | |
var start = Math.floor(new Date().getTime()/1000); | |
socket.readings = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ws.prototype.sendJson = function(data, options, callback) { | |
this.send.call(this, JSON.stringify(data), options, callback); | |
}; |
OlderNewer