Skip to content

Instantly share code, notes, and snippets.

View cwells's full-sized avatar

Cliff Wells cwells

  • Portland, Oregon USA
  • 16:50 (UTC -07:00)
View GitHub Profile
import json
from typing import Any, TypedDict, Union, Callable, Optional
from typeguard import CollectionCheckStrategy, check_type
Serializer = Optional[Callable]
def typed_object_factory(object_type: Any, serializer: Serializer=None):
class TypedObject:
from typing import Any, TypedDict, Union
from typeguard import CollectionCheckStrategy, check_type
class TypedObject:
def __init__(self, object_type: Any) -> None:
self.object_type = object_type
def validate(self, value: Any) -> Any:
check_type(
#!/usr/bin/python
from __future__ import print_function
import sys
from datetime import datetime
import certifi
import pem
import OpenSSL
from acme import crypto_util as acme_crypto_util
@cwells
cwells / demo.py
Last active October 11, 2020 05:59
Execution of topologically-sorted functions and methods
#!/bin/env python
import json
import time
from collections import ChainMap
from functools import partial
import click
from taskgraph import TaskGraph

Keybase proof

I hereby claim:

  • I am cwells on github.
  • I am cliffwells (https://keybase.io/cliffwells) on keybase.
  • I have a public key ASCNReFgwc-v0DTQ-_2gwf_br_YI8ZDQ9NxtqopyYHvfJAo

To claim this, I am signing this object:

def scale(x, a, b):
# translate x from scale(a) -> scale(b)
(a_min, a_max), (b_min, b_max) = a, b
return ((b_max - b_min) * (x - a_min)) / (a_max - a_min) + b_min
#!/usr/bin/env python3
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
GEOCLUE = 'org.freedesktop.GeoClue2'
DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
GCLUE_ACCURACY_LEVEL_COUNTRY = dbus.UInt32(1)
#!/usr/bin/env python3
SKYHOOK_SDK_KEY = '<your skyhook sdk key>'
SKYHOOK_URL = 'https://global.skyhookwireless.com/wps2/location'
UUID = '<generate using uuidgen>'
import time
import webbrowser
import gi
gi.require_version('NM', '1.0')
import functools
def async_compat(func):
@functools.wraps(func)
def wrapper_decorator(*args, **kwargs):
version = sys.version_info[0] + sys.version_info[1] / 10.0
if version >= 3.7:
kwargs['is_async'] = kwargs.get('async', False)
del kwargs['async']
return func(*args, **kwargs)
@cwells
cwells / deep_fn_merge.py
Created December 7, 2018 20:12
deep merge two nested dictionaries, while applying a function to each item
import collections
def deep_fn_merge(fn, left, right):
for k, v in right.iteritems():
if k in left and isinstance(left[k], dict) and isinstance(right[k], collections.Mapping):
deep_fn_merge(fn, left[k], right[k])
else:
left[k] = fn(left, right, k)
def sum(left, right, key):