Skip to content

Instantly share code, notes, and snippets.

View vdeturckheim's full-sized avatar
😇
Living the JS life

Vladimir de Turckheim vdeturckheim

😇
Living the JS life
View GitHub Profile
@vdeturckheim
vdeturckheim / Array.prototype.isPresent.js
Last active October 28, 2015 20:31
Proper (according to me) "contains" method for arrays in javascript. This allows the use of callback on testing.
/**
* 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
*/
{
"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"
},
'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({
'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');
const Thinky = require('thinky')();
const Type = Thinky.type;
// create the model for messages
const Message = Thinky.createModel('Message', {
username: Type.string(),
message: Type.string()
});
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) {
{
config: {
validate: {
payload: {
message: Joi.string(),
username: Joi.string()
}
}
},
method: 'POST',
{
method: 'GET',
path: '/chat-feed',
handler: function (request, reply) {
Message
.changes()
.run()
.then((feed) => {
feed.each((err, doc) => {
var evtSource = new EventSource("/chat-feed");
evtSource.addEventListener("message", e => {
// e.data == the message that has been received
});
'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);