Skip to content

Instantly share code, notes, and snippets.

earonesty / DPAPI keyring
Created Apr 22, 2021
Replacement keyring backend that uses DPAPI instead of credsmanager
View DPAPI keyring
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
#!/usr/bin/env python
import sys
import re
import configparser
from fnmatch import fnmatch
from unidiff import PatchSet
EXTS = ["py"]

Coding Guidelines


  • These are not to be blindly followed; strive to understand these and ask
    when in doubt. Sometimes standards are a bad idea.

  • Don't duplicate the functionality of a built-in library.

View testman.js
* 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 / qserial.hpp
Last active Mar 22, 2020
Fast C++ serialization: header only with schema
View qserial.hpp
/// replaced with better tested:
#include <vector>
#include <memory>
#include <algorithm>
namespace qserial {
* Simple but limited schema-driven serialization, header-only, small + fast.
earonesty /
Last active Nov 20, 2019
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): = name
self.__io = io
self.__delete = delete
def __getattr__(self, k):
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())))
View delete-squashed-branches
#!/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
earonesty /
Last active Jan 6, 2021
Python's 'if' statement gets privileged information from conditionals
# 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):