Skip to content

Instantly share code, notes, and snippets.

View Summertime's full-sized avatar
😳
programming

Andrew C. H. McMillan Summertime

😳
programming
View GitHub Profile
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-n', '--count', metavar='TIMES', default=None, type=int)
parser.add_argument('-e', '--every', metavar='SECONDS', default=5, type=float)
parser.add_argument('-o', '--stdout', action='store_true')
parser.add_argument('-H', '--header', dest='headers', metavar=('KEY', 'VALUE'), action='append', default=[], nargs=2)
parser.add_argument('-t', '--template', default='%Y-%m-%dT%H:%M:%S.%f%:z')
parser.add_argument('--timeout', metavar='SECONDS', default=60, type=float)
parser.add_argument('url')
class TimeoutMixin:
def send(self, *args, **kwargs):
if hasattr(self, 'timeout') and 'timeout' not in kwargs:
kwargs['timeout'] = self.timeout
return super().send(*args, **kwargs)
# Use
import requests
class Session(TimeoutMixin, requests.Session):
#!/usr/bin/env python
import os
import ctypes
from ctypes import CDLL
import sys
import random
import string
from errno import EEXIST
# C stuff
libc = CDLL('libc.so.6', use_errno=True)
#!/usr/bin/env python
from functools import wraps
class Interpolation:
def __init__(self, getvalue):
self.getvalue = getvalue
def eager_tag(func):
@wraps(func)
def wrapper(*args):
#!/usr/bin/env python
# Novel code (of which there is almost none) is under The Unlicense
# the C# runtime code this file copies from is
# https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/LICENSE.TXT
# The decompiled C# code this file copies parts from is owned by https://x.com/eggHatcherGame
# And is unfortunately used here without permission.
import json
import sys
import io
@Summertime
Summertime / README.md
Last active March 19, 2023 11:22
Bash Book

Bash Book

@Summertime
Summertime / processing.bash
Last active November 23, 2022 11:57
Bunch of functions to make things easier
#!/usr/bin/env bash
p () {
declare USAGE="${FUNCNAME[0]} [-h] [-0] [--] [ARGS ...]"
declare NL='\n'
declare -i OPTIND=1
while getopts h0 OPT; do
case "$OPT" in
'h')printf 'Usage: %s\n' "$USAGE";return;;
'?')printf 'Usage: %s\n' "$USAGE">&2;return 1;;
APPNAME=exchange.sh
p () { printf '%s\n' "$@";}
: "${XDG_CACHE_HOME:=$HOME/.cache}"
cachedget () {
URL=$1
CACHEDIR="$XDG_CACHE_HOME/$APPNAME/curl/GET-$(base64 -w0 <<< "$URL")"
mkdir --parents "$CACHEDIR"
curl -sS \
const filters = [
/^Running script with [0-9]+ thread\(s\), pid [0-9]+ and args/,
]
function findProp(propName) {
// stolen from talamond
for (let div of eval("document").querySelectorAll("div")) {
let propKey = Object.keys(div)[1];
if (!propKey)
continue;