Skip to content

Instantly share code, notes, and snippets.

Avatar
📈

James J. Womack jameswomack

📈
View GitHub Profile
@jameswomack
jameswomack / autoload-for-zshrc.zsh
Created June 2, 2023 20:44
Auto-load correct Node version from directory based on .nvmrc
View autoload-for-zshrc.zsh
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
@jameswomack
jameswomack / History|-1022aafb|entries.json
Last active October 5, 2022 17:37
Visual Studio Code Settings Sync Gist
View History|-1022aafb|entries.json
{"version":1,"resource":"file:///Users/jameswomack/Projects/github/SportsCardInvestor/sci-api/jest.config.js","entries":[{"id":"Xi7a.js","source":"Workspace Edit","timestamp":1663784147251}]}
@jameswomack
jameswomack / instructions.md
Last active February 2, 2022 21:47
Monorepo test iteration. Logging your `lerna run test` output & using that to only re-run packages that haven't passed yet
View instructions.md

usage

start a new test session

lerna-test-resume --init

run your tests w/ tee

@jameswomack
jameswomack / mandrill.js
Created January 13, 2022 21:10
using the for loop paradigm to drill down to a matching shadowRoot
View mandrill.js
function updateState (state) {
return console.dir(state);
}
const thaNode = {};
const host = {
shadowRoot: thaNode
};
@jameswomack
jameswomack / accept-all-invites.scpt
Created November 27, 2021 17:10
Accept every calendar event in Outlook Mac using AppleScript
View accept-all-invites.scpt
tell application "Microsoft Outlook"
repeat with calendarEvent in the every calendar event
accept meeting calendarEvent
end repeat
end tell
@jameswomack
jameswomack / find-and-replace.txt
Created September 2, 2021 18:02
Replacing named function expressions w/ arrow body style
View find-and-replace.txt
Find:
function ([a-zA-Z]+)(\([a-zA-Z, \{\}]+\)) (\{)
Replace:
const $1 = $2 => $3
@jameswomack
jameswomack / _jewel.js
Last active July 15, 2021 00:30
Configurably generating a "jewel" board in which no 3 consecutive jewels are allowed in a given column or row
View _jewel.js
/* eslint-disable no-console, no-param-reassign */
/**
* Returns a filled in board such that there are no 3 consecutive
* jewels (vertically/horizontally) of the same type.
*
* @param widthOfBoard int which provides width of board
* @param heightOfBoard int which provides height of board
* @param jewels array providing valid jewels for board
*/
@jameswomack
jameswomack / scope.js
Created July 14, 2021 16:34
Looking at the difference between function & block scope in JavaScript
View scope.js
const console = require("console");
(function () {
console.log(foo); // undefined
{
var foo = 'foo';
}
})();
(function () {
@jameswomack
jameswomack / palindromes.js
Last active December 14, 2021 21:43
Determining if a string is a palindrome—or becomes a palindrome by dropping one of its characters
View palindromes.js
function isArrayPalindrome (array) {
const forward = [...array].join();
const reversed = [...array].reverse().join();
if (reversed == forward) {
return true;
}
return false;
}
const getArraySansIndex = (a, _index) => a.filter((item, index) => index !== _index);