Skip to content

Instantly share code, notes, and snippets.

View theelous3's full-sized avatar

M.J. theelous3

  • Dublin, Ireland
View GitHub Profile
'--8banana133744910kmmr13a56!102!2405\r\nContent-Disposition: form-data; name="file_1"; filename="test_file1.txt"; Content-Type: application/octet-stream\r\n\r\nCompooper\r\n--8banana133744910kmmr13a56!102!2405--\r\n'
class LastLoopCacherNoFinal:
pass
class LastLoopCacher:
"""
An iterable context manager that stores the last value it loops as
an attribute, `final`.
Final falls out of scope upon exiting the context manager.
from threading import BoundedSemaphore
from types import GeneratorType
from collections.abc import MappingView, Sequence
from functools import partial
_ALLOWED_SEQUENCE_TYPES = (
Sequence,
MappingView,
GeneratorType
from threading import BoundedSemaphore
from types import GeneratorType
from collections.abc import MappingView, Sequence
from functools import partial
_ALLOWED_SEQUENCE_TYPES = (
Sequence,
MappingView,
GeneratorType
from collections import OrderedDict
class OrderedDefaultDict(OrderedDict):
def __init__(self, default, *args, **kwargs):
# Your default must be callable.
self.default = default
super().__init__(*args, **kwargs)
def __missing__(self, key):
self[key] = value = self.default()
def processor(burn=1):
def inner(gen):
def wrapper(*args, **kwargs):
g = gen(*args, **kwargs)
for _ in range(burn):
next(g)
return g
return wrapper
return inner
import socket
import time
from gzip import compress
def main():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 8000))
s.listen(4)
while True:
from itertools import cycle, islice
import pprint
# one cycle of the group
def increasing_cyclical(xs, period, max_width):
"""
Find the subcycles of an iterable given a depth and breadth.
period: the depth of the subcycle
max_width: the breadth of the subcycle
"""
@theelous3
theelous3 / python_encoding_strings.py
Last active June 15, 2018 15:30
Python formatting list of encodings as strings.
['ascii',
'big5',
'big5hkscs',
'cp037',
'cp273',
'cp424',
'cp437',
'cp500',
'cp720',
'cp737',
"""
Server that accepts a connection, spawns a client handler. Client handler
accepts a request, sends a 404, and kills the connection. Client should attempt
to reuse the connection, failing. Client should retry a new request, passing.
"""
import time
import socket
import h11