Skip to content

Instantly share code, notes, and snippets.

View earonesty's full-sized avatar
🎹
Piano

earonesty

🎹
Piano
View GitHub Profile
import os
import argparse
from typing import NamedTuple
from coinmarketcapapi import CoinMarketCapAPI, CoinMarketCapAPIError
api_key = os.environ["COINMARKETCAP_API_KEY"]
cmc = CoinMarketCapAPI(api_key)
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 = ()
@earonesty
earonesty / reno-report.py
Last active November 3, 2021 15:11
reno reporter & linter that is far faster and leverages filtered git logs to handle topology for you
#!/usr/bin/python
import argparse
import contextlib
import os.path
import re
import shutil
import subprocess
import logging
import time
import sys
@earonesty
earonesty / DPAPI keyring
Created April 22, 2021 14:10
Replacement keyring backend that uses DPAPI instead of credsmanager
import typing
from contextlib import suppress
from pathlib import Path
import logging
from logextension import LoggingContext
with LoggingContext(logging.getLogger("keyring.backend"), logging.ERROR):
import keyring.backend
@earonesty
earonesty / diffcount.py
Last active December 21, 2020 13:56
diffcount.py
#!/usr/bin/env python
import sys
import re
import configparser
from fnmatch import fnmatch
from unidiff import PatchSet
EXTS = ["py"]
/*
* Very simple test runner for nodejs:
*
* Supports:
*
* before, after, beforeAll, afterAll
* fixture object passed to each test, that before/after/beforeAll/afterAll can modify
* -[t]est option on command line to pick tests to run
* -[l]inear option on command to disable parallel
* built in fixture logger, captures log lines, adds line numbers/file names/timestamps
"""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("_"))
@earonesty
earonesty / qserial.hpp
Last active March 22, 2020 22:21
Fast C++ serialization: header only with schema
/// 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.
@earonesty
earonesty / ntf.py
Last active January 31, 2023 10:50
NamedTemporaryFile drop in replacement that deletes on gc, not close(), and supports mode=None
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):