Skip to content

Instantly share code, notes, and snippets.

@socketbox
socketbox / k8s_debug_pod.sh
Last active November 3, 2021 00:01
Kubernetes debugging pod based on praqma/network-multitool image
#!/bin/zsh
set -euo pipefail
if [[ "$#" -ne 1 ]];
then
echo "Set the namespace by passing in a single argument"
fi
IMAGE="praqma/network-multitool:alpine-extra"
NAMESPACE=$1
@socketbox
socketbox / check_versioning_on_tfstate.py
Last active December 3, 2021 21:49
A not-so-quick but dirty script that changes bucket versioning across all projects in a GCP organization
"""
"""
from google.cloud.resourcemanager import ProjectsClient
from google.cloud.storage import Client
from google.api_core import exceptions
from google.api_core.retry import Retry
ORGANIZATION_ID = 'YOUR-ORG-ID'
_RETRYABLE_TYPES = [
@socketbox
socketbox / list_certs.sh
Created February 4, 2022 22:42
Get all certificates for a given project
#!/bin/sh
gcloud --format list compute ssl-certificates list
@socketbox
socketbox / rate_limit_test.py
Created April 5, 2022 05:13
Using async IO to test rate limiting
from requests_threads import AsyncSession
import requests
import multiprocessing
import sys
req_count = 500
async_sess = AsyncSession(n=req_count)
async def make_sign_in_call(cookie: dict):
status = 200
@socketbox
socketbox / pre-commit.sh
Last active May 23, 2022 22:30
Pre-commit hook for git
if git rev-parse --verify HEAD
then
export against=HEAD
else
# Initial commit: diff against an empty tree object
export against=$(git hash-object -t tree /dev/null)
fi
files=$(git diff --name-only --diff-filter=ACTM $against)
for f in $files; do
@socketbox
socketbox / worktree.md
Last active May 28, 2025 15:44
Start a new git worktree from an existing branch other than the default

Starting out

Run these commands in a directory devoted to your project:

mkdir project_foo
cd project_foo
git clone --bare [email protected]:yourorg/project_foo.git .bare
echo "gitdir: ./.bare" > .git

Now edit .bare/config, adding fetch = +refs/heads/*:refs/remotes/origin/* below [remote "origin"]

@socketbox
socketbox / pyenv_delete.sh
Created September 17, 2022 21:58
Use grep and awk to delete multiple pyenv envs matching a pattern
for foo in $(pyenv virtualenvs | grep --color=NEVER "^\s\sk" | awk -F" " '{print $1}');
do
pyenv virtualenv-delete -f $foo;
done
@socketbox
socketbox / pbsorg_python_env.md
Last active April 21, 2023 16:35
Setting up a python dev environment for pbsorg

Getting setup

These instructions are for a *NIX operating system. MacOS/Darwin users shouldn't have too much trouble following along. Windows users should switch operating systems.

  1. Install asdf
    1.1 Install python plugin for asdf: asdf plugin add python
    1.2 Install the version of python that is current in the project (cat .tool-versions)
  2. Install poetry using the standard installer.
@socketbox
socketbox / git_cheatsheet.md
Last active June 14, 2023 13:41
Commands and tricks for git

Branches

Get the SHA of the last commit on a remote branch:
git ls-remote [email protected]:org/repo.git branch_name | awk -F '\t' '{ print $1 }'

Delete remote branch
git push -d <remote_name> <branchname>

Diffs

Get a diff between the remote repo of a subtree and the subtree directory of a dependent project:
git diff -w -G upstream-subtree-repo/main main:subtree-repo-directory

@socketbox
socketbox / openconnect_vpn_inside_netns.sh
Created January 30, 2024 23:41 — forked from duboisf/openconnect_vpn_inside_netns.sh
OpenConnect VPN Inside Linux Network Namespace
#!/bin/bash
# start openconnect tunnel and shell inside Linux network namespace
#
# this is a fork of schnouki's script, see original blog post
# https://schnouki.net/posts/2014/12/12/openvpn-for-a-single-application-on-linux/
#
# original script can be found here
# https://gist.github.com/Schnouki/fd171bcb2d8c556e8fdf
# ------------ adjust values below ------------