function loadSpriteConfig(file, mapid) { var databuffer = []; var file_reader = fs.createReadStream(file+"/base.js"); file_reader.pipe(getPackConfigExtractorTransform()).on('data', function(chunk){ databuffer.push(chunk.toString()); }).on('end', sync.defer()); sync.await(); // console.log("Databuffer 1:", databuffer); sleep(100); var config; if (databuffer.length) config = JSON.parse(databuffer.join(" ")); else config = {}; databuffer.length = 0; file_reader = fs.createReadStream(file+"/"+ mapid+".js"); file_reader.pipe(getPackConfigExtractorTransform()).on('data', function(chunk){ databuffer.push(chunk.toString()); }).on('end', sync.defer()); sync.await(); // console.log("Databuffer 2:", databuffer); sleep(100); if (databuffer.length) extend(config, JSON.parse(databuffer.join(" "))); config["__path"] = file; return config; }
sync.fiber(function() { console.log('getStockCode'); var code = sync.await(otplib.requestStockCodeOTP(sync.defer())).text; var body = { isu_cd : null, no: 'P1', mktsel: 'ALL', searchText: isu_nm, pagePath: '/contents/COM/FinderStkIsu.jsp', code: code }; request .post(stockCodeURL) .type('form') .send(body) .end(sync.defer()); var result = sync.await(); result = JSON.parse(result.text); for(var i=0; i<result.block1.length; i++) { var stock = result.block1[i]; if(stock.codeName === isu_nm) { return stock; } } }, function(err, res) {
FetchCookie.prototype.init = function(drop) { if ( this.authdbname ) { this.authdb = new mongodb.Db( this.authdbname, mongodb.Server(this.host,this.port), { safe:true} ); sync.await(this.authdb.open(sync.defer())); sync.await(this.authdb.authenticate(this.user, this.pass, sync.defer())); this.db = this.authdb.db(this.dbname); } else { this.db = new mongodb.Db( this.dbname, mongodb.Server(this.host,this.port), { safe:true} ); sync.await(this.db.open(sync.defer())); } this.col = this.db.collection(this.colname); if ( drop ) { try { sync.await(this.col.drop(sync.defer())); }catch(e){ } } sync.await(this.col.ensureIndex({domain: 1},sync.defer())); }
FetchLogger.prototype.init = function(drop) { if ( this.authdbname ) { this.authdb = new mongodb.Db( this.authdbname, mongodb.Server(this.host,this.port), { safe:true} ); sync.await(this.authdb.open(sync.defer())); sync.await(this.authdb.authenticate(this.user, this.pass, sync.defer())); this.db = this.authdb.db(this.dbname); } else { this.db = new mongodb.Db( this.dbname, mongodb.Server(this.host,this.port), { safe:true} ); sync.await(this.db.open(sync.defer())); } this.col = this.db.collection(this.colname); if ( drop ) { try { sync.await(this.col.drop(sync.defer())); sync.await(this.col.ensureIndex({ts:1},sync.defer())); }catch(e){ } } // sync.await(this.col.ensureIndex({status:1},sync.defer())); // sync.await(this.col.ensureIndex({code:1},sync.defer())); // sync.await(this.col.update( // {status:{'$ne': 'End'} }, // { '$set' : {status:'Queuing',code:'queuing...'} } , // { multi : true } , sync.defer())); }
GetStockInfo: function(term) { var response; try { response = sync.await(request({ url: 'http://www.nasdaq.com/aspx/symbolnamesearch.aspx', qs: { q: term }, timeout: 10 * 1000 }, sync.defer())); } catch (e) { res.status(500).send('Error'); return; } var matches = response.body.split('\n'); var symbols = new Array() for (var i = 0; i < matches.length; i++) { var symbolAndName = matches[i].split(' | '); var symbol = symbolAndName[0].trim(); var name = '' if (symbolAndName[1]) { name = symbolAndName[1].split(';')[0] } var knownSymbol = true try { response = sync.await(request({ url: 'http://www.google.com/finance/info', qs: { q: 'NASDAQ:' + symbol }, timeout: 10 * 1000 }, sync.defer())); } catch (e) { // Ignore unknown symbols knownSymbol = false } if (knownSymbol) { var symbolMatches = response.body.trim().match(/\/\/\s+\[((.|\n)*)\]/); if (symbolMatches) { var jsonSymbolInfo = JSON.parse(symbolMatches[1]) var symbolInfo = jsonSymbolInfo.l_fix + ' ' + jsonSymbolInfo.c + ' (' + jsonSymbolInfo.cp + '%)' symbols.push(symbol + ' [' + symbolInfo + ']: ' + name) } } } return symbols }
function buildDevTools() { //These copies can happen in parallel sync.parallel(function(){ copyDirectory("lib/tools/", BUILD_OUT+"tools/"); copyFileWithJekyllPrepend("src/tools/mapview.html", BUILD_OUT+"tools/mapview.html"); copyFileWithJekyllPrepend("src/tools/gallery.html", BUILD_OUT+"tools/gallery.html"); copyFileWithJekyllPrepend("src/tools/ledgesim.html", BUILD_OUT+"tools/ledgesim.html"); copyFileWithJekyllPrepend("src/tools/chatot.html", BUILD_OUT+"tools/chatot.html"); copyFileWithJekyllPrepend("src/tools/music-test.html", BUILD_OUT+"tools/music-test.html"); copyFileWithJekyllPrepend("src/tools/casino.html", BUILD_OUT+"tools/casino.html"); }); var l = sync.await(); console.log("[Copy ] Copied", l.length, "dev tools files."); //These copies can happen in parallel sync.parallel(function(){ copyDirectory("res/music/", BUILD_OUT+"tools/music/"); }); var l = sync.await(); console.log("[Copy ] Copied", l.length, "music test files."); /////////////////////////// bundle("tools/mapview", { dest:BUILD_OUT+"tools/mapview.js", appcache:false, globals: { COMPILED_MAPS : function() { return "['"+compiledMaps.join("', '")+"']"; }, }, }); bundle("tools/gallery", { dest:BUILD_OUT+"tools/gallery.js", appcache:false, }); bundle("tools/ledgesim", { dest:BUILD_OUT+"tools/ledgesim.js", appcache:false, }); bundle("tools/chatot", { dest:BUILD_OUT+"tools/chatot.js", appcache:false, }); bundle("tools/music-test", { dest:BUILD_OUT+"tools/music-test.js", appcache:false, }); bundle("tools/casino", { dest:BUILD_OUT+"tools/casino.js", appcache:false, }); }
function cleanpos(string) { var pos = sync.await(readpos(string, sync.defer())) if (pos == null) { pos = sync.await(tagger.tag(string, sync.defer())) sync.await(writepos(string, pos, sync.defer())) } return pos // var tagged = tagger.tag(string) // writepos(string, tagged) // return tagged }
module.exports = function(req, res) { if (!req.query.text.trim()) { res.json({ body: '' }); return; } var get_params_obj = { key: api_key, text: req.query.text.trim(), lang: 'en-es', format: 'json' }; var response; try { response = sync.await(request({ url: 'https://translate.yandex.net/api/v1.5/tr.json/translate', timeout: 10 * 1000, qs: get_params_obj }, sync.defer())); } catch (e) { res.status(500).send('Error'); return; } res.json({ body: JSON.parse(response.body).text + '<br>' + "<a href='http://translate.yandex.com/'>Powered by Yandex.Translate</a>" }); return; };
syncTextEvidence: function (listOfResources, parentResource) { function errorWrappedTfIdf(listOfResources, parentResource, callback) { rank(listOfResources, parentResource).then(function(results) { callback(null, results); }); } return sync.await(errorWrappedTfIdf(listOfResources, parentResource, sync.defer())); },
function handleSearchString(term, req, res) { // Here, we just select the very first post from the subreddit page var response; try { response = sync.await(request({ url: 'http://www.reddit.com/r/' + term + '.json', gzip: true, json: true, timeout: 10 * 1000 }, sync.defer())); } catch (e) { res.status(500).send('Error'); return; } if (!response || !response.body || !response.body.data || !response.body.data.children) { // We did not get the correct response back, return an error res.status(500).send('Error'); return; } res.json({ body: createHtml(response.body.data.children[0]) // Add raw:true if you're returning content that you want the user to be able to edit }); }
function handleSearchString(term, req, res) { var response; try { response = sync.await(request({ url: 'http://api.giphy.com/v1/gifs/random', qs: { tag: term, api_key: key }, gzip: true, json: true, timeout: 15 * 1000 }, sync.defer())); } catch (e) { res.status(500).send('Error'); return; } var data = response.body.data; // Cap at 600px wide var width = data.image_width > 600 ? 600 : data.image_width; var html = '<img style="max-width:100%;" src="' + data.image_url + '" width="' + width + '"/>'; res.json({ body: html // Add raw:true if you're returning content that you want the user to be able to edit }); }
function bundle(srcs, mapid, type) { // Browserify the events together var bundler = new Browserify({ noParse : ["three", "jquery"], debug : true, insertGlobalVars : { add : function() { return "function(a){ currentMap.addEvent(a); }"; }, map : function() { return "currentMap"; }, }, }); bundler.add(srcs); bundler.transform(getPackConfigRemoverTransform); bundler.exclude("three"); bundler.exclude("jquery"); // Externalize the Event Library bundler.external(EXTERNAL_EVENT_LIBS); bundler.plugin("minifyify", { map: SRC_MAPS+"/maps/"+mapid+"/"+type+".map.json", output: SRC_MAPS+"/maps/"+mapid+"/"+type+".map.json", minify: MINIFY, }); var data = sync.await(bundler.bundle(sync.defer())); console.log("[Event] Bundled", (typeof srcs == "string")?1:srcs.length, type, "events."); return data; }
FetchList.prototype.fetching = function () { return sync.await(this.col.findAndModify( { status: 'Queuing' }, {}, { '$set' : { status: 'Fetching',date:new Date().getTime() } } , { new : true } , sync.defer())).value; }
function handleIdString(id, req, res) { var response; try { response = sync.await(request({ url: 'http://api.giphy.com/v1/gifs/' + encodeURIComponent(id), qs: { api_key: key }, gzip: true, json: true, timeout: 15 * 1000 }, sync.defer())); } catch (e) { res.status(500).send('Error'); return; } var image = response.body.data.images.original; var width = image.width > 600 ? 600 : image.width; var html = '<img style="max-width:100%;" src="' + image.url + '" width="' + width + '"/>'; res.json({ body: html // Add raw:true if you're returning content that you want the user to be able to edit }); }
FetchCookie.prototype.get = function(protocol, domain, path) { var domains = this.domains(domain); var paths = this.paths(path); var cookies = sync.await(this.col.find({ domain : { $in: domains }, path : { $in: paths }, }).toArray(sync.defer())); var merged = {}; for ( var i in cookies ){ var cookie = cookies[i]; for ( var k in cookie.values ){ var value = cookie.values[k]; if ( protocol !== 'https' && value.s){ continue; } merged[k] = value.v; } } var ret = ''; for ( var i in merged ){ ret += i + '=' + merged[i] + ';' } return ret; }
function handleIdString(id, req, res) { var response; try { response = sync.await(request({ url: id + '.json', gzip: true, json: true, timeout: 15 * 1000 }, sync.defer())); } catch (e) { res.status(500).send('Error'); return; } if (!response || !response.body || !response.body[0].data || !response.body[0].data.children) { // We did not get the correct response back, return an error res.status(500).send('Error'); return } res.json({ body: createHtml(response.body[0].data.children[0]), // Add raw:true if you're returning content that you want the user to be able to edit }); }
FetchList.prototype.queuing = function (url,test,referer) { var data = sync.await(this.col.findOne( { _id : url}, sync.defer())); if ( data ) { return data; } this.change(url,'Queuing',Array(50).join(' '),test,referer); return null; }
createEmptyTest : function(testId) { var testModel = new TestModel({ testId: testId, lists: {} }); return sync.await( testModel.save(sync.defer()) ); },
FetchLogger.prototype.body = function( url , status,header,body ) { var data = { _id: url, status:status, header:header, body:body, ts: new Date().getTime() }; sync.await(this.col.save( data, sync.defer())); }
findTrading.forEach(function(trading) { if(time % trading.time != 0 ) { return; } var param = { type: trading.type }; sync.await(tradingService.findTradingList(param, sync.defer())); });
function compileLess(src, dest) { console.log("[Less ] Compiling less", src, ">", dest); sync.await(exec("lessc "+src+" "+dest, sync.defer())); // if (exec("lessc "+src+" "+dest) != 0){ // throw new Error("Exec lessc returned non-zero!"); // } appCache.push(dest); }
sync.fiber(function() { var body = { sect_tp_cd: null, period_strt_dd: date.format('YYYYMMDD'), period_end_dd: date.format('YYYYMMDD'), pagePath: '/contents/MKD/10/1002/10020310/MKD10020310.jsp', code: code }; if(type === 'kosdaq') { body.ind_tp = 'KSQ'; body.idx_type = 2001; } else if(type === 'kospi') { body.ind_tp = 'STK'; body.idx_type = 1001; } request .post(top100StocksURL) .type('form') .send(body) .end(sync.defer()); var result = sync.await(); result = JSON.parse(result.text); result = result.block1.splice(0, 99); result = result.map(function(stock) { return { kor_shrt_isu_nm: stock.kor_shrt_isu_nm, isu_end_pr: stock.isu_end_pr } }); result.forEach(function(stock) { //새로운 stock정보 저장 sync.await(stocklistlib.addStock(stock.kor_shrt_isu_nm, sync.defer())); }); //best stock 추가 sync.await(stocklistlib.addBestStock(date.format('YYYYMMDD'), type, result, sync.defer())); }, function(err, res) {
createTestResult : function(testId, testResults) { var resultForList = {}; resultForList[testResults.listId] = testResults.result; var testModel = new TestModel({ testId: testId, lists: resultForList }); return sync.await( testModel.save(sync.defer()) ); },
function copyResourceFiles() { //These copies can happen in parallel sync.parallel(function(){ copyDirectory("res/img/", BUILD_OUT+"img/"); copyDirectory("res/snd/", BUILD_OUT+"snd/"); copyDirectory("res/css/", BUILD_OUT+"css/"); }); var l = sync.await(); console.log("[Copy ] Copied", l.length, "static image files."); }
FetchList.prototype.timeout = function (url) { var data = sync.await(this.col.findAndModify( { _id : url, status: { '$ne': 'End'} }, {}, { '$set' : { status: 'End', code:'TIMEOUT',date:new Date().getTime() } } , { new : true } , sync.defer())); if ( data ) { return true; } return false; }
function copyHtmlFiles() { //These copies can happen in parallel sync.parallel(function(){ copyFileWithJekyllPrepend("src/game.html", BUILD_OUT+"/game.html"); copyFileWithJekyllPrepend("src/index.html", BUILD_OUT+"/index.html"); }); var l = sync.await(); console.log("[Copy ] Copied", l.length, "html files."); return; }
function copyConfigFiles() { //These copies can happen in parallel sync.parallel(function(){ copyFile("src/.htaccess", BUILD_OUT+"/.htaccess"); copyFile("src/_config.yml", BUILD_OUT+"/_config.yml"); copyFile("ParkReadme.md", BUILD_OUT+"/README.md"); }); var l = sync.await(); console.log("[Copy ] Copied", l.length, "config files."); }
function createEventLibraryBundle(outfile) { // Browserify the Event Library classes together var bundler = new Browserify({ noParse : ["three", "jquery"], debug : true, }); bundler.exclude("three"); bundler.exclude("jquery"); bundler.require("extend", { expose: "extend" }); bundler.require("inherits", { expose: "inherits" }); bundler.require("./src/js/events/event", { expose: "tpp-event" }); bundler.require("./src/js/events/trigger", { expose: "tpp-trigger" }); bundler.require("./src/js/events/warp", { expose: "tpp-warp" }); bundler.require("./src/js/events/actor", { expose: "tpp-actor" }); bundler.require("./src/js/events/sign", { expose: "tpp-sign" }); bundler.require("./src/js/events/animevent", { expose: "tpp-animevent" }); bundler.require("./src/js/events/camera-trigger", { expose: "tpp-cameratrigger" }); bundler.require("./src/js/events/particle-system", { expose: "tpp-particle" }); bundler.require("./src/js/events/player-character", { expose: "tpp-pc" }); bundler.require("./src/js/events/actor_animations", { expose: "tpp-actor-animations" }); bundler.require("./src/js/events/behavior", { expose: "tpp-behavior" }); bundler.require("./src/js/managers/controller", { expose: "tpp-controller" }); bundler.require("./src/js/model/spritemodel", { expose: "tpp-spritemodel" }); bundler.require("./src/js/model/model-mods", { expose: "tpp-model-mods" }); bundler.require("./src/js/events/tGallery", { expose: "tpp-test-gallery" }); // This function will collect all the exposed labels, in a process similar to passing // this not-yet-bundled bundler to another bundler through external(). bundler.on("label", function(prev, id){ if (typeof id == "string") EXTERNAL_EVENT_LIBS.push(id); }); bundler.plugin("minifyify", { map: "_srcmaps/maps/events.map.json", output: "_srcmaps/maps/events.map.json", minify: MINIFY, }); var data = sync.await(bundler.bundle(sync.defer())); fs.writeFileSync(BUILD_OUT+"js/eventlib.js", data); console.log("[EvLib] Bundled event library."); //return data; }
createTestResultSet : function(req, res) { var testId = req.params.id; var pushedLists = _.mapKeys(req.body.lists, function(value, key) { return key.replace(/\./g, ''); }); if (!testId) { res.json(TestModelCtrl.NO_TEST_ID); return; } if (!pushedLists || !_.isObject(pushedLists)) { res.json(TestModelCtrl.NO_RESULT_LISTS); return; } var testModel, lists; // create a new test model or fetch an existing one if (!TestModelCtrl.existsTest(testId)) { testModel = TestModelCtrl.createEmptyTest(testId); lists = {}; } else { testModel = TestModelCtrl.fetchTest(testId); lists = testModel.lists || {}; } // if a list does not exist yet // create a version container for (var listId in pushedLists) { if (!_.has(lists, listId)) { lists[listId] = []; // empty version container } } // add new lists to each version container testModel.lists = _(lists) .mapValues(function(versions, listId) { if (_.has(pushedLists, listId)) { return versions.concat([ pushedLists[listId] ]); } return versions; }) .value(); sync.await( testModel.save(sync.defer()) ); res.json(TestModelCtrl.SUCCESSFULLY_SAVED); }
module.exports = function(req, res) { var user = req.query.text.trim(); if (!user) { res.json([{ title: '<i>(enter a username or organization)</i>', text: '' }]); return; } // Compared to the tutorial, there's no need for underscore. Our Mixmax typeahead dropdown should only contain one // entry per query var response; try { response = sync.await(request({ url: 'https://api.github.com/users/' + user, 'headers': { 'user-agent': 'alexadusei' }, json: true, timeout: 10 * 1000, }, sync.defer())); } catch (e) { res.status(500).send('Error'); return; } // Essentially happens when the user doesn't exist, return no results if (response.statusCode !== 200 || !response.body) { res.json([{ title: '<i>(no results)</i>', text: '' }]); return; } // Display their bios. If they have none, just display their name var textInfo = !response.body.bio ? response.body.name : response.body.bio; // Some GitHub users don't even have names.. (bots?). If so, leave the field blank. var textInfo = !textInfo ? '' : textInfo; res.json([ { title: '<img style="height:75px;float:left" src="' + response.body.avatar_url + '">' + '<p style="height:75px;margin-left:80px">' + textInfo + '</p>', text: user }]); };