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 some_fun(req,res,next) { | |
asyc.waterfall([ | |
function getNewObjectID(callback) { | |
redis.incr('next_id', callback); | |
}, | |
function storeObject(r, callback) { | |
var object = {id:r, now:Date.now()}; | |
redis.set('key', object, callback); | |
}, | |
function sendResponse(_, callback) { |
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
redis_scheme = require 'redis_scheme' | |
# HASH: users:<id>(name, password, books, __blog.id) | |
# HASH: __blog:<id>(url) | |
# LIST: __blog:<id>:subscribers | |
# ZSET: users:<id>:books | |
redis_scheme.define_model('user', { | |
name: redis_scheme.type.string, | |
password: redis_scheme.type.string, | |
books: redis_scheme.foreign_key(redis_scheme.model('book'), 'readers'), |
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 _dict = {}; | |
// Start a TCP Server | |
net.createServer(function (socket) { | |
socket.write("Welcome to Nodis!\n"); | |
// Handle incoming messages from clients. | |
socket.on('data', function (data) { | |
data = data.toString().replace(/[\r\n]/g, '').split(' '); |
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 iterators (list) { | |
var index = 0; | |
return function () { | |
return list[index++]; | |
} | |
} | |
var v; | |
var str = "hello world!"; |
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
angular.module('projectServices', []) | |
.factory 'User', -> | |
@authenticated = false | |
@name = null | |
isAuthenticated: => @authenticated | |
getName: => @name | |
login: (username, password, callback) => | |
$.post '/login', | |
{username: username, password: password}, | |
((data) => |
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 Pool = function (poolSize, taskHandler) { | |
this.poolSize = poolSize; | |
this.taskHandler = taskHandler; | |
this.free = poolSize; | |
this.offlineTasks = []; | |
}; | |
Pool.prototype.check = function () { | |
if (this.offlineTasks.length > 0 && this.free > 0) { |
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.prototype.unCurrying = function () { | |
var self = this; | |
return function () { | |
var args = Array.prototype.slice.call(arguments); | |
return self.apply(args[0], args.slice(1)); | |
}; | |
}; | |
var foo = []; | |
var push = Array.prototype.push.unCurrying(); |
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
// Let express support "Promise" | |
app.use(function(req, res, next) { | |
var oldResJson = res.json; | |
res.json = function(promise) { | |
if (promise && | |
typeof promise === 'object' && | |
typeof promise.success === 'function') { | |
promise.success(function(fetchedObj) { | |
if (fetchedObj) { | |
oldResJson.call(res, fetchedObj); |
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
s1, s2 and s3 are operations in the server, and c1, c2 are operations performed on the client. | |
s1 s2 s3 | |
c1 c2 | |
1. transform(c1, s1) = (c1', s1') => c1 s1' = s1 c1' | |
2. transform(c1', s2) = (c1'', s2') => c1' s2' = s2 c1'' | |
3. transform(c1'', s3) = (c1''', s3') => c1'' s3' = s3 c1''' |
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 redis = require('redis'); | |
var options = { | |
host: '127.0.0.1', | |
port: '6379' | |
}; | |
var publisher = redis.createClient(options); | |
var subscriber = redis.createClient(options); | |
function sub(message) { |
OlderNewer