This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def range(*args): | |
def inner(start=0, stop=..., step=1): | |
if stop is ...: | |
stop = float('inf') | |
while start < stop: | |
yield start | |
start += step | |
if len(args) == 1: | |
return inner(stop=args[0]) | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Alabama": ["Autauga County", "Baldwin County", "Barbour County", "Bibb County", "Blount County", "Bullock County", "Butler County", "Calhoun County", "Chambers County", "Cherokee County", "Chilton County", "Choctaw County", "Clarke County", "Clay County", "Cleburne County", "Coffee County", "Colbert County", "Conecuh County", "Coosa County", "Covington County", "Crenshaw County", "Cullman County", "Dale County", "Dallas County", "DeKalb County", "Elmore County", "Escambia County", "Etowah County", "Fayette County", "Franklin County", "Geneva County", "Greene County", "Hale County", "Henry County", "Houston County", "Jackson County", "Jefferson County", "Lamar County", "Lauderdale County", "Lawrence County", "Lee County", "Limestone County", "Lowndes County", "Macon County", "Madison County", "Marengo County", "Marion County", "Marshall County", "Mobile County", "Monroe County", "Montgomery County", "Morgan County", "Perry County", "Pickens County", "Pike County", "Randolph County", "Russell County", "St. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test = { | |
'lol': ['wat', 'the', 'fuck'], | |
'ten': 'pence', | |
'who': {'did': 1, 'the': 2, 'poop': 3}, | |
'this': [{'goes': {'pretty': 'deep'}, 'if': {'I': 'may say so'}}] | |
} | |
class StopSearch(Exception): | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import BoundedSemaphore | |
from types import GeneratorType | |
from collections.abc import MappingView, Sequence | |
from functools import partial | |
_ALLOWED_SEQUENCE_TYPES = ( | |
Sequence, | |
MappingView, | |
GeneratorType |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import BoundedSemaphore | |
from types import GeneratorType | |
from collections.abc import MappingView, Sequence | |
from functools import partial | |
_ALLOWED_SEQUENCE_TYPES = ( | |
Sequence, | |
MappingView, | |
GeneratorType |