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 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);
'use strict';
const Joi = require('joi'); // object schema validation tool
const optionsSchema = Joi.object().keys({
// a string representing a hostname or an ip
host: Joi.alternatives().try(Joi.string().hostname(), Joi.string().ip()).default('127.0.0.1'),
// a number in the allowed TCP port range, default to default mongodb port
port: Joi.number().min(1).max(65535).default(27017),
// If no database name, we create an random one that look like 'database_abcd' with a,b,c,d random numbers
database: Joi.string().min(1).replace(' ', '_').default(`database_${Math.floor(Math.random() * 10000)}`),