Skip to content

Instantly share code, notes, and snippets.

@socketbox
socketbox / git_worktree_add.sh
Created March 20, 2024 19:58
Add a git worktree within a workflow that uses tmux
#!/bin/zsh
set -euo pipefail
#check to see that we're in the worktree root that contains the .bare directory
if [ ! -d .bare ]; then
echo "This script must be run from the root of the worktree"
exit 1
fi
#check if an argument was passed to the script and if not print usage
@socketbox
socketbox / update_qbit_port.sh
Last active February 24, 2024 11:31 — forked from trevordavies095/update_qbit_port.sh
Determine protonvpn port via gluetun and update qbittorrent
#!/bin/sh
# Determine protonvpn port via gluetun and update qbittorrent
#
# Add the following to sudo crontab -e to run every 5 minutes
# */5 * * * * /bin/sh /path/to/update_qbit_port.sh
# For synology users, run the script as root via the task scheduler every 5 minutes.
QBITTORRENT_USER= # qbittorrent username
QBITTORRENT_PASS= # qbittorrent password
QBITTORRENT_PORT=
@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 ------------
@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 git@github.com: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 / 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.
aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <your-aws-account-id>.dkr.ecr.us-east-1.amazonaws.com
@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 / worktree.md
Last active March 15, 2024 15:32
Start a new git worktree from an existing branch other than the default

Starting out*

mkdir project_foo
cd project_foo
git clone --bare git@github.com:yourorg/project_foo.git .bare
echo "gitdir: ./.bare" > .git

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

[remote "origin"]                               
 url = git@github.com:yourorg/project_foo.git 
@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 / 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