Skip to content

Instantly share code, notes, and snippets.

View chris-burkhardt's full-sized avatar
🏠
Working from home

Chris B chris-burkhardt

🏠
Working from home
View GitHub Profile
@chris-burkhardt
chris-burkhardt / createErrorBody.js
Last active October 31, 2018 00:42
JEST unit testing example for fs.readFile on Lambda handler
module.exports = (data) => {
const {
message, path, reason, requestId, code,
} = data;
return {
message,
error: {
path,
reason,
@chris-burkhardt
chris-burkhardt / nodejs-csv-export.js
Last active October 28, 2021 06:31
Export CSV File - React/Javascript
import { zipObject } from 'lodash';
export const CSVExport = csvData => {
const { items, headers, filename } = csvData;
// use headers if available, if not, use the key names for headers
// updated to create same type with zipped object
const headerKeys = Object.keys(items[0]);
const rowHeader = headers || zipObject(headerKeys, headerKeys);
@chris-burkhardt
chris-burkhardt / DockerCommandCheatSheet.txt
Last active May 3, 2020 23:25
Docker Command Cheat Sheet
Most frequently used Docker commands:
-----------------------------------------------------------------
ALL CONTAINERS - delete
-----------------------------------------------------------------
## Main ways to remove all images/containers
docker rm $(docker ps -a -q)
docker rmi -f $(docker images -q)
## Delete all running and stopped containers
docker container rm -f $(docker ps -aq)
@chris-burkhardt
chris-burkhardt / nodejs-remove-array-duplicates-using-set().txt
Last active July 15, 2021 03:22
Remove Array Duplicates with new Set() in JS
const testArr1 = ['pig', 'fox', 'zebra']
const testArr2 = ['ferrari', 'fox', 'pig', 'maserati']
// each value of a Set needs to be unique, so combining arrays that have
// duplicate entries into a Set will auto-remove exact matches
const removeArrayDuplicates = (first, second) => {
const combinedArrays = [...first, ...second];
const arraySet = [...new Set(combinedArrays)]
return arraySet
}
const missingIDs = ['111111', '2222222'];
const existingUsers = [{
"System": "Test",
"Company Name": "Test Company",
"UU_UserName": "testuser",
"Active": 0,
"Ceased": 0,
"Unused": 4,
"UBO Surname1": "Test",
"UBO Firstname1": "Test",
@chris-burkhardt
chris-burkhardt / nodejs-crypto-encryption-service.txt
Last active July 15, 2021 03:23
JS Crypto Encryption Service
'use strict'
// use the following online tool for encryption and decryption testing
// https://www.javainuse.com/aesgenerator
const CryptoJS = require('crypto-js');
class EncryptionService {
/**
* Encrypts a plain-text string using AES-256 cipher with the following settings
* Mode: CBC, Key Size: 256, Output Format: Base64
@chris-burkhardt
chris-burkhardt / NodeJS-base64encodedimage-to-S3.txt
Last active October 27, 2021 03:39
JS Upload Base64 Encoded Image to AWS S3 Bucket
'use strict'
const AWS = require("aws-sdk");
const S3 = new AWS.S3();
module.exports = async function (inputs, context) {
// example encoded images can be created here: https://www.base64-image.de/
// upload image to S3
try {
const s3BucketLocation = await uploadImageToS3(inputs.DeviceDiagnosticRequest.IMEIImage, "IMEIImage", inputs, context);
} catch (error) {
@chris-burkhardt
chris-burkhardt / s3BucketCleaner.yml
Created June 28, 2021 03:01
Github Actions Teardown Serverless Stack - Empty S3 Buckets
name: TeardownBranch
'on': [delete]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
@chris-burkhardt
chris-burkhardt / nodejs12-sort.txt
Last active July 15, 2021 03:15
NodeJS 12 sort() working
var existingOrder = [{
CreatedDate: "2021-07-12T03:49:57.000Z"
},
{
CreatedDate: "2021-07-13T09:25:23.000Z"
},
{
CreatedDate: "2021-07-18T04:52:41.000Z"
},
{
@chris-burkhardt
chris-burkhardt / Nodejs-quicksort-descending
Created July 15, 2021 03:19
NodeJS QuickSort Descending
var existingOrder = [{
CreatedDate: "2021-07-12T03:49:57.000Z"
},
{
CreatedDate: "2021-07-13T09:25:23.000Z"
},
{
CreatedDate: "2021-07-18T04:52:41.000Z"
},
{