Example #1
0
m.getBlockHeight = function () {
    var promise = new Promise();

    var now = new Date().getTime() / 1000;
    /*if (now < lastCheckedBlockHeight + 10) {

     // console.log("do not need https", bHeight);
     promise.resolve(bHeight);
     return promise;
     // return promise;
     }*/

    https.get('https://blockchain.info/latestblock', function (r) {

        var d = '';

        r.on('data', function (chunk) {
            d += chunk;
        });

        r.on('end', function () {
            try {
                var resObj = JSON.parse(d);
                bHeight = resObj.height;
                m.updateBTCTxs();
            //    console.log("blockchain.info/latestblock bHeight ", bHeight);
                lastCheckedBlockHeight = new Date().getTime() / 1000;
                promise.resolve(bHeight);
            } catch (e) {
                console.log("https.get err", e)

            }
        });

        r.on('error', function (e) {
            console.log("https.get err", e)
        });
    });

    return promise;
};
Example #2
0
Conveyor.prototype.print = function() {
    var that = this;
    var promise = new Promise();
    var slicer_settings = {};
    // Create dummy slicer settings
    var param_names = ['slicer', 'extruder', 'raft', 'support', 'infill', 'layer_height', 'shells',
        'extruder_temperatures', 'platform_temperature', 'heat_platform', 'print_speed', 'travel_speed',
        'default_raft_extruder', 'default_support_extruder', 'do_auto_raft', 'do_auto_support', 'path', 'materials'];
    for (var name in param_names) {
        slicer_settings[param_names[name]] = null;
    }

    slicer_settings['extruder'] = "0";
    slicer_settings['materials'] = ['PLA', 'PLA'];
    slicer_settings['extruder_temperatures'] = [0, 0];

    this.rpc.invoke('print', {
        "machine_name": that.deviceData.identifier,
        "input_file": that.tmpGCodeFile,
        "has_start_end": true,
        "user_print_settings": slicer_settings,
        "thumbnail_dir": '',
        "metadata": {},
        "job_metadata": {},
        "verify_gcode": false
    })
        .then(function (reply) {
            if (reply && reply.hasOwnProperty('error')) {
                logger.info('could not start print');
                promise.resolve(DriverResponse.Failure(that.getState(), DriverResponse.Errors.COMMAND_FAILED));
            }
            else {
                logger.info('print started with id: ', reply.id);
                that.conveyorJobId = reply.id;
                that.print_progress = 0;
                promise.resolve(DriverBase.prototype.print.call(that));
            }
        });

    return promise;
};
Example #3
0
shorten.updateMe = function(hash, key, data) {
  var promise = new Promise();
  var blankKey = {}
  blankKey[key] = data
  var query = { hash : hash }
	  	, update = { $set: blankKey }
	    , options = {};
  //console.log(update)
  var retrievePromise = ShortURL.findOne(query);
  ShortURL.update(query, update, options, function(){ });
  retrievePromise.then(function(ShortURLObject) {
    if (ShortURLObject && ShortURLObject !== null) {
      promise.resolve(ShortURLObject);
    } else {
      promise.reject(new Error('MongoDB - Cannot find Document'), true);
    };
  }, function(error) {
    promise.reject(error, true);
  });
  return promise;
};
Example #4
0
shorten.generate = function(document, forcehash) {
  var generatePromise
    , promise = new Promise()
    , generatedHash = ID.store(document.URL+document.pubID)
    , query = { URL: document.URL, pubID: document.pubID };
  document['URL'] = document.URL;
  document['pubID'] = document.pubID;
  document['hash'] = generatedHash;
  if (forcehash) {
    document['hash'] = forcehash;
    query = { 'hash': document['hash'] };
  }
  document['data'] = (document.data) ? document.data : null;
  generatePromise = ShortURL.findOrCreate(query, document, {});
  generatePromise.then(function(ShortURLObject) {
    promise.resolve(ShortURLObject);
  }, function(error) {
    promise.reject(error, true);
  });
  return promise;
};
Example #5
0
exports.generate = function(document) {
  var generatePromise
    , promise = new Promise();

  document['data'] = document.data || null;

  // hash was specified, so we should always honor it
  if (document.hasOwnProperty('hash')) {
    generatePromise = ShortURL.create(document);
  } else {
    document['hash'] = ID.store(document.URL);
    generatePromise = ShortURL.findOrCreate({URL : document.URL}, document, {});
  }

  generatePromise.then(function(ShortURLObject) {
    promise.resolve(ShortURLObject);
  }, function(error) {
    promise.reject(error, true);
  });

  return promise;
};
Example #6
0
Conveyor.prototype.cancel = function() {

    var promise = new Promise();
    var that = this;

    // Delete temp gcode file
    this.removeTempGCode();

    this.rpc.invoke('job_cancel', {
        "id": this.conveyorJobId
    })
        .then(function (reply) {
            if (reply && reply.hasOwnProperty('error')) {
                logger.info('could not cancel print');
                promise.resolve(DriverResponse.Failure(that.getState(), DriverResponse.Errors.COMMAND_FAILED));
            } else {
                logger.info('print canceled');
                promise.resolve(DriverBase.prototype.cancel.call(that));
            }
        });
    return promise;
};
Example #7
0
ObjectsStore.prototype.getId = function (name) {
	var promise = new Promise(),
		that = this;
	this.get().then(function (objects) {
		for (var id in objects) {
			if (objects.hasOwnProperty(id)) {
				if (objects[id] === name) {
					promise.resolve(id);
					return;
				}
			}
		}
		connection.query('INSERT INTO ' + that.type + ' SET ?', {name: name}, function (err, result) {
			if (err) return;

			var id = result.insertId;
			that.cache[id] = name;
			promise.resolve(id);
		});
	});
	return promise;
};
Example #8
0
module.exports.saveCoder = function (keyword, data) {
  var promise = new Promise();

  MongoClient.connect(url, function(err, db) {
    if (err) {
      console.log(err);
      return;
    }

    db.collection(keyword).remove();
    db.collection(keyword).insert(data, function (error, result) {
      if (error) {
        console.log(error);
        return;
      }
      promise.resolve(result);
      db.close();
    });
  });

  return promise;
};
Example #9
0
        var gss_fetch = function(url, key) {
            var promise = new Promise.Promise();
            http.get(url, function(res) {
                var response_data = '';
                res.on('error', function(e) {
                    promise.reject("Got error: " + e.message);
                });
                res.on('data', function(data) {
                    response_data += data;
                });
                res.on('end', function(data) {
                    var data = JSON.parse(response_data);
                    var more_promises = [];
                    for (var i = 0; i < data.feed.entry.length; i++) {
                        more_promises.push( fetch_each_sheet(data.feed.entry[i], key) );
                    }
                    Promise.all( more_promises ).then(function(results) {
                        var resolvable = {};
                        if (results.length > 1) {
                            resolvable[data.feed.title.$t] = {};
                            for (var i=0; i < results.length; i++) {
                                var key = Object.keys(results[i])[0];
                                resolvable[data.feed.title.$t][key] = results[i][key];
                            }
                            promise.resolve(resolvable);
                        } else if (results.length === 1) {
                            var key = Object.keys(results[0])[0];
                            resolvable[data.feed.title.$t] = results[0][key];
                            promise.resolve(resolvable);
                        } else {
                            promise.reject("Bad return from spreadsheets: " + results);
                        }

                    });
                });
            });
            return promise;
        };
