Skip to content

Instantly share code, notes, and snippets.

View wesleylhandy's full-sized avatar

Wesley Handy wesleylhandy

View GitHub Profile
@wesleylhandy
wesleylhandy / deep-equal.js
Last active September 5, 2021 01:43
Recursive Method to determine if two Object literals are deeply equal.
/**
* Recursive function that compares two deeply nested objects to determine if they are identical in their structure and values.
*
* @param {*} obj1
* @param {*} obj2
* @returns {boolean} Whether or not the two arguments being compared are deeply equal
*/
function deepEqual(obj1, obj2) {
if (typeof obj1 !== typeof obj2) {
return false;
@wesleylhandy
wesleylhandy / evaluate-mathematical-expression-string.js
Created August 2, 2021 00:38
This script incorporates the Shunting-yard algorithm to convert a stringified mathematical expression into postfix notation (RPN) and then evaluates that notation to provide the calculation for the mathematical expression provided.
const OPEN_PARENS = "(";
const CLOSED_PARENS = ")";
const ADD = "+";
const SUBTRACT = "-";
const MULTIPLY = "*";
const DIVIDE = "/";
const MODULUS = "%";
const TO_POWER_STAR = "**";
const TO_POWER_CARET = "^";
const LEFT = "left";
lsof -t -i tcp:8000 | xargs kill
@wesleylhandy
wesleylhandy / copy-and-replace.sh
Last active June 9, 2020 16:17
Bash Command to Copy Files and Rename Using Regex
#!/bin/bash
#
# Utility that reads (-r) files that match a filestring pattern and writes (-w) new files
# using replace string (-s) to ammend the filename using the pax archive utility
# Will not overwrite existing files (-k) and will update access times (-t)
#
# EXAMPLE: pax -rwtks '/IAmPatrickDVD/WrittenInStoneDVD/' *IAmPatrickDVD* .
#
pax -rwtks '/<Find>/<Replace>/' <pattern> <location>
@wesleylhandy
wesleylhandy / add-tests.sh
Last active June 6, 2020 02:05
MacOS Bash Command to Create (empty) Test Files for any JavaScript or TypeScript files in your project.
#!/bin/bash
find . \( -iname "*.js*" -or -iname "*.ts*" \) \
-and \( ! -path "*/__mocks__/*" ! -name "*.test.*" ! -name "*.spec.*" \) \
-exec sh -c \
'b=$(basename $1);f=${b%.*};d=$(dirname $1);e=${b##*.}; mkdir -p $d/__tests__ && > $d/__tests__/$f.test.$e' \
sh {} \;