Skip to content

Instantly share code, notes, and snippets.

View wrouesnel's full-sized avatar

Will Rouesnel wrouesnel

View GitHub Profile
@wrouesnel
wrouesnel / reverseit.systemd
Created August 10, 2022 23:45
Systemd script with restarts which will keep going
[Unit]
Description=Maintain a reverseit SSH connection
After=network.target
StartLimitBurst=5
# This line disables the "stop forever" start back off
StartLimitIntervalSec=0
[Service]
Type=simple
@wrouesnel
wrouesnel / README.md
Created August 2, 2022 00:47
Firefox enterprise CA certs
@wrouesnel
wrouesnel / README.md
Created July 23, 2022 10:22
Github Clone All

Script for bulk cloning of Github repositories.

@wrouesnel
wrouesnel / safeid.sh
Created June 8, 2022 03:47
128 bit ID in b32 lowercase with no special characters
# Generate a 128-bit identifier, encoded entirely in b32 lowercase. No special characters.
function safeid() {
python3 -c 'import uuid, base64 ; print(base64.b32encode(uuid.uuid4().bytes).lower().rstrip(b"=").decode())'
}
@wrouesnel
wrouesnel / keyvaluejsonaction.py
Created March 19, 2022 03:42
An action implementing key=<json> parsing
import argparse
import json
class KeyValueJsonAction(argparse.Action):
"""
Argparse action for generating dictionaries from key-value args with JSON support
"""
def __call__(self, parser, namespace, values, option_string=None):
result = {}
for entry in values:
@wrouesnel
wrouesnel / standard-bash-script-header.sh
Created March 13, 2022 23:24
standard-bash-script-header.sh
# See: https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
# Note: you can't refactor this out: its at the top of every script so the scripts can find their includes.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
@wrouesnel
wrouesnel / subprocess-passthru.py
Created March 4, 2022 10:33
launch a properly passed through shell command in python
cmd = []
env = os.environ.copy()
p = subprocess.Popen(
cmd, env=env, cwd=os.path.realpath(os.curdir), stdin=sys.stdin, stderr=sys.stderr, stdout=sys.stdout
)
# Attach all signals and forward them to the subprocess
def sighandler(signum, stack):
p.send_signal(signum)
def boto_results(key, fn, *args, **kwargs):
result = []
next_token = None
while True:
r = fn(*args, **kwargs)
next_token = r.get("NextToken")
value = r[key]
if isinstance(value, (str, bytes)):
result.append(value)
elif isinstance(value, Mapping):
@wrouesnel
wrouesnel / ctype_async_raise.py
Last active February 2, 2022 09:50 — forked from liuw/ctype_async_raise.py
Nasty hack to raise exception for other threads
#!/usr/bin/env python
# liuw
# Nasty hack to raise exception for other threads
import ctypes # Calm down, this has become standard library since 2.5
import threading
import time
NULL = 0
from dataclasses import dataclass, field
from typing import List, Optional, ClassVar, Type, Union
import marshmallow_dataclass
import marshmallow_union
from marshmallow import fields
from marshmallow.validate import Equal
from marshmallow_polyfield import PolyField
from marshmallow_toplevel import TopLevelSchema