Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Boutin kevboutin

View GitHub Profile
@kevboutin
kevboutin / clonetest.ts
Last active Mar 22, 2021
cloning objects in javascript
View clonetest.ts
function cloneObject(obj: any): any {
switch (obj["constructor"]) {
case Date: return new Date(obj);
case Object: return Object.keys(obj).reduce<{ [key: string]: any }>((newObj, key) => (newObj[key] = cloneObject(obj[key]), newObj), {});
case Array: return obj.map(cloneObject);
}
return obj;
}
// Test
View vindecoder.js
/**
* 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
@kevboutin
kevboutin / Solarin.bgptheme
Last active Sep 16, 2020
Solarin theme for git prompt (brew install bash-git-prompt)
View Solarin.bgptheme
# 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
@kevboutin
kevboutin / bash-async.sh
Created Mar 29, 2020
This demonstrates how a bash script can invoke a child process to do some work asynchronously and monitor for finish
View bash-async.sh
#!/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 / processMessages.js
Created Mar 10, 2020
Processing messages from a queue using Azure Service Bus
View processMessages.js
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 / sendMessages.js
Created Mar 10, 2020
Sending messages to a queue using Azure Service Bus
View sendMessages.js
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 / scheduleEvent.js
Last active Mar 6, 2020
Calculate available time windows
View scheduleEvent.js
// 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 / .eslintrc
Created Mar 29, 2018
eslint configuration
View .eslintrc
{
"extends": "google",
"plugins": [],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"settings": {
"import/core-modules": [
"aws-sdk"
@kevboutin
kevboutin / hapi-lifecycle-events.js
Created Feb 26, 2016
Shows how to use hapi to extend lifecycle events within node.
View hapi-lifecycle-events.js
'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 / hapi-static-files.js
Created Feb 26, 2016
Shows how to serve up static files using hapi within node.
View hapi-static-files.js
'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'), () => {