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
import os | |
import sys | |
import json | |
import math | |
from runstats import Statistics, Regression | |
__all__ = ["randtest", "randtestall", "buildstats"] | |
def primes(givenNumber): | |
# Initialize a list |
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
#!/bin/env python | |
import yaml | |
import sys | |
import json | |
import argparse | |
from subprocess import Popen, PIPE | |
import argparse | |
import os |
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
import os | |
import argparse | |
from typing import NamedTuple | |
from coinmarketcapapi import CoinMarketCapAPI, CoinMarketCapAPIError | |
api_key = os.environ["COINMARKETCAP_API_KEY"] | |
cmc = CoinMarketCapAPI(api_key) | |
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
class LRUSet(set): | |
def __init__(self, *args, max_size=None, **kws): | |
self.max_size = max_size | |
super().__init__(*args, **kws) | |
def add(self, ent): | |
if len(self) >= self.max_size: | |
self.pop() | |
super().discard(ent) | |
super().add(ent) |
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
""" | |
Generate api-style github markdown-files from python docstrings. | |
Example: | |
qpydoc my_module > API.md | |
""" | |
import re |
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
import threading | |
from typing import Any | |
class PropagatingThread(threading.Thread): | |
"""A Threading Class that raises errors it caught, and returns the return value of the target on join.""" | |
def __init__(self, *args, **kwargs): | |
self._target = None | |
self._args = () |
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
# allows you to say with mock_run(...): | |
# .... | |
# good for testing scripts that do a lot of subprocess.run calls | |
class CmdMatch(NamedTuple): | |
cmd: str | |
matches: str = ".*" | |
result: str = "" | |
side_effect: Union[Callable, Exception] = 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
import requests | |
import string | |
import random | |
import argparse | |
import json | |
def main(): | |
parser = argparse.ArgumentParser(description='Post cryptoquips') | |
parser.add_argument("--generate", action="store_true") |
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
#!/usr/bin/python | |
import argparse | |
import contextlib | |
import os.path | |
import re | |
import shutil | |
import subprocess | |
import logging | |
import time | |
import sys |
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
"""TypedEnum : type preserving enumeration metaclass.""" | |
class TypedEnum(type): | |
"""This metaclass creates an enumeration that preserves isinstance(element, type).""" | |
def __new__(mcs, cls, bases, classdict): | |
"""Discover the enum members by removing all intrinsics and specials.""" | |
object_attrs = set(dir(type(cls, (object,), {}))) | |
member_names = set(classdict.keys()) - object_attrs | |
member_names = member_names - set(name for name in member_names if name.startswith("_") and name.endswith("_")) |