Skip to content

Instantly share code, notes, and snippets.

View mathew-fleisch's full-sized avatar

Mathew Fleisch mathew-fleisch

View GitHub Profile
@mathew-fleisch
mathew-fleisch / timeout.sh
Created October 18, 2023 18:12
Bash timer
#!/bin/bash
convertsecs() {
((h=${1}/3600))
((m=(${1}%3600)/60))
((s=${1}%60))
printf "%02d:%02d:%02d\n" $h $m $s
}
started=$(date +%s)
current=$started
@mathew-fleisch
mathew-fleisch / cm-queue-test.sh
Created August 6, 2023 17:04
test for cm-queue.sh
#!/bin/bash
# testing cm-queue.sh from: https://gist.github.com/mathew-fleisch/9743d9801cc2ce3bd6aa678b49cd8ea6
ns=default
cmqueue=test-queue
cmkey=queue
function setup_test() {
echo "Setting up queue..."
./cm-queue.sh $ns $cmqueue $cmkey delete \
@mathew-fleisch
mathew-fleisch / cm-queue.sh
Last active August 6, 2023 17:03
Using a configmap as a simple queue with kubectl
#!/bin/bash
ns=$1
cm=$2
cmkey=$3
# actions: getfirst, getlast, getall, getyaml, shift, pop, prepend, append, delete
action=$4
cmval=$5
k="kubectl -n $ns"
jp="jsonpath='{.data.$cmkey}'"
@mathew-fleisch
mathew-fleisch / balanced-parentheses.js
Created January 12, 2020 23:18
Balanced Parentheses
matrix = [["(","("],[")",")"]]
matrix1 = [["(","("],["(",")"]]
matrix2 = [["(",")"],[")",")"]]
matrix3 = [["(",")"],["(",")"]]
console.log(`isBalanced(${JSON.stringify(matrix)}) => ${isBalanced(matrix)}`)
console.log(`isBalanced(${JSON.stringify(matrix1)}) => ${isBalanced(matrix1)}`)
console.log(`isBalanced(${JSON.stringify(matrix2)}) => ${isBalanced(matrix2)}`)
console.log(`isBalanced(${JSON.stringify(matrix3)}) => ${isBalanced(matrix3)}`)
#!/bin/python3
input = [
["price", "display price of item"],
["owner", "show owner of item"],
["update", "sync cache with database"],
["delete", "delete item"],
["disassociate", "remove item from owner"]
]
var input = [
["price", "display price of item"],
["owner", "show owner of item"],
["update", "sync cache with database"],
["delete", "delete item"],
["disassociate", "remove item from owner"]
]
// This function should display a menu of key/value pairs
// in a justified format, for viewing in a terminal/console
@mathew-fleisch
mathew-fleisch / recursive-directory-sizes.sh
Last active June 7, 2021 16:41
Get the size of each directory recursively with du -sh
#!/bin/bash
get_dirs() {
dir=$(realpath $1)
for d in $dir/*/; do
if [[ -d $d ]]; then
du -sh $d
get_dirs $d
fi
done
#!/bin/bash
# shellcheck disable=SC2086
set -eou pipefail
_git_token="${GIT_TOKEN:-}"
repo_owner="${1:-}"
repo_name="${2:-}"
git_tag="${3:-}"
asset_filename="${4:-}"
@mathew-fleisch
mathew-fleisch / get-maximum-from-array-of-ints.js
Created January 22, 2021 18:55
Get maximum multiple of all possible values in array of integers
// get maximum multiple of all possible values in array of integers
// [1, 2 , 5 , 0, 100] 500
let arr = [-300, -10, 1, 2 , 5 , 0, 100, 99]
// let arr = [-3000, -10, 1, 2 , 5 , 0, 100, 99]
// let arr = [-3000, 10, 1, 2 , 5 , 0, 100, 99]
function getHighestMultiple(arr) {
#!/bin/bash
usage="usage: decode-all-kubernetes-secrets.sh [context] [namespace]"
context=${1:-}
namespace=${2:-}
if [[ -z "$context" ]]; then
echo "Missing context"
echo "$usage"
exit 1
fi