This file contains 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
findSomething() | |
.then((something) => transformSomething(something)) | |
.then((transformed) => validateTransformed(transformed)) | |
.then((validated) => console.log('data is valid:', validated) | |
.catch((error) => console.error(new Error(error)) |
This file contains 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
const validateTransformation = sequentialCallback( | |
transformSomething, | |
validateSomething | |
) | |
const something = { foo: 'bar' } | |
validateTransformation(something, (error, validated) => { | |
if (error) { | |
console.error(new Error(error)) |
This file contains 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
const validateTransformation = sequentialCallback( | |
transformSomething, | |
validateTransformed, | |
(validated, callback) => callback(null, validated, 'data is valid:') | |
) | |
validateTransformation({ foo: 'bar' }, (error, validated, label) => { | |
if (error) { | |
console.error(new Error(error)) | |
} else { |
This file contains 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
const users = { | |
1: { name: 'bob' }, | |
2: { name: 'sally' } | |
} | |
const posts = [ | |
{ author: 'sally', title: 'Hello World' }, | |
{ author: 'bob', title: 'How to do stuff' } | |
] |
This file contains 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 sequentialCallback (...fns) { | |
return (...args) => { | |
const done = args.pop() | |
const next = (error, ...args) => { | |
if (error) return done(error) | |
if (fns.length) { | |
const fn = fns.shift() | |
return fn(...args, next) | |
} | |
return done(null, ...args) |
This file contains 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 setArity (arity, fn) { | |
if (typeof setArity.cache === 'undefined') { | |
setArity.cache = {} | |
} | |
if (typeof setArity.cache[arity] === 'undefined') { | |
setArity.cache[arity] = (fn) => { | |
switch (arity) { | |
case 0: return function () { return fn.apply(this, arguments) } | |
case 1: return function (a) { return fn.apply(this, arguments) } | |
case 2: return function (a, b) { return fn.apply(this, arguments) } |
This file contains 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
// this file is just so I can reference the idea behind placeholders - if you want a maintained version, check out: | |
// - https://github.com/thisables/curry | |
// - http://ramdajs.com | |
const __ = Symbol | |
const ARITIES = {} | |
const setArity = (arity, fn) => { | |
if (!ARITIES[arity]) { |
This file contains 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
findSomething((error, something) => { | |
if (error) { | |
throw new Error(error) | |
} | |
transformSomething(something, (error, transformed) => { | |
if (error) { | |
throw new Error(error) | |
} | |
validateTransformed(transformed, (error, validated) => { | |
if (error) { |
This file contains 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
import fetch, { | |
Response } from 'node-fetch'; | |
import qs from 'querystring'; | |
import WebSocket from 'ws'; | |
class SimpleSlack { | |
baseURL = 'https://slack.com/api/'; | |
eventListeners = {}; | |
connection = null; |
This file contains 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
// Vertical Rhythm ported from SASS/Compass | |
// Works exactly as before, with four exceptions: | |
// 1. rhythm() is a mixin, $rhythm() is a function. Stylus doesn't differentiate between same-name mixins and functions | |
// 2. All of the variables you're used to lack the dollar sign ($) prepend. | |
// 3. debug-vertical-alignment uses a temporary online image solution via http://basehold.it | |
// 4. There is no h-borders alias. Use horizonatal-borders instead. | |
// The base font size. | |
base-font-size ?= 16px |