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 Promise = require("bluebird"); | |
| function promisifyWaterline(action){ | |
| return Promise.try(function() { | |
| return action(); | |
| }).catch(function(err) { | |
| // you should almost never catch errors inline. ONLY do it if you need to 'repackage' an error. | |
| // definitely don't do the below, as you lose the original error. | |
| throw new Error("lol"); | |
| }) |
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
| criterion.forEach(function(item) { | |
| item.maprange = item.startmap + " "; | |
| if (item.endmap != null && item.startmap !== item.endmap) { | |
| item.maprange += " - " + item.endmap; | |
| } | |
| }) |
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 promisify = require("es6-promisify"); // you can also look for a promisifyAll equivalent, but for the sake of demonstration | |
| function findText(freeText, result) { | |
| var query = { | |
| index: result.teamUnique + "_team", | |
| type: result.username, | |
| body: { | |
| query: { | |
| match: { | |
| name: freeText |
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 inherits = require('utils').inherits | |
| var Model = require('some-orm').Model | |
| function User () { | |
| Model.call(this) | |
| } | |
| inherits(User, Model) | |
| Model.prototype.getName () { |
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
| function bingTranslate(message,originLang,destLang,accessToken){ | |
| Promise.try(function(){ | |
| accessToken.then(function(bingToken){ | |
| options = { | |
| headers:{ | |
| 'Authorization': "Bearer "+accessToken | |
| } | |
| }; | |
| queryString="text="+encodeURIComponent(message)+"&from="+originLang+"&to="+destLang+"&contentType=text%2Fplain"; | |
| return bhttp.get("http://api.microsofttranslator.com/V2/Http.svc/Translate?"+queryString,options).then(function(data){ |
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
| function buildTranslations(message, originLanguage, destLanguages){ | |
| return Promise.try(function(){ | |
| translations = {}; | |
| destLanguages.map(function(currentLang){ | |
| translations[currentLang.code] = {} | |
| db.model('Translation').translate(message,originLanguage.code,currentLang.code).then(function(translation){ | |
| console.log('build Trans function'+translation); | |
| translations[currentLang.code] = translation; | |
| }); | |
| }); |
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
| server.notes.getdomain = function(domain){ | |
| return function(callback) { | |
| callback(null) | |
| } | |
| } |
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 Promise = require("bluebird"); | |
| var db = Promise.promisifyAll(db); | |
| function getUser(userId) { | |
| return Promise.try(function(){ | |
| return db.findAsync({"selector": {"documentType": "user", "_id": userId}}); | |
| }).then(function(userInfo){ | |
| if (userInfo.docs.length > 1) { | |
| throw new Error("More than one user returned."); | |
| } else { |
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
| const input = TestUtils.renderIntoDocument(<input onChange={sinon.spy()} />); | |
| Promise.resolve().then(function(){ | |
| TestUtils.Simulate.change(React.findDOMNode(input)); | |
| return true; | |
| }).then(function(result) { | |
| expect(result).to.be.true; | |
| expect(input.props.onChange).has.been.calledOnce; | |
| }).then(done, done); |
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
| function runBow(input, cb) { | |
| return Promise.try(function(){ | |
| if (input.url.match(/^https:\/\//i)) { | |
| /* Mutating is bad! */ | |
| var url = input.url.replace(/^https:\/\//i, 'http://'); | |
| } else { | |
| var url = input.url; | |
| } | |
| return bow.crawl(url); |