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
| //this function adds 3 to the number passed in | |
| function addThree(x) { | |
| return x + 3; | |
| } | |
| //this function takes a function and returns | |
| //a function that runs the function it was passed, | |
| //and then runs that function _again_ on the return | |
| //value of the first call to the function. | |
| //make sense? look at it until it does. |
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 http_get(url, { "User-Agent" = "kitchen sink 2.0" }, { sayHi, verbose: v }) { | |
| if (sayHi) { | |
| console.log("HI!"); | |
| } | |
| if (v) { | |
| console.log("Sending request"); | |
| } | |
| return require('http').get({ |
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
| exports.convertXLSXToJSON2 = function(req, res) { | |
| var path = fileServerPath + req.body.name; | |
| console.log("starting..." + path); | |
| var exists = fs.existsSync(path); | |
| console.log("path exists? " + exists); | |
| console.log("in xlsx to json 2 method...starting conversion"); | |
| try { | |
| var obj = asyncXLSX.parse(path); | |
| console.log("obj: " + obj); | |
| res.send(obj); |
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 Article = Promise.promisifyAll(require("../wherever/the/article/model/is")); | |
| var whichService = function whichService(input) { | |
| // Keep in mind that you need to *return* the promise (not just the values in the callback!) if you want to use them as return-like values. | |
| isDupe(input).then(function(data) { | |
| console.log( 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 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); |
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
| 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
| 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
| 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
| 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){ |
OlderNewer