Example #10
0
	function(error, response, body) {
        console.log(body);
			var tokens = [],
				cleanString = body.match(/\n(\d)(.)+/g);

                console.log(cleanString);

				if(!cleanString) {
					return false;
				}

				cleanString.forEach(function(line) {
				var token = {};

				var elements = line.match(/[^\t]+/g);

				token.text = elements[1];
				token.base = elements[2];
				token.type = elements[3];
				token.subtype = elements[4];

				if(elements[5]) {
					var allData = elements[5].split('|');
				var data = {};
					allData.forEach(function(d) {
						var splitted = d.split('=');
						data[splitted[0]] = splitted[1];
					});
				}

				token.data = data;

				tokens.push(token);
			});

			promise.resolve(tokens);
	});
module.exports = function(page) {
    var p = new Promise();

    // query dbpedia for images from a page
    var endpoint = 'http://dbpedia.org/sparql';
    var query = "SELECT ?img WHERE {?concept <http://xmlns.com/foaf/0.1/isPrimaryTopicOf> <"+page+"> . ?concept <http://xmlns.com/foaf/0.1/depiction> ?img}";

    // issue query
    var client = new SparqlClient(endpoint);
    client.query(query)
        .execute(function(error, results) {
            if (error) {
                p.reject(error);
            } else {
                try {
                    p.resolve(results.results.bindings[0].img.value);
                } catch (e) {
                    p.reject(e);
                }
            }
        });

    return p;
}
Example #12
0
    getLink: function (guid) {
        var promise = new Promise(),
            me = this;

        guid = guid || me.guid;

        // Fetch some recent history from the room and try to find our
        // image's GUID. Then harvest the file URL from the message
        request(me.historyUrl, function (e, r, b) {
            var items = JSON.parse(b).items,
                fileMessage = items.filter(function (e) {
                    return e.message === guid;
                });

            if (fileMessage.length === 0) {
                promise.resolve(messages.guidNotFound);
                return;
            }

            promise.resolve(fileMessage[0].file.url);
        });

        return promise;
    }
Example #13
0
 var lateResponder = _.debounce(function () {
   if (waitingForOutput) {
     promise.resolve(output);
   }
 }, 100);
Example #14
0
 }, function(error) {
   promise.reject(error, true);
 });
Example #15
0
 generatePromise.then(function(ShortURLObject) {
   promise.resolve(ShortURLObject);
 }, function(error) {
Example #16
0
 function (e, r, b) {
     promise.resolve(b);
 });
Example #17
0
			connection.query('INSERT INTO positions SET ?', position, function (err) {
				if (err) throw err;
				promise.resolve();
			});
Example #18
0
							connection.query('REPLACE INTO posts SET ?', post, function (err) {
								if (err) throw err;
								promise.resolve();
							});
Example #19
0
 ShortURLObject.save(function (err) {
     if (err) {
         promise.reject(new Error('Couldn\'t save ShortURLObject'), true);
     }  
 });
Example #20
0
 listPromise.then(function(ShortenedURLObjects) {
   promise.resolve(ShortenedURLObjects);
 }, function(error) {
Example #21
0
 }, function (err) {
     clientPromise.reject(err);
 });
Example #22
0
 Promise.all(promises).then(function () {
     clientPromise.resolve();
 }, function (err) {
Example #23
0
 function () {
     promise.resolve(me.guid);
 });
Example #24
0
 .then(function (stdout) {
   promise.resolve(stdout);
 });
Example #25
0
			connection.query('REPLACE INTO subscribers SET ?', {time: now, id: subreddit, count: count}, function (err) {
				if (err) throw err;

				promise.resolve();
			});
Example #26
0
 addWantProduct.add(returnObj.destHost, returnObj.rawUrl, mongodbDoc.hash, true).then(function(result) {
   routePromise.resolve(result);
 });
Example #27
0
	connection.query('SELECT * FROM positions WHERE ?', filter, function (err, rows) {
		if (err) throw err;

		promise.resolve(rows);
	});
Example #28
0
 }, function(err) {
   routePromise.reject(new Error('Could not find a Beso match ' + err), true);
 });
Example #29
0
	  generatePromise.then(function(result) {
	    promise.resolve(result);
	    //console.log(result);
	  }, function(error) {
Example #30
0
 }, function(error) {
   if (error) {
     log.log({event: 'Shorterror', text: 'Creation problem' + error});
     routePromise.reject(new Error('Creation problem'), true);
   }
 });