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 mqtt = require('mqtt'); | |
var uuid = require('node-uuid'); | |
// Import events module | |
var events = require('events'); | |
var MQTTService = (function () { | |
var instance; | |
function init() { | |
const NOTIFICATION_MESSAGE = 'F9D4494D-62F8-4CBD-BCCA-CC3DB557276A' |
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 schedule = require('node-schedule'); | |
var ScheduleService = (function () { | |
var instance; | |
function init() { | |
// | |
// * * * * * * | |
// ┬ ┬ ┬ ┬ ┬ ┬ | |
// │ │ │ │ │ | | |
// │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun) |
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 kue = require('kue'); | |
// Priority Level | |
// { | |
// low: 10 | |
// , normal: 0 | |
// , medium: -5 | |
// , high: -10 | |
// , critical: -15 | |
// }; | |
var CreateJobService = (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
var co = require('co') | |
LogDive.testORM = function(cb) { | |
var query = { | |
"where": {"id": "1234567890"}, | |
include: ['photos','comments','likes','owner',{user:'profile'}] | |
} | |
co(function*() { | |
var insts = yield DataTable.find(query); | |
console.log(insts); | |
cb(null,insts); |
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 getCountryCode = promisify(myGoogleMapAPI.getGeoCodeByAddress); | |
var result = yield (allCountry.map(function(country,index){ | |
var result = getCountryCode(country); | |
return {country:country,result:result} | |
})) |
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 ObjectID = require("bson-objectid"); | |
webappfiles.genMongoId = function(objectId,cb) { | |
console.log(ObjectID(objectId)); //Correct One | |
console.log(MongoId(objectId)); //Wrong | |
cb(null,ObjectID(objectId)) | |
} |
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
forEach is Synchronous Operation. It Blocks. |
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
// 修改后 既支持 callback 回调,又支持 Promise | |
var getInfo = function(uid, callback) { | |
return new Promise(function(resolve, reject) { | |
if (callback) { | |
resolve = function (ret) { | |
callback(null, ret); | |
}; | |
reject = 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
(function(){ | |
var parse = JSON.parse; | |
JSON = { | |
stringify: JSON.stringify, | |
validate: function(str){ | |
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 asyncLoop(iterations, func, callback) { | |
var index = 0; | |
var done = false; | |
var loop = { | |
next: function() { | |
if (done) { | |
return; | |
} | |
if (index < iterations) { |
OlderNewer