Skip to content

Instantly share code, notes, and snippets.

@joepie91
joepie91 / .js
Last active August 26, 2015 21:48 — forked from dsauerbrun/.js
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;
});
});
@joepie91
joepie91 / .js
Last active August 27, 2015 20:50 — forked from dsauerbrun/.js
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){
@joepie91
joepie91 / stuff.js
Created January 3, 2015 18:00 — forked from mderijcke/stuff.js
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({
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);
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);
})
}
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);
@joepie91
joepie91 / -.js
Last active August 29, 2015 14:25 — forked from marr/-
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);
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 {
server.notes.getdomain = function(domain){
return function(callback) {
callback(null)
}
}
//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.