Skip to content

Instantly share code, notes, and snippets.

View earonesty's full-sized avatar
🎹
Piano

earonesty

🎹
Piano
View GitHub Profile
@earonesty
earonesty / README.md
Last active June 22, 2021 18:39
Convert a djinni input file to a node cpp bindings file. Load the resulting lib directly in node.

USAGE:

python3 node_bindings.py djinni.yml <namespace> node/node.cpp
yarn
mkdir -p build-node
cd build-node; \
    cmake .. -DCMAKE_BUILD_TYPE=Release -DNODE=yes; \
    cmake --build . -j

node node/test.js

@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 / fun.py
Last active January 6, 2021 16:46
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):
@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"]
@earonesty
earonesty / qjson.h
Last active December 4, 2020 12:32
#ifndef INCLUDED_QJSON_H
#define INCLUDED_QJSON_H
#include <string>
#include <vector>
#include <map>
#include <stdexcept>
#include <memory>
#include <algorithm>
#include <istream>
@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.
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())))
#!/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.
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()
@earonesty
earonesty / scramble.py
Created September 27, 2019 19:48
randomize a generator stream within a fixed window
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: