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
/** | |
* VIN decoder. | |
* | |
* kevinboutin on 3/11/18. | |
* | |
* My VIN for testing is WBA3A5G59DNP26082 so use the following command to invoke: | |
* node vindecoder WBA3A5G59DNP26082 | |
* | |
* Examples: | |
* KM8JM12D56U303366 |
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
'use strict'; | |
const Hapi = require('hapi'); | |
const Path = require('path'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 8000 }); | |
// test by using this on browser: | |
// http://localhost:8000/hapi.png | |
server.register(require('inert'), () => { |
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
'use strict'; | |
const Hapi = require('hapi'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 8000 }); | |
// test by using this on browser: | |
// http://localhost:8000/kevin | |
server.register(require('vision'), () => { | |
server.views({ |
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
'use strict'; | |
const Hapi = require('hapi'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 8000 }); | |
// test by using this on command line: | |
// http -v --form POST localhost:8000 fname=Kevin lname=Boutin | |
server.route({ | |
method: ['POST', 'PUT'], |
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
'use strict'; | |
const Hapi = require('hapi'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 8000 }); | |
// test by using this on command line: | |
// http GET localhost:8000 | |
server.ext('onRequest', (request, response) => { | |
console.log('onRequest'); |
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
'use strict'; | |
const Hapi = require('hapi'); | |
const Boom = require('boom'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 8000 }); | |
// test by using this in browser: | |
// http://localhost:8000 | |
server.register(require('vision'), () => { |
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
'use strict'; | |
const Hapi = require('hapi'); | |
const Joi = require('joi'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 8000 }); | |
// test by calling: | |
// http POST localhost:8000/user/123?id=456 | |
// or for validation failure testing, call: | |
// http POST localhost:8000/user/123?id=foo |
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
// simple implementation of a thread pool | |
function Pool(size) { | |
var _this = this; | |
// set some defaults | |
this.taskQueue = []; | |
this.workerQueue = []; | |
this.poolSize = size; | |
this.addWorkerTask = function(workerTask) { |
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 calculateDistance(lat1, lon1, lat2, lon2) { | |
var R = 6371; // km | |
var dLat = (lat2 - lat1).toRad(); | |
var dLon = (lon2 - lon1).toRad(); | |
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + | |
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * | |
Math.sin(dLon / 2) * Math.sin(dLon / 2); | |
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | |
var d = R * c; | |
return d; |