View Array.prototype.isPresent.js
/** | |
* Proper (according to me) "isPresent" method for arrays in javascript. This allows the use of callback on testing. | |
* An empty callback is like using '==' as test. | |
* @param item item to find | |
* @param cpf -optional- test callback function: function(a,b) where a is the element to find and b the element tested | |
* from the array. | |
* @returns {boolean} true if at least one element is present in the array equals to the one to find according to the | |
* compare function. | |
* @author Vladimir de Turckheim | |
*/ |
View leanhub-intro-package.json
{ | |
"name": "intro", | |
"version": "0.1.0", | |
"description": "Short introduction to Lab and Hapi", | |
"main": "index.js", | |
"scripts": { | |
"test": "lab -cLv -t 100", | |
"start": "node ./index" | |
}, |
View leanhub-intro-index.js
'use strict'; | |
// Hapi framework | |
const Hapi = require('hapi'); | |
// our plugin in the file api.js | |
const ApiPlugin = require('./api'); | |
// We create a server object | |
const server = new Hapi.Server(); | |
// Server will listen on port 8080 | |
server.connection({ |
View leanhub-intro-test.js
'use strict'; | |
// Hapi framework | |
const Hapi = require('hapi'); | |
// our plugin in the file api.js | |
const ApiPlugin = require('../api'); | |
// assertion library | |
const Code = require('code'); | |
// Lab test runner | |
const Lab = require('lab'); |
View rethink-chat-rooms-model.js
const Thinky = require('thinky')(); | |
const Type = Thinky.type; | |
// create the model for messages | |
const Message = Thinky.createModel('Message', { | |
username: Type.string(), | |
message: Type.string() | |
}); |
View susie-rethink-server.js
const Hapi = require('hapi'); | |
const Path = require('path'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 4000 }); | |
server.register([require('inert'), require('susie')], err => { | |
if (err) { |
View susie-rethink-post.js
{ | |
config: { | |
validate: { | |
payload: { | |
message: Joi.string(), | |
username: Joi.string() | |
} | |
} | |
}, | |
method: 'POST', |
View susie-rethink-get.js
{ | |
method: 'GET', | |
path: '/chat-feed', | |
handler: function (request, reply) { | |
Message | |
.changes() | |
.run() | |
.then((feed) => { | |
feed.each((err, doc) => { |
View rethink-chat-rooms-client.js
var evtSource = new EventSource("/chat-feed"); | |
evtSource.addEventListener("message", e => { | |
// e.data == the message that has been received | |
}); |
View nest-1-index.js
'use strict'; | |
const Mongoose = require('mongoose'); | |
const validateOptions = require('./lib').validateOptions; | |
const builConnectionString = require('./lib').builConnectionString; | |
module.exports.register = function (server, options, next) { | |
const validation = validateOptions(options); |
OlderNewer