Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
🐳 🚢 🏗️

Ryan Jones rjchicago

💭
🐳 🚢 🏗️
View GitHub Profile
@rjchicago
rjchicago / test.sh
Created February 27, 2023 14:58
Test Endpoint
View test.sh
# create alias
test() {
local URL=${1:?URL is required as first argument}
local TIMEOUT=${TIMEOUT:-1}
local SLEEP=${SLEEP:-1}
while true; do curl -s -m $TIMEOUT $URL > /dev/null && echo -n ✅ || echo -n 💀; sleep $SLEEP; done
}
# usage
@rjchicago
rjchicago / verify-floating-ip.sh
Created February 3, 2023 16:47
Script to verify MetalLB floating IP assignment to a given service.
View verify-floating-ip.sh
#!/bin/sh
set -Eeuo pipefail
echo
: ${NAMESPACE:?NAMESPACE is required}
: ${SERVICE:?SERVICE is required}
: ${FLOATING_IP:?FLOATING_IP is required}
echo "VERIFY FLOATING IP: $FLOATING_IP"
while true; do
@rjchicago
rjchicago / metallb-health.yaml
Created February 2, 2023 21:30
Demo Nginx service health endpoint for MetlalLB in K8s.
View metallb-health.yaml
apiVersion: v1
kind: Namespace
metadata:
name: metallb-health
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
@rjchicago
rjchicago / configmap_from_file.sh
Created February 2, 2023 19:04
Function to read and format K8s ConfigMap data from file
View configmap_from_file.sh
# Function to read and format ConfigMap data from file
configmap_from_file() {
local FILE=${1:?FILE is required}
local INDENT=${2:-4}
local SPACES=$(printf ' %.0s' {1..$INDENT})
echo "|" && cat $FILE | sed "s/^/$SPACES/"
}
##################################################
# usage
@rjchicago
rjchicago / swarm-host-ip.sh
Created October 26, 2022 14:29
Docker Swarm Host IPs
View swarm-host-ip.sh
# get hosts (mgr node)
HOSTS=$(docker node ls --format "{{.Hostname}}")
# print host/ip
for HOST in $HOSTS; do host $HOST; done | awk '{print $1, $4}' | sort
View IEEE-754.js
( 0.1 + 0.2 === 0.3 ) ? console.log('LGTM') : console.log('WTF');
@rjchicago
rjchicago / import_table.sql
Created May 9, 2022 15:05
Postgres Import Table Function
View import_table.sql
CREATE OR REPLACE FUNCTION "my_schema"."import_table" (fdw_server text, tablename text, where_filter text) RETURNS bigint
VOLATILE
AS $body$
DECLARE
v_fdw_schema TEXT;
v_fdw_tablename TEXT;
v_col_def TEXT;
v_query TEXT;
v_schema_name TEXT;
v_table_name TEXT;
@rjchicago
rjchicago / arr2chunks
Created February 28, 2022 14:59
chunk large object arrays to string
View arr2chunks
# chunk array to string
private *arr2chunks(arr: any[], n: number) {
for (let i = 0; i < arr.length; i += n) {
const str = JSON.stringify(arr.slice(i, i + n))
const open = i === 0 ? '[':'';
const close = n*(i+1) < arr.length ? ',' : ']';
yield `${open}${str.slice(1, str.length-1)}${close}`;
}
yield null;
}
@rjchicago
rjchicago / docker-network-services.sh
Created May 27, 2021 16:46
Get Docker services by network
View docker-network-services.sh
NETWORK=$1
docker network inspect $NETWORK -v | jq -r '.[0] .Services | to_entries[] | .key'
@rjchicago
rjchicago / git-reset-master.sh
Last active May 24, 2021 19:03
Sometimes you just want to reset everything and clean up with only the master branch again (locally). This script will reset hard, checkout master, and delete all local non-master branches.
View git-reset-master.sh
git reset --hard && git checkout master && git branch | grep -v "^..master$" | xargs git branch -D && git pull
# add to ~/.bash_profile
# alias git-reset-master='git reset --hard && git checkout master && git branch | grep -v "^..master$" | xargs git branch -D && git pull'