Skip to content

Instantly share code, notes, and snippets.

View dannysauer's full-sized avatar

Danny Sauer dannysauer

View GitHub Profile
@dannysauer
dannysauer / 1_forward.md
Created October 21, 2022 18:45
ssh port fowarding

We have two machines: master and agent. The goal is for agent to ssh into master, allocating a local port on master which forwards to a port on agent.

In this example, we'll use ssh - but that's arbitrary. The "master" is lightning and the "agent" is fabulinus.

First: open the ssh connection:

sauer@fabulinus:~$ ssh -Nf -R 10022:localhost:22 lightning

This will fork ssh into the background (-f) and not run a program (-N). Thus, it's just forwarding the port and nothing else.

@dannysauer
dannysauer / contributors.sh
Created May 6, 2022 17:13
quick github stats
#!/bin/bash
ORG=Kong
declare -A externals
printf "repo,user,external?\n"
for REPO in $(gh api --paginate "/orgs/$org/repos?type=public&sort=full_name&per_page=100" \
| jq -r '.[] | select( .fork == false ) | .name')
do
echo "processing $REPO" >&2
@dannysauer
dannysauer / env-specific.md
Last active March 17, 2022 18:46
Shell stuff

autoscaler logs

kubectl -n kube-system logs --selector="app.kubernetes.io/name=aws-cluster-autoscaler"
#!/usr/bin/perl
use warnings;
use strict;
use Carp;
use DateTime;
use Date::Parse qw( str2time );
use JSON qw( decode_json );
# legacy ingress log examples:
@dannysauer
dannysauer / 1 bash POST multiplex.md
Last active January 29, 2022 03:21
Stupid shell tricks

One-liner to accept incoming http POST data and then relay it to some number of POST endpoints.

while true; do printf 'HTTP/1.0 200 OK\r\nContent-Length: 0\r\n' | { nc -q1 -l 8080; echo; } | sed '0,/^[[:space:]]*$/d' | tee >(http POST http://localhost:8081/path1) >(http POST http://localhost:8081/path2); done

With some linebreaks so it's readable:

while true
do
@dannysauer
dannysauer / getall.sh
Last active March 24, 2022 18:52
misc kubernetes / k8s junk
# put this in your ~/.bashrc
function kubectlgetall {
kubectl -n ${1:?usage: ${FUNCNAME[0]} <namespace>} get --ignore-not-found $( \
kubectl api-resources --verbs=list --namespaced -o name \
| grep -v --line-regexp -e "events.events.k8s.io" -e "events" \
| sort -u \
| paste -sd, \
)
}
@dannysauer
dannysauer / Upgrade.md
Created November 28, 2021 03:31
Hassbian notes

Upgrade Hassbian installation to Debian Bullseye in order to get python 3.9

Update OS. Follow another guide, except also remember to update all of the other /etc/apt/sources.list.d/ files too. :) Note that there is no hassbian-scripts repo for bullseye, so just leave that one at buster. https://www.tomshardware.com/how-to/upgrade-raspberry-pi-os-to-bullseye-from-buster

Update hassbian-scripts, which likely got removed at the automremove step - removing your systemd unit and all sorts of other things. The scripts package available on gitlab is broken, but there's a fork with a few fixes (primarily python package deps).

git clone https://github.com/dannysauer/hassbian-scripts.git
cd hassbian-scripts
@dannysauer
dannysauer / gitconfig.ini
Created March 10, 2021 17:06
git tag promotion aliases
✔ /tmp/testrepo [main L|✔]
10:04 $ sed -n '/alias/,$p' .git/config
[alias]
show-tag-date = tag --list --format "%(taggerdate:unix)"
flux-latest-stage-tag = describe --abbrev=0 --tags --match 'stage/*' main
flux-latest-prod-tag = describe --abbrev=0 --tags --match 'prod/*' main
flux-state = show --oneline --no-patch main stage prod
# git flux-rollback [stage|prod]
flux-rollback = "!git branch -f $1 $( git describe --abbrev=0 --tags --match="$1/*" ${1}^ ) && git tag -m \"rollback $1\" ${1}/$(date +'%F-%H-%M-%S')/rollback $1 #"
flux-stage = !git tag -m 'promote to stage' stage/$(date +'%F-%H-%M-%S') refs/heads/main && git branch -f stage $( git flux-latest-stage-tag )
@dannysauer
dannysauer / secretbench.py
Last active March 2, 2021 05:04
secretbench
#!/usr/bin/env python3
import random
from base64 import b64encode
from kubernetes import client, config
from string import ascii_letters
from timeit import timeit
config.load_kube_config()
v1 = client.CoreV1Api()
@dannysauer
dannysauer / secretbench.sh
Last active March 1, 2021 18:36
K8S secret storage "benchmark"
#!/bin/bash
set -o errexit
output_every=100
separator='###'
secret_template='---
apiVersion: v1
kind: Secret
metadata:
name: secret$I