Skip to content

Instantly share code, notes, and snippets.

View krohne's full-sized avatar

Gregory Krohne krohne

  • Atlanta, Georgia, USA
View GitHub Profile
@krohne
krohne / get-form-validation-errors.ts
Last active October 11, 2023 14:13 — forked from JohannesHoppe/get-form-validation-errors.ts
Get all validation errors for Angular FormGroup, FormRecord, or FormArray
import {
FormGroup,
FormRecord,
FormArray,
ValidationErrors
} from '@angular/forms';
export function getFormValidationErrors(form: FormGroup|FormRecord|FormArray, path ?: string = '$') {
const result = [];
@krohne
krohne / MutiString.pipe.ts
Created October 25, 2021 16:28
Angular pipe to trim and contatenate strings with space between. Mostly for formatting names, which may include null/undefined values, or leading/trailing spaces
// MultiString.pipe.ts
import {
Pipe,
PipeTransform
} from '@angular/core';
@Pipe({ name: 'multiString' })
export class MultiStringPipe implements PipeTransform {
function transform(...values: string[]): string {
return values
@krohne
krohne / unique_objects.js
Created January 9, 2020 18:00
Eliminate duplicate array objects
const arr = [
{ id: 1, val: 'a' },
{ id: 2, val: 'b' },
{ id: 1, val: 'a' },
{ id: 1, val: 'c' }
];
const uni = arr
.reduce( ( unique, item ) =>
unique.some( existing =>
@krohne
krohne / kill_sophos.sh
Created January 28, 2019 15:29
Remove Sophos from Mac without tamper protection password
#!/bin/bash
# https://gist.github.com/lukebussey/70fe3b245c7b55fa41300670d2698e54#gistcomment-2636296
sudo rm -R /Library/Sophos\ Anti-Virus/
sudo rm -R /Library/Application\ Support/Sophos/
sudo rm -R /Library/Preferences/com.sophos.*
sudo rm /Library/LaunchDaemons/com.sophos.*
sudo rm /Library/LaunchAgents/com.sophos.*
sudo rm -R /Library/Extensions/Sophos*
sudo rm -R /Library/Caches/com.sophos.*
~/Applications/Remove\ Sophos\ Endpoint
@krohne
krohne / update_ip.sh
Last active January 28, 2019 19:05
Update ~/.ssh/config IP addresses for preprod and production
#!/bin/bash
# production|preprod
command -v jq >/dev/null 2>&1 || { echo >&2 "I require jq but it's not installed. Try 'brew install jq' Aborting."; exit 1; }
command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl but it's not installed. Try 'brew install curl' Aborting."; exit 1; }
command -v perl >/dev/null 2>&1 || { echo >&2 "I require perl but it's not installed. Try 'brew install perl' Aborting."; exit 1; }
command -v tr >/dev/null 2>&1 || { echo >&2 "I require tr but it's not installed.' Aborting."; exit 1; }
case $1 in
production|preprod)
platform=$1
;;
@krohne
krohne / copy_to_platform.sh
Last active January 11, 2019 20:20
Copy source file to remote platform docker container. If running from the repository path, container is optional
#!/bin/bash
# Your bastion username should be in ~/.ssh/config
# platform path [container]
# preprod /routes/genesys/router.js tripnotificationagent
export platform=$1
export repo=$(basename "$PWD")
export filename=$2
export container=$3
if [ -z ${container} ]; then export container=$(grep '"name":\s*"\w*",' $PWD/package.json | awk -F '"' '{ print $4 }'); fi
export service="rmpay_${container}_1"
@krohne
krohne / restart_platform_container.sh
Last active January 11, 2019 20:21
Restart remote platform container, usually because a source file or logging level has been changed
#!/bin/bash
# Your bastion username should be in ~/.ssh/config
# platform [container]
# preprod tripnotificationagent
export platform=$1
export container=$2
if [ -z ${container} ]; then export container=$(grep '"name":\s*"\w*",' $PWD/package.json | awk -F '"' '{ print $4 }'); fi
echo "Container: $container"
if [ -z ${container} ];
then
@krohne
krohne / set_remote_logging.sh
Last active January 11, 2019 20:21
Turn logging level up or down on remote platform
#!/bin/bash
# Your bastion username should be in ~/.ssh/config
# on|off platform [container]
# on preprod tripnotificationagent
export setting=$1
export platform=$2
export container=$3
if [ -z ${container} ]; then export container=$(grep '"name":\s*"\w*",' $PWD/package.json | awk -F '"' '{ print $4 }'); fi
export service="rmpay_${container}_1"
case $setting in
@krohne
krohne / update_repos_routematch.sh
Last active January 18, 2019 15:37
Update local Git repositories in parallel, 1 thread per core
#!/bin/bash
export GIT_ROOT=/Volumes/Routematch/Git
doit() {
cd $GIT_ROOT/$1
# What branch is this repo on?
# If master branch, checkout package.json and pull latest updates
# If .nvmrc exists, use specified version, else use node version 4
# Update dependencies
@krohne
krohne / decode_jwt.js
Created May 21, 2018 15:42
Decode Base64 JWT from login request in Postman
const jsonData = JSON.parse(responseBody);
const payload = jsonData.id_token.split('.')[1]; // Assuming the JWT is in id_token
const parsed = JSON.parse(atob(payload));
pm.environment.set('user_id', parsed.user_id); // Assuming user_id is in the payload