Skip to content

Instantly share code, notes, and snippets.

Avatar

Will Rouesnel wrouesnel

View GitHub Profile
@wrouesnel
wrouesnel / README.md
Created Aug 2, 2022
Firefox enterprise CA certs
View README.md
@wrouesnel
wrouesnel / README.md
Created Jul 23, 2022
Github Clone All
View README.md

Script for bulk cloning of Github repositories.

@wrouesnel
wrouesnel / safeid.sh
Created Jun 8, 2022
128 bit ID in b32 lowercase with no special characters
View safeid.sh
# 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 Mar 19, 2022
An action implementing key=<json> parsing
View keyvaluejsonaction.py
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 Mar 13, 2022
standard-bash-script-header.sh
View 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 Mar 4, 2022
launch a properly passed through shell command in python
View subprocess-passthru.py
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)
View boto_results.py
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 Feb 2, 2022 — forked from liuw/ctype_async_raise.py
Nasty hack to raise exception for other threads
View ctype_async_raise.py
#!/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
View gist:74df5ce0622fbc7addcee5f6be82ed7f
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
@wrouesnel
wrouesnel / recurse_object.py
Last active Nov 3, 2021
Simple function for recursively iterating JSON-like data in Python
View recurse_object.py
from collections.abc import Mapping
from typing import Any, Callable, Iterable, MutableMapping, MutableSequence
def recurse_object(o: Any,
k=None,
fn: Callable[[Any,Any,Any],Any]=None,
prefn:Callable[[Any,Any],None]=None,
postfn:Callable[[Any,Any,Any,Any],Any]=None,