Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View James-Firth's full-sized avatar
🐙

James Firth James-Firth

🐙
View GitHub Profile
@James-Firth
James-Firth / foundry_update.sh
Last active January 15, 2024 19:46
FoundryVTT Updater - A quick script to pull the latest foundry image for docker
#!/bin/bash
# Docker Foundry Updater
# This script is used to download the Foundry ZIP file so it can be picked up by the Foundry container
# By felddy (felddy/foundryvtt:release)
# USAGE
# ./foundry_update.sh TIMED_URL (PATH_TO_CONTAINER_CACHE_FOLDER)
@James-Firth
James-Firth / tmux-on-ssh.md
Last active January 15, 2024 19:46
[Servers] tmux on ssh

On the server, put this snippet in ~/.bashrc to automatically open tmux on ssh

# Open Tmux Session immediately on SSH and exit SSH Session when exiting tmux
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
    tmux attach-session -t ssh_tmux || tmux new-session -s ssh_tmux;
    exit;
fi
@James-Firth
James-Firth / morse-code.json
Created October 15, 2015 22:00 — forked from mohayonao/morse-code.json
Morse code and reverse lookup
{
"0": "-----",
"1": ".----",
"2": "..---",
"3": "...--",
"4": "....-",
"5": ".....",
"6": "-....",
"7": "--...",
"8": "---..",
@James-Firth
James-Firth / file_walker.py
Created July 19, 2022 00:02
Print paths and filenames
import os
for dirname, _, filenames in os.walk('.'):
for filename in filenames:
print(os.path.join(dirname, filename))
// Taken from
// https://advancedweb.hu/how-to-use-async-functions-with-array-filter-in-javascript/
// and
// https://patrickmuff.ch/blog/async-filter-array-typescript/
/**
* @param {Array} array The array to perform the map on
* @param {Function} callback to be performed on each array element
* @return {Promise} Which returns an array of the results, in order.
*/
@James-Firth
James-Firth / _JS_or_TS_examples.md
Last active April 20, 2022 00:42
Demonstrates errors handling arrays of promises

Typescript and Javascript Examples

This will have examples in a file grouped by topic. These are FAQs from co-workers, etc.

@James-Firth
James-Firth / reassigned.js
Last active October 6, 2021 16:31
Why you need to re-assign promises
// Expected (and actual) output:
// "first done"
// "hello world!"
let reassigned = Promise.resolve();
reassigned = reassigned.then(() => new Promise((resolve, reject) => { setTimeout(() => {console.log('first done'); return resolve("hello")}, 3000);}) );
reassigned.then((x) => new Promise((resolve, reject) => { console.log(`${x} world!`); resolve(`${x} world!`);}));
// Flesh Warp Targeter Macro
// for The Occultist
// Whispers player and GM which Defense should be used for each targeted enemy for quicker play when you've taken the Flesh Warp Talent.
// Set up some vars
const gmID = game.users.entities.filter(u => u.isGM).map(u => u._id)[0];
const mdLower = [];
const pdLower = [];
// Figure out what each target should be
@James-Firth
James-Firth / snippet_db_connect_loop_basic.sh
Created July 24, 2019 21:54
Check if DB is up snippet
# vars
NOT_CONNECTED=1
COUNT=0
#...
# run server, etc.
#...
echo "Attempting to connect to SQL SERVER...";
while [ "$NOT_CONNECTED" != "0" ]; do
# Specifically for the MSSQL docker container. Run and try to do a query. Dump all output to /dev/null
/opt/mssql-tools/bin/sqlcmd -e -S "$DB_ADDR" -U "$DB_USER" -P "$SA_PASSWORD" -b -Q "SELECT * FROM sys.databases;" 2>&1 > /dev/null
@James-Firth
James-Firth / ssudo.sh
Created June 20, 2017 19:50
Practice safe-sudo'ing with ssudo. Removes elevated priveleges after a command is run to avoid those accidental shutdowns.
# Throw this in your .zshrc (.bashrc may work too)
safe_sudo() {
cmd="${@: 1}"
if [ "" = "$cmd" ]; then
echo "Missing parameters!";
return 1
fi
sudo ${@: 1};
sudo -k;