This file contains 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
# coding=utf-8 | |
from itertools import product | |
adjacents = ('08', '124', '1253', '236', '1457', '24568', '3569', '478', '57890', '689') | |
adjacents = {str(i): s for i, s in enumerate(adjacents)} | |
def get_pins_itertools(observed): | |
for pins in product(*(adjacents[ch] for ch in observed)): |
This file contains 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
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
try: | |
# noinspection PyUnresolvedReferences,PyShadowingBuiltins | |
str = unicode | |
except NameError: | |
# noinspection PyShadowingBuiltins,PyUnboundLocalVariable | |
str = str |
This file contains 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
# coding=utf-8 | |
from math import log2, ceil | |
# valid chars for a url path component: a-z A-Z 0-9 .-_~!$&'()*+,;=:@ | |
# for the default set here (base 72) we have excluded $'();:@ | |
radix_alphabet = sorted( | |
"0123456789" | |
"abcdefghijklmnopqrstuvwxyz" | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
This file contains 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
# coding=utf-8 | |
class NaryHeap(object): | |
"""implements an n-ary heap""" | |
def __init__(self, items=(), *, n=2, direction=min): | |
""" | |
create a new heap |
This file contains 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
# coding=utf-8 | |
from mumblecode.multithreading import CloseableQueue | |
from queue import Queue, Empty | |
from threading import Thread | |
import requests | |
_STOP = object() |
This file contains 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
# coding=utf-8 | |
from mumblecode.multithreading import CloseableQueue | |
from threading import Thread | |
from concurrent.futures import Future | |
import requests | |
class RequestFuturePool(object): | |
def __init__(self, pool_size=20, queue_size=64, rate_limiter=lambda: None): |
This file contains 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
# coding=utf-8 | |
from collections import Mapping, Iterable | |
from operator import attrgetter | |
from struct import pack, unpack | |
__doc__ = """ | |
Pure python tools for inspecting unknown protobuf data. Written for py3.6+. | |
Author: Kent Ross |
This file contains 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
# coding=utf-8 | |
from collections import deque | |
from queue import Empty, Full | |
from threading import Condition, RLock, Thread | |
from time import monotonic as now | |
from weakref import finalize | |
class ChannelClosed(Exception): | |
"""Exception raised when a channel has been closed.""" |
This file contains 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
# coding=utf-8 | |
"""Lazy hacks to enable easier usage of async functions, context managers, and iterators in the REPL.""" | |
from asyncio import set_event_loop | |
try: | |
import uvloop as loop_maker | |
except ImportError: | |
import asyncio as loop_maker | |
loop = loop_maker.new_event_loop() |
This file contains 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 Thread | |
import requests | |
from multithreading import Channel | |
def fetch_all_with_pool(iterable_of_urls, pool_size=20): | |
""" | |
Fetches URLs with a thread pool. |