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
-- sets all fields for a hash from a dictionary | |
local hmset = function (key, dict) | |
if next(dict) == nil then return nil end | |
local bulk = {} | |
for k, v in pairs(dict) do | |
table.insert(bulk, k) | |
table.insert(bulk, v) | |
end | |
return redis.call('HMSET', key, unpack(bulk)) | |
end |
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
-- gets all fields from a hash as a dictionary | |
local hgetall = function (key) | |
local bulk = redis.call('HGETALL', key) | |
local result = {} | |
local nextkey | |
for i, v in ipairs(bulk) do | |
if i % 2 == 1 then | |
nextkey = v | |
else | |
result[nextkey] = v |
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
-- turns a dictionary table into a bulk reply table | |
local dict2bulk = function (dict) | |
local result = {} | |
for k, v in pairs(dict) do | |
table.insert(result, k) | |
table.insert(result, v) | |
end | |
return result | |
end |
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
Namespace.ModuleName = function (opt) { | |
// default configuration values | |
var defaults = { | |
moduleContextSelector: '.select-an-awesome > .module', | |
moduleTitle: 'Some Arbitrary Title', | |
moduleTimeoutSpeed: 3000 | |
} |
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
// to install the connect framework, go to your applications directory | |
// and type "npm install connect" in your command prompt. | |
// to launch the webserver, place this file in your application | |
// directory and execute it using "node index.js" | |
var connect = require('connect') | |
, app = connect() | |
, webserver = require('http').createServer(app); |
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 Robot = function(robot) { | |
robot.rotateCannon(-90); | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
robot.ahead(); | |
//i'll add a clone but i need to refactor collision | |
//robot.clone(); | |
}; |
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 ee = new (require('events').EventEmitter)(); | |
var foo; | |
// listener function | |
ee.on('test', function (newValue) { | |
foo = newValue; | |
}); | |
// before emitting | |
foo = 'one'; |
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
// create EventEmitter instance | |
var myEventEmitter = new EventEmitter(); | |
// attach a property | |
myEventEmitter.someVar = "some var"; | |
// add event listener for "test" | |
myEventEmitter.on('test', function () | |
console.log(this.someVar); | |
}); |
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
// create EventEmitter instance | |
var myEventEmitter = new EventEmitter(); | |
// add event listener for "test" | |
myEventEmitter.on('test', function () | |
console.log('2'); | |
}); | |
// the following code will output 1 2 3 | |
console.log('1'); |
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
// returns a function that spits out messages to a callback | |
// function; those messages have been split by newline | |
function newLineStream(callback) { | |
var buffer = ''; | |
return (function (chunk) { | |
var i = 0, piece = '', offset = 0; | |
buffer += chunk; | |
while ( (i = buffer.indexOf('\n', offset)) !== -1) { | |
piece = buffer.substr(offset, i - offset); | |
offset = i + 1; |
NewerOlder