Skip to content

Instantly share code, notes, and snippets.

View bmorrisondev's full-sized avatar

Brian Morrison II bmorrisondev

View GitHub Profile
@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));
}
@bmorrisondev
bmorrisondev / AllPropertiesNullOrEmpty.cs
Created November 4, 2019 16:20
Returns false if all members of an object are null
/// <summary>
/// Iterates through an object's properties and checks of any of them are null.
/// </summary>
public static bool AllPropertiesNullOrEmpty(this object theObject)
{
var propertiesNotNull = theObject.GetType()
.GetProperties()
.Select(pi => pi.GetValue(theObject))
.Any(value => value != null);
@bmorrisondev
bmorrisondev / Set-NamecheapDdnsRecord.ps1
Last active June 25, 2025 16:40
Update a Dynamic DNS Record in Namecheap using PowerShell
function Set-NamecheapDdnsRecord {
<#
.SYNOPSIS
Update the IP address of a Dynamic DNS record in Namecheap.
.EXAMPLE
PS C:\> Set-NamecheapDdnsRecord -HostRecord www -Domain brianmorrison.me -ApiKey 12345678abcd -Ip 123.234.123.234
Updates the record for www.brianmorrison.me to 123.234.123.234
.NOTES
Author: Brian Morrison II
Date: 4/10/2019
@bmorrisondev
bmorrisondev / Remove-AllMsolLicenses.ps1
Created February 8, 2019 21:02
Remove all licenses from a user in Office 365 using PowerShell
$MsolUser = Get-MsolUser -UserPrincipalName $Username
$AssignedLicenses = $MsolUser.licenses.AccountSkuId
foreach($License in $AssignedLicenses) {
Set-MsolUserLicense -UserPrincipalName $Username -RemoveLicenses $License
}
@bmorrisondev
bmorrisondev / dbhelper.js
Created January 24, 2019 14:47
A mongoose connection helper script that builds a connection string from environment variables
// env.test file:
// DB_HOST="localhost"
// DB_PORT="27017"
// DB_NAME="dbname"
// DB_USER="dbusername"
// DB_PASS="dbpassword"
require('custom-env').env(true)
const mongoose = require('mongoose')
@bmorrisondev
bmorrisondev / sampleDynamooseModel.js
Created January 23, 2019 14:51
A sample user model using Dynamoose, an ORM for AWS DynamoDB with a similar API to Mongoose
const dynamoose = require('dynamoose');
let configUpdates = {
region: "us-east-1",
accessKeyId: 'key123',
secretAccessKey: 'secret123'
}
dynamoose.AWS.config.update(configUpdates);
@bmorrisondev
bmorrisondev / test-spec.json
Created January 21, 2019 18:25
NPM command to start nodemon & mocha, and run any tests with the 'spec.js' suffix inside the src folder of a node project.
{
"test-spec": "nodemon --exec \"mocha -c --reporter=spec --recursive \"src/**/*.spec.js\"\""
}
@bmorrisondev
bmorrisondev / VuetifyAppTemplate.vue
Created January 21, 2019 17:17
A VueJS + Vuetify app template with toolbar, navigation drawer, and router configuration.
<template>
<v-app>
<v-navigation-drawer :value="isDrawerVisible" app clipped>
<v-list class="pt-0">
<v-list-tile @click="">
<v-list-tile-action>
<v-icon>dashboard</v-icon>
</v-list-tile-action>
<v-list-tile-content>