This file contains hidden or 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
// https://www.blockspring.com/blog/serverless-slack-bots | |
blockspring = require('blockspring'); | |
var webhook = function(team_domain, service_id, token, user_name, team_id, user_id, channel_id, timestamp, channel_name, text, trigger_word, raw_text) { | |
// Basic bot will just echo back the message | |
response = ["*", user_name, "* said _", text, "_"].join('') | |
return { |
This file contains hidden or 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 async = function (input) { | |
return new Promise(function (resolve, reject) { | |
var data = input + ' Whatever.'; | |
// call the async process here | |
setTimeout(function(){ | |
// send the result when it arrives | |
resolve(data); | |
}, 100); |
This file contains hidden or 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 Q = require('q'); | |
var async = function (prefix) { | |
// create a promise wrapper | |
var hold = Q.defer(); | |
var success = function () { | |
var data = prefix + "SOLVED!"; | |
// by calling 'resolve', the next steps in the | |
// 'then' handler (e.g. 'console.log' below) | |
// will be executed with 'data' passed in |
This file contains hidden or 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
code { | |
padding: 2px 3px; | |
color: #d14; | |
background-color: #f7f7f9; | |
border: 1px solid #e1e1e8; | |
white-space: nowrap; | |
} |
This file contains hidden or 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
# Methods for cycling through the models in a Backbone Collection | |
# Usage: | |
# | |
# c = new MyCollection([...]) | |
# nextModel = c.modelAfter(myModel) | |
# myModel == c.modelBefore(nextModel) | |
# # true | |
# | |
class MyCollection extends Backbone.Collection |
This file contains hidden or 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
passport.use(new LocalStrategy( // a new Local instance | |
function(username, password, done) { // passing in a function | |
User.findOne({ username: username }, function (err, user) { // Mongo interface | |
if (err) { return done(err); } // generic error | |
if (!user) { return done(null, false); } // user not found | |
if (!user.verifyPassword(password)) { return done(null, false); } // wrong password | |
return done(null, user); // authenticated, returns 'user' | |
}); | |
} | |
)); |
This file contains hidden or 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
function powerset(alphabet) { | |
var p = [[]]; | |
for (var i=0; i < alphabet.length; i++) { | |
// here the value of len is set at the beginning | |
for (var j = 0, l = p.length; j < l; j++) { | |
p.push(p[j].concat(alphabet[i])); | |
// inspector | |
console.log(p); | |
} | |
} |
This file contains hidden or 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 data = ''; | |
request.on('data', function (partial) { | |
data += partial; | |
}); | |
request.on('end', function () { | |
data = JSON.parse(data); | |
}); |
This file contains hidden or 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
function permutator(inputArr) { | |
// the output matrix of all permutations | |
var results = []; | |
// takes the array of character set | |
function permute(columnOptions, path) { | |
var place, newPath, path = path || []; | |
// for a given row | |
// go through the options for "which column" |
This file contains hidden or 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 hue, cell, | |
grades = 100, | |
query = ''; | |
for (var i = 0; i < grades; i++) { | |
hue = i * 360 / grades | |
query = '<div style="float:left;' + | |
'width:' + (100/grades) + '%;' + | |
'height:20px;' + | |
'background-color: hsl(' + hue + ', 100%, 75%);"></div>' |