Skip to content

Instantly share code, notes, and snippets.

View bmorrisondev's full-sized avatar

Brian Morrison II bmorrisondev

View GitHub Profile
@bmorrisondev
bmorrisondev / azure-pipelines.yml
Created March 26, 2020 21:54
An #Azure DevOps build pipeline for #GatsbyJS (or other #nodejs) projects
# Whenever a new commit is added to 'master', this build will trigger.
trigger:
- master
# Use an Azure VM with Ubuntu to build this poroject.
pool:
vmImage: 'ubuntu-latest'
# Our first step preps the VM to build our project.
steps:
@bmorrisondev
bmorrisondev / profile.ps1
Created March 26, 2020 14:15
My profile.ps1 - I use this to customize my #PowerShell session
# Stored in "~/Documents/Windows PowerShell". Any commands in this file will be executed when a session is launched.
function prompt {
"PS ($(Split-Path -leaf -path (Get-Location)))> "
}
@bmorrisondev
bmorrisondev / Check-IISSiteExists.ps1
Created March 20, 2020 21:54
Check if an IIS Site exists using PowerShell
if((Get-IISSite -Name "IisSiteName") -eq $true) {
# The site exists, do something
} else {
# The site doesnt exist.
}
@bmorrisondev
bmorrisondev / docker-rebuild.sh
Created March 19, 2020 15:48
My docker-compose script I use in my devops pipelines
#!/bin/bash
docker-compose down -v # Takes down the docker containers including named volumes
docker-compose build # Build the image
docker-compose up -d # Start the container
@bmorrisondev
bmorrisondev / simpleDiscordBot.js
Created March 6, 2020 16:34
A simple Discord bot shell, built using the discord.js library
const Discord = require('discord.js');
const client = new Discord.Client();
// When the bot is ready, log out a message.
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
// When a message is received that starts with 'hello', respond with 'world!'
// This is where you would handle various commands that your bot responds to.
@bmorrisondev
bmorrisondev / HttpContextFaker.cs
Created March 6, 2020 14:52
A simple method to mock out an HttpContext using NSubstitute for unit testing API Controllers in C#
using System;
using NSubstitute;
using Stage.Data;
using System.IO;
using System.Linq;
using System.Security.Principal;
using System.Web;
namespace FakerTools
{
@bmorrisondev
bmorrisondev / cognitoMw.js
Created March 2, 2020 15:07
An express.js authentication middleware using AWS Cognito & the CognitoExpress package
const CognitoExpress = require('cognito-express')
exports.validateToken = (req, res, next) => {
if (req.headers && req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
let cognitoConfig = {
region: process.env.COGNITO_REGION,
cognitoUserPoolId: process.env.COGNITO_USERPOOL_ID,
tokenUse: 'id',
tokenExpiration: 3600000
}
@bmorrisondev
bmorrisondev / asyncForEach.js
Created February 24, 2020 19:25
An async version of an array forEach loop in JavaScript
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
// Usage:
// await asyncForEach(myArray, async (element) => {
// await someLongRunningOperation(element);
// await someOtherLongRunningOp(element);
@bmorrisondev
bmorrisondev / rng.js
Created February 17, 2020 15:35
A simple psuedo-random number generator. Pass it a min and max number and it will return a random number in that range.
function rng (min, max) {
var num = Math.random() * (max - min) + min;
return Math.floor(num)
}
@bmorrisondev
bmorrisondev / sleep.js
Created February 17, 2020 15:34
An awaited version of setTimeout to pause script execution
async function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}