Skip to content

Instantly share code, notes, and snippets.

@joepie91
joepie91 / take2.js
Last active January 13, 2016 00:34 — forked from vicatcu/take2.js
return Promise.try(function () {
return MongoClient.connectAsync(MONGODB_CONNECTION_STRING)
}).then(function(db){
return Promise.try(function(){
return db.collection("downloads").findOneAsync({key: status.filename});
}).then(function(item){
return Promise.try(function() {
return db.closeAsync();
}).then(function() {
return item;
@joepie91
joepie91 / dump.js
Created January 13, 2016 22:51 — forked from audstanley/dump.json
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
@joepie91
joepie91 / Account.js
Last active February 6, 2017 14:30 — forked from anomaly44/Account.js
static login(email, password) {
return Promise.try(() => {
return Account.fetch(email))
}).then((acc) => {
return Promise.try(() => {
bcrypt.compareAsync(password, acc.password)
}).then(result => {
if (result) {
console.log(`User logged in: ${acc.email}`);
const token = jwt.sign(_.pick(acc, ['id', 'email', 'agencyId']),
client.select('*').from(opts.table).stream()
.pipe(through.obj(function chunkToFiles (chunk, enc, callback) {
const primaryKey = chunk[opts.primaryKey]
Object.keys(chunk).forEach((key) => {
this.push(new File({
path: `./${primaryKey}/${key}`,
contents: new Buffer(chunk[key] + '')
}))
})
const basename = require('basename');
const Promise = require('bluebird');
const globAsync = Promise.promisify(require('glob'));
const dir = 'a';
function galleryListPromise() {
return Promise.try( () => {
return globAsync("gallery/*/", {})
var Promise = require('bluebird');
var rdb = Promise.promisify(require('rethinkdb'));
module.exports = function(config) {
return {
connectToDb: function(){
return Promise.try(() => {
return rdb.connect(config);
});
}
@joepie91
joepie91 / .js
Created December 14, 2016 12:30
var resultTemplate = "" +
" <ul class='searchList'>" +
" <% _.each(paymentActions,function(paymentActivity){ %>" +
" <li><span class='amount visible-phone'>-<%= paymentActivity.grossAmount %></span>" +
" </li>" +
" <% }); %>" +
" </ul>";
var template = _.template(resultTemplate, {
@joepie91
joepie91 / .js
Last active April 28, 2017 14:13 — forked from lkmill/.js
'use strict';
const _ = require('lodash');
module.exports = (permissions, requiredPermissions) => {
if (!_.isPlainObject(requiredPermissions)) {
throw new TypeError('`requiredPermissions` is not an object');
} else if (!_.isPlainObject(permissions)) {
throw new TypeError('`permissions` is not an object');
} else {
/// Handler for /travel/{url}
module.exports.travel = (event, context, callback) => {
// Get the url from the resource path.
// Get the html.
// Turn it into a successful request.
// Attach the Node.js callback onto the end.
return Promise.try(() => {
return getURLFromPath(event.path);
}).then((url) => {
const ChartjsNode = require('chartjs-node');
// 600x600 canvas size
var chartNode = new ChartjsNode(600, 600);
var randomnumber=Math.random();
var imagename = "testimage"+randomnumber+".png"
module.exports = imagename
// each api returns a Promise
chartNode.drawChart({
type: 'bar',