Skip to content

Instantly share code, notes, and snippets.

View kevboutin's full-sized avatar

Kevin Boutin kevboutin

View GitHub Profile
@kevboutin
kevboutin / hapi-post-put.js
Created February 26, 2016 22:46
Shows POST and PUT examples in hapi within Node.
'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'],
@kevboutin
kevboutin / hapi-views.js
Created February 26, 2016 22:55
Shows how to use view templating with hapi within node.
'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({
@kevboutin
kevboutin / hapi-static-files.js
Created February 26, 2016 23:05
Shows how to serve up static files using hapi within node.
'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'), () => {
@kevboutin
kevboutin / hapi-lifecycle-events.js
Created February 26, 2016 21:34
Shows how to use hapi to extend lifecycle events within node.
'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');
@kevboutin
kevboutin / .eslintrc
Created March 29, 2018 19:17
eslint configuration
{
"extends": "google",
"plugins": [],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"settings": {
"import/core-modules": [
"aws-sdk"
@kevboutin
kevboutin / scheduleEvent.js
Last active March 6, 2020 05:08
Calculate available time windows
// Designed for Azure functions
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
const scheduledEvents = [];
//Add all scheduled events into an array
req.body.forEach(function (calendar) {
calendar.items.forEach(function (items) {
scheduledEvents.push({
start: new Date(items['start']).toLocaleTimeString('en-US', { hour12: false }),
@kevboutin
kevboutin / sendMessages.js
Created March 10, 2020 20:45
Sending messages to a queue using Azure Service Bus
const { ServiceBusClient } = require('@azure/service-bus');
const moment = require('moment');
const connectionString = process.env.SB_CONNECTION;
const queueName = process.env.SB_QUEUE_NAME;
const listOfScientists = [
{
id: 1,
name: "Einstein",
@kevboutin
kevboutin / processMessages.js
Created March 10, 2020 20:47
Processing messages from a queue using Azure Service Bus
const { ServiceBusClient } = require('@azure/service-bus');
const moment = require('moment');
const connectionString = process.env.SB_CONNECTION;
const queueName = process.env.SB_QUEUE_NAME;
/**
* Processing messages from service bus queue.
*
* @param {object} context The context.
@kevboutin
kevboutin / bash-async.sh
Created March 29, 2020 22:26
This demonstrates how a bash script can invoke a child process to do some work asynchronously and monitor for finish
#!/bin/bash
mycommand &
child_pid=$!
while kill -0 $child_pid >/dev/null 2>&1; do
echo "Child process is still running"
sleep 1
done
@kevboutin
kevboutin / Solarin.bgptheme
Last active September 16, 2020 23:57
Solarin theme for git prompt (brew install bash-git-prompt)
# This is a custom theme template for gitprompt.sh and is used here: https://github.com/magicmonty/bash-git-prompt
# Install this package using: brew install bash-git-prompt
# Copy this file to $(brew --prefix)/opt/bash-git-prompt/share/themes/
# Add the following code to your ~/.bash_profile
# if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
# __GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
# GIT_PROMPT_ONLY_IN_REPO=1
# GIT_PROMPT_THEME=Solarin
# source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
# fi