Skip to content

Instantly share code, notes, and snippets.

@socketbox
socketbox / check_ips_against_subnets.sh
Created August 8, 2024 14:42
A script that takes two files--a set of IPs and a set of Subnet--and shows which IPs are in which subnets
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <IP_FILE> <CIDR_FILE>"
exit 1
fi
IP_FILE=$1
CIDR_FILE=$2
@socketbox
socketbox / fmt.hcl
Created July 30, 2024 20:24
tf_fmt_issue
2024-07-30T16:23:34.410-0400 [INFO] Terraform version: 1.9.3
2024-07-30T16:23:34.410-0400 [DEBUG] using github.com/hashicorp/go-tfe v1.51.0
2024-07-30T16:23:34.410-0400 [DEBUG] using github.com/hashicorp/hcl/v2 v2.20.0
2024-07-30T16:23:34.410-0400 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2024-07-30T16:23:34.410-0400 [DEBUG] using github.com/zclconf/go-cty v1.14.4
2024-07-30T16:23:34.410-0400 [INFO] Go runtime version: go1.22.5
2024-07-30T16:23:34.410-0400 [INFO] CLI args: []string{"/home/c
@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 [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 / 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 / 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 September 17, 2024 14:28
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 / 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