Skip to content

Instantly share code, notes, and snippets.

Sven Slootweg joepie91

Block or report user

Report or block joepie91

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View js_example.js
"use strict";
const Promise = require("bluebird");
const AWS = require("aws-sdk");
AWS.config.update({ region: "eu-central-1" });
module.exports = function createRDSInstance(identifier) {
let rds = new AWS.RDS();
return Promise.try(() => {
View app.js
// file: serial.js
const SerialPort = require('serialport')
module.exports = function() {
const port = SerialPort('path/to/serial/port')
const e = new events.EventEmitter()
// listen for incoming serial data
port.on('data', function (data) {
View drawchart.js
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',
View gist:cbe6b09618c951765c05154fa5ccba13
/// 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) => {
@joepie91
joepie91 / .js
Last active Apr 28, 2017 — forked from lohfu/.js
View .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 {
View .js
var resultTemplate = "" +
" <ul class='searchList'>" +
" <% _.each(paymentActions,function(paymentActivity){ %>" +
" <li><span class='amount visible-phone'>-<%= paymentActivity.grossAmount %></span>" +
" </li>" +
" <% }); %>" +
" </ul>";
var template = _.template(resultTemplate, {
View RethinkDbConnection.js
var Promise = require('bluebird');
var rdb = Promise.promisify(require('rethinkdb'));
module.exports = function(config) {
return {
connectToDb: function(){
return Promise.try(() => {
return rdb.connect(config);
});
}
View gist:06ba1b51759728b8eaa5633b3cf8479c
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/*/", {})
View db-to-files.js
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] + '')
}))
})
View 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']),
You can’t perform that action at this time.