Skip to content

Instantly share code, notes, and snippets.

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] + '')
}))
})
@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']),
@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 / 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;
AuctionController.getAll = function() {
return collections.AuctionCollection.forge().fetch();
};
@joepie91
joepie91 / get.js
Last active December 16, 2015 21:14 — forked from horsey/get.js
var aws = require('aws-sdk'),
Promise = require('bluebird'),
chalk = require('chalk'),
messageFactory = require('./factory'),
config = require('./config.json');
var sqs = new Promise.promisifyAll(new aws.SQS({
region: config.aws.region,
accessKeyId: config.aws.accessId,
@joepie91
joepie91 / gist:e78ca0c9d9831de4c775
Last active December 11, 2015 11:51 — forked from horsey/gist:96ce0a9db9e66090288d
Code snippet to demonstrate Promises.
'use strict';
var _ = require('lodash');
var async = require('async');
var moment = require('moment');
var Promise = require('bluebird');
var messaging = require('../../messaging');
var patients = require('../patients');
var practitioners = require('../practitioners');
var dataProvider = require('../../database');
@joepie91
joepie91 / api.js
Last active December 7, 2015 22:28 — forked from WickedDevice/api.js
var Promise = require("bluebird");
var bhttp = Promise.promisifyAll(require("bhttp"));
// config encapsulates opensensors-api-key
// the only key config should have is "api-key"
module.exports = function(config) {
var API_BASE_URL = "https://api.opensensors.io/v1/";
var API_OPTIONS = {
headers: {
Accept: "application/json",
passport.use(new LocalStrategy(
function(username, password, done) {
collections.UserCollection.forge()
.query(function (qb) {
qb.where('username', '=', username.toLowerCase());
})
.fetchOne()
.then(function (user) {
if (user == null) {
return new Promise((resolve, reject) => {
var currentDate = moment().format();
var dates = [];
for (var i = 1; i < days + 1; i++) {
dates.push(moment().subtract(i, "days"));
}
resolve(dates);