This file contains hidden or 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 cresque = require('coffee-resque'); | |
var util = require('util'); | |
var myJobs = { | |
add: function(a, b, callback) { callback(a + b); }, | |
succeed: function(arg, callback) { callback(); }, | |
fail: function(arg, callback) { callback(new Error('fail')); } | |
} | |
// setup a worker |
This file contains hidden or 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 obj = { | |
levelOne: { | |
levelTwo: { | |
property: 'Got me!' | |
}, | |
levelOneArray: [1,2,3] | |
} | |
} |
This file contains hidden or 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 propertyValueOrUndefined = (((obj||{}).levelOne||{}).levelTwo||{}).property; | |
console.log(propertyValueOrUndefined); | |
var levelOneArrayElementOneOrUndefined = (((obj||{}).levelOne||{}).levelOneArray||[])[0]; | |
console.log(levelOneArrayElementOneOrUndefined); |
This file contains hidden or 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
if (obj) { | |
var levelOne = obj.levelOne; | |
if (levelOne) { | |
var levelTwo = levelOne.levelTwo; | |
if (levelTwo) { | |
var propertyValueOrUndefined = levelTwo.property; | |
if (propertyValueOrUndefined) | |
console.log(propertyValueOrUndefined); | |
} | |
This file contains hidden or 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 obj = { | |
levelOne: { | |
levelTwo: { | |
property: 'Got me!' | |
}, | |
levelOneArray: [1,2,3] | |
} | |
} |
This file contains hidden or 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
netstat -anp tcp | grep 3000 |
This file contains hidden or 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
lsof -i tcp:3000 |
This file contains hidden or 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 TimeQueue = require('timequeue'); | |
var n = 0; | |
function worker(callback) { | |
console.log('request'+(n++)); | |
callback(null, 'good'); | |
} | |
var x = 0; | |
console.log('0 minute'); |
This file contains hidden or 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 limiter = new RateLimiter(5, 'minute');var n = 0; | |
var x = 0; | |
console.log('0 minute'); | |
setInterval(function() { | |
console.log((++x)+' minute'); | |
}, 60000); | |
setInterval(function() { | |
limiter.removeTokens(1, function(err, remainingRequests) { | |
console.log('request'+(n++)+' :: '+remainingRequests); |
This file contains hidden or 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 rateLimit = require('function-rate-limit'); | |
var fn = rateLimit(5, 60000, function(n) { | |
console.log('request'+n); | |
}); | |
var x = 0; | |
console.log('0 minute'); | |
setInterval(function() { | |
console.log((++x)+' minute'); |