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
#pylint: disable=protected-access | |
import inspect, itertools, functools | |
class StrictError(TypeError): | |
pass | |
def strict(cls): | |
cls._x_frozen = False | |
cls._x_setter = getattr(cls, "__setattr__", object.__setattr__) |
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
class FakeFile: | |
def __init__(self, size, repeat=b'0'): | |
self.loc = 0 | |
self.size = size | |
self.repeat = repeat | |
self.closed = False | |
def fileno(self): | |
raise OSError() |
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 random | |
def scramble(gen, buffer_size): | |
buf = [] | |
i = iter(gen) | |
while True: | |
try: | |
e = next(i) | |
buf.append(e) | |
if len(buf) >= buffer_size: |
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 fastjsonschema as fjs | |
from urllib import parse as urlparse | |
from hashlib import md5 | |
_schema_dir = os.path.dirname(__file__) | |
_file_loader = {'file': lambda f: json.loads(open(_schema_dir + "/" + urlparse.urlsplit(f).path.lstrip('/')).read())} | |
def gen_var_name(schema, step="format"): | |
x=schema.copy() |
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
# python 'if' statement is priviliged to the boolean output of compound conditionals | |
# other statements are not, and have to double-evaluate the output | |
# unless the output is "the last one" | |
class X: | |
def __init__(self): | |
self.v = False | |
self.c = 0 | |
def __bool__(self): |
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
#!/usr/bin/env python | |
'''Delete local branches which have been merged via GitHub PRs. | |
Usage (from the root of your GitHub repo): | |
delete-squahsed-branches [--dry-run] | |
If you specify --dry-run, it will only print out the branches that would be | |
deleted. |
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 threading | |
class SafeWrap(): | |
""" | |
Wrap an unsafe sdk (like onedrivesdk, for example) in a thread lock. | |
Derive from this if you want to translate exceptions, or change the | |
type set | |
""" | |
__safe_types = (str, int, float, type(None), bool, bytes, type(iter(bytes())), type(iter(str()))) |
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 os, tempfile, gc | |
class TemporaryFile: | |
def __init__(self, name, io, delete): | |
self.name = name | |
self.__io = io | |
self.__delete = delete | |
def __getattr__(self, k): |
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
/// replaced with better tested: github.com/earonesty/qserial | |
#include <vector> | |
#include <memory> | |
#include <algorithm> | |
namespace qserial { | |
/* | |
* Simple but limited schema-driven serialization, header-only, small + fast. |
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
"""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("_")) |