This file contains 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
somePromise().then(function () { | |
return anotherPromise(); | |
}).then(function () { | |
return yetAnotherPromise(); | |
}).catch(console.log.bind(console)); |
This file contains 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
db.allDocs({include_docs: true}).then(function (result) { | |
return Promise.all(result.rows.map(function (row) { | |
return db.remove(row.doc); | |
})); | |
}).then(function (arrayOfResults) { | |
// All docs have really been removed() now! | |
}); |
This file contains 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
// I want to remove() all docs | |
db.allDocs({include_docs: true}).then(function (result) { | |
result.rows.forEach(function (row) { | |
db.remove(row.doc); | |
}); | |
}).then(function () { | |
// I believe all docs have been removed() | |
}); |
This file contains 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
db.allDocs(...).then(function (resultOfAllDocs) { | |
return localdb.put(...); | |
}).then(function (resultOfPut) { | |
return localdb.get(...); | |
}).then(function (resultOfGet) { | |
return localdb.put(...); | |
}).catch(function (err) { | |
console.log(err); | |
}); |
This file contains 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
db.allDocs({ | |
include_docs: true, | |
attachments: true | |
}).then(function (result) { | |
var docs = result.rows; | |
docs.forEach(function(element) { | |
localdb.put(element.doc).then(function(response) { | |
alert("Pulled doc with id " + element.doc._id + " and added to local db."); | |
}).catch(function (err) { | |
if (err.name == 'conflict') { |
This file contains 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 fs = require('fs'); | |
Promise.promisifyAll(fs); | |
var myFile = '/tmp/test'; | |
fs.readFileAsync(myFile, 'utf8').then(function(txt) { | |
txt = txt + '\nAppended something!'; | |
fs.writeFile(myFile, txt); | |
}).then(function() { | |
console.log('Appended text!'); | |
}).catch(function(err) { |
This file contains 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
fs.readdir(source, function (err, files) { | |
if (err) { | |
console.log('Error finding files: ' + err) | |
} else { | |
files.forEach(function (filename, fileIndex) { | |
console.log(filename) | |
gm(source + filename).size(function (err, values) { | |
if (err) { | |
console.log('Error identifying file size: ' + err) | |
} else { |
This file contains 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
'use strict'; | |
const Promise = require('bluebird'); | |
const fs = require('fs'); | |
const crypto = require('crypto'); | |
const gm = require('gm').subClass({imageMagick: true}); | |
var base64 = require('node-base64-image'); | |
const _ = require('lodash'); | |
function ImageServiceService() { |
NewerOlder