コード例 #1
0
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;
}
コード例 #2
0
ファイル: request.js プロジェクト: lmo0317/etrade
    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) {
コード例 #3
0
ファイル: fetch_cookie.js プロジェクト: review---/analysis
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()));
}
コード例 #4
0
ファイル: fetch_logger.js プロジェクト: review---/analysis
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()));
}
コード例 #5
0
  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
  }
コード例 #6
0
ファイル: build.js プロジェクト: tustin2121/TPPParkDev
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, 
	});
}
コード例 #7
0
ファイル: utils1.js プロジェクト: erelsgl/nlu-server
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
}
コード例 #8
0
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;
};
コード例 #9
0
  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()));
  },
コード例 #10
0
ファイル: resolver.js プロジェクト: adamstony2/mixmaxreddit
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
  });
}
コード例 #11
0
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
  });
}
コード例 #12
0
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;
}
コード例 #13
0
ファイル: fetch_list.js プロジェクト: review---/analysis
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
  });
}
コード例 #15
0
ファイル: fetch_cookie.js プロジェクト: review---/analysis
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;
}
コード例 #16
0
ファイル: resolver.js プロジェクト: adamstony2/mixmaxreddit
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
  });
}
コード例 #17
0
ファイル: fetch_list.js プロジェクト: review---/analysis
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;
}
コード例 #18
0
	createEmptyTest : function(testId) {
		var testModel = new TestModel({
			testId: testId,
			lists: {}
		});

		return sync.await( testModel.save(sync.defer()) );
	},
コード例 #19
0
ファイル: fetch_logger.js プロジェクト: review---/analysis
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()));
}
コード例 #20
0
ファイル: cron.js プロジェクト: lmo0317/etrade
            findTrading.forEach(function(trading) {
                if(time % trading.time != 0 ) {
                    return;
                }

                var param = {
                    type: trading.type
                };
                sync.await(tradingService.findTradingList(param, sync.defer()));
            });
コード例 #21
0
ファイル: build.js プロジェクト: tustin2121/TPPParkDev
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);
}
コード例 #22
0
ファイル: request.js プロジェクト: lmo0317/etrade
    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) {
コード例 #23
0
	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()) );
	},
コード例 #24
0
ファイル: build.js プロジェクト: tustin2121/TPPParkDev
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.");
}
コード例 #25
0
ファイル: fetch_list.js プロジェクト: review---/analysis
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;
}
コード例 #26
0
ファイル: build.js プロジェクト: tustin2121/TPPParkDev
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;
	
}
コード例 #27
0
ファイル: build.js プロジェクト: tustin2121/TPPParkDev
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.");
}
コード例 #28
0
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;
}
コード例 #29
0
	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);
	}
コード例 #30
0
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
  }]);
};