Skip to content

Instantly share code, notes, and snippets.

var promisify = require("es6-promisify"); // you can also look for a promisifyAll equivalent, but for the sake of demonstration
function findText(freeText, result) {
var query = {
index: result.teamUnique + "_team",
type: result.username,
body: {
query: {
match: {
name: freeText
@joepie91
joepie91 / ak.js
Last active October 31, 2015 14:53
criterion.forEach(function(item) {
item.maprange = item.startmap + " ";
if (item.endmap != null && item.startmap !== item.endmap) {
item.maprange += " - " + item.endmap;
}
})
var Promise = require("bluebird");
function promisifyWaterline(action){
return Promise.try(function() {
return action();
}).catch(function(err) {
// you should almost never catch errors inline. ONLY do it if you need to 'repackage' an error.
// definitely don't do the below, as you lose the original error.
throw new Error("lol");
})
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);
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) {
@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",
@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 / 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,
AuctionController.getAll = function() {
return collections.AuctionCollection.forge().fetch();
};
@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;