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
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
// 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 handlers = { | |
onConnect: function () { | |
console.log('Connected!'); | |
}, | |
onMessage: function () { | |
console.log('Message!'); | |
} | |
}; | |
var map = { |
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
module.exports = function () { | |
var c = []; | |
return { | |
push: function (item) { | |
c.push(item); | |
}, | |
print: function () { | |
console.log(c); | |
} | |
}; |
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 wrap (text, limit) { | |
if (text.length > limit) { | |
// find the last space within limit | |
var edge = text.slice(0, limit).lastIndexOf(' '); | |
if (edge > 0) { | |
var line = text.slice(0, edge); | |
var remainder = text.slice(edge + 1); | |
return line + '\n' + wrap(remainder, limit); | |
} | |
} |
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 solution(A) { | |
var n = A.length - 1, | |
lSum = 0, | |
rSum = 0, | |
diffs = new Array(n), | |
diff, | |
min = Infinity; | |
for (var p = 0; p < n; p++) { | |
lSum += A[p]; | |
rSum += A[n - 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 num = "27019", | |
base = 16, | |
output = ''; | |
while (num > 0) { | |
digit = num % base; | |
num = (num - digit) / base; | |
if (digit > 9) { | |
digit = String.fromCharCode(digit + 55); | |
} |
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 request = require('request'); | |
var Promise = require('bluebird'); | |
var authorize = require('./session-keys'); | |
var BASE_URL = 'http://challenge.shopcurbside.com/'; | |
var fetch = function(resource, session) { | |
var options = { | |
url: BASE_URL + resource, | |
headers: { 'Session': session } |
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
// initiating a worker | |
var karl = new Worker("task.js"); | |
// receiving messages | |
karl.onmessage = function(event){ | |
console.log(event.data); | |
}; | |
// in the end | |
karl.terminate(); |