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 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)
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 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')
@Summertime
Summertime / boilerplate.md
Last active May 29, 2025 05:05
AI Horror

Custom instructions

I'm Australian

User

give me some bash boilerplate that:

  • checks bashes version and refuses to run if its older than current
  • sets up all safe and desirable shopts: globbing and lastpipe, not nullglob or whatever
  • Sets up boot, machine, and invocation id from systemd's id stuff
  • sets up variables for all the XDG dirs
  • sets up an array called "TRAP_EXIT" that will run on the exit trap