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 stepOne = function () { | |
return Promise.resolve({ some: 'result' }); | |
} | |
const stepTwo = function (prevResult) { | |
prevResult.more = 'results'; | |
return prevResult; | |
} | |
stepOne().then((result) => { |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Subnets</key> | |
<array> | |
<dict> | |
<key>_creator</key> | |
<string>com.apple.NetworkSharing</string> | |
<key>allocate</key> |
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
var handler = function (request, reply) { | |
doSomethingWithAPromise().then(function (result) { | |
if (!result) { | |
return reply.view('error'); | |
} | |
return reply.view('success'); | |
}).catch(function (err) { |
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
server.ext('onPreResponse', function (request, reply) { | |
if (request.response.variety === 'view') { | |
request.response.source.context.i18n = yourfunc; | |
} | |
reply.continue(); | |
}); |
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
var Hapi = require('hapi'); | |
var server = new Hapi.Server(); | |
server.connection(); | |
server.register([{ | |
register: require('vision') | |
}, { | |
register: require('hapi18n') | |
}], function (err) { |
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
var handler = function (request, reply) { | |
var result = getAModel().then(function (model) { | |
if (!model) { | |
throw Boom.notFound(); | |
} | |
return request.generateResponse(model.asJSON()).code(204); | |
}); |
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
var Promise = require('bluebird'); | |
module.exports.request = function (options, callback) { | |
return new Promise(function (resolve, reject) { | |
request(options, function (err, res, body) { | |
if (err) { | |
return reject(err); | |
} | |
resolve(body.results); | |
}); |
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
var Joi = require('joi'); | |
var Hapi = require('hapi'); | |
var server = new Hapi.Server(); | |
server.connection(); | |
var schema = Joi.object({ | |
query: Joi.string().required(), | |
types: Joi.array().items( | |
Joi.string().valid('accounts'), | |
Joi.string().valid('addresses'), |
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
var schema = Joi.object({ | |
field1: Joi.string().when('field2', { is: Joi.array().items(Joi.string().valid('magic_string').required()), then: Joi.required() }), | |
field2: Joi.array() | |
}) |
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 { EventEmitter } from 'events'; | |
class Spit extends EventEmitter { | |
addListener(event, fn) { | |
this._events[event] = this._events[event] || []; | |
this.emit('newListener', event, typeof fn.listener === 'function' ? fn.listener : fn); | |
this._events[event].push(fn); | |
return this; |