Skip to content

Instantly share code, notes, and snippets.

View fish2000's full-sized avatar
👉
My Python work is on the Mars helicopter, and ubiquitous on earth, and more!!!!

Alexander Böhn fish2000

👉
My Python work is on the Mars helicopter, and ubiquitous on earth, and more!!!!
  • Objects in Space and Time, LLC
  • Baltimore, MD
  • 06:41 (UTC -05:00)
  • X @fish2000
View GitHub Profile
@dhilst
dhilst / delegate.py
Last active December 15, 2019 17:28
Delegate methods in python
def delegate(to, *methods):
'''
Class decorator to delegate methods to another objects.
>>> @delegate('v', 'upper')
... @delegate('v', 'lower')
... @delegate('v', 'wrong_method')
... @delegate('not_an_attribute', 'wrong_attribute')
... class Foo:
... def __init__(self, v):
... self.v = v
@fish2000
fish2000 / keyvalue.py
Last active May 10, 2019 01:29
Generic Python REPL configuration NOW WITH ANSI-COLOR FIGLET BANNERS DOGG
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import plistlib
import zict
import os
import appdirs
from replutilities import attr, isstring, isbytes

DevOps README.md

The Phoenix Project

  • Novel; Not your typical technical book
  • Transformation of Broken Organization towards DevOps Culture
  • Quintessential beginning of a DevOps journey
  • Pros: Easy to digest, can suggest to executives
  • Cons: The implementation details are fuzzy
  • Quip: We all know Brent. Help Brent not be Brent.
@elidchan
elidchan / verbiage.py
Created January 19, 2019 17:30
Utilities for indefinite article and plurality
import ast
import contextlib
import json
import os
import string
from collections import OrderedDict
from enum import Enum
from numbers import Number
from string import Template
@DangerOnTheRanger
DangerOnTheRanger / importhooks.py
Last active August 19, 2022 02:54
Example showing how to use import hooks in Python 3 - original article: https://dev.to/dangerontheranger/dependency-injection-with-import-hooks-in-python-3-5hap
import importlib.abc
import importlib.machinery
import sys
import types
class DependencyInjectorFinder(importlib.abc.MetaPathFinder):
def __init__(self, loader):
self._loader = loader
def find_spec(self, fullname, path, target=None):
@fish2000
fish2000 / pycheckmate.py
Last active December 5, 2018 17:53
Overhaul of PyCheckMate.py for Python 3.7 circa late 2018
#!/usr/bin/env python
# encoding: utf-8
#
# PyCheckMate, a PyChecker output beautifier for TextMate.
# Copyright (c) Jay Soffian, 2005. <jay at soffian dot org>
# Inspired by Domenico Carbotta's PyMate.
# Extensively overhauled for version 2.0 by Alexander Böhn.
#
# License: Artistic.
#
@fish2000
fish2000 / multiple_dispatch.py
Last active November 20, 2018 20:25 — forked from wolfv/multiple_dispatch.py
A Taste Of Julia / C++ in Python – simple Python multiple dispatch from type hints
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# multiple_dispatch.py
#
# My version:
# https://gist.github.com/fish2000/1af4b852d20b7568a9b9c90fe2346b6d
#
# Forked from the originall by @wolfv:
# https://gist.github.com/wolfv/73f56e4a9cac84eea6a796fde3213456
@yeraydiazdiaz
yeraydiazdiaz / threadpool_future_cancellation.py
Last active February 6, 2021 04:59
Cancellation on run_in_executor using ThreadPoolExecutor
"""
A demonstration on how raising KeyboardInterrupt in the context of tasks
spawned via asyncio's loop.run_in_executor does not cancel the threads
using any of the cancellation methods in asyncio Futures.
The only "proper" way to cancel is to:
1. unregister the `atexit` registered `_python_exit` function
2. call `shutdown(wait=False)`
The reason is that the `thread` module registers `_python_exit` forcing a
@wolfv
wolfv / multiple_dispatch.py
Last active November 20, 2018 18:08
A Taste Of Julia / C++ in Python – simple Python multiple dispatch from type hints
from typing import *
import re
def to_regex(typevar, groups):
def to_matchgroup(arg, groups):
if type(arg) is TypeVar:
if arg in groups:
return "(?P={})".format(arg.__name__)
else:
groups |= {arg}
@AppMkrATL
AppMkrATL / almost-ascii-deletion-distance.py
Created September 19, 2018 01:20 — forked from fish2000/almost-ascii-deletion-distance.py
Almost ASCII Deletion Distance
def ascii_deletion_distance(str1, str2):
from collections import defaultdict
histogram = defaultdict(int)
for ch in str1:
histogram[ch] += 1
for ch in str2:
histogram[ch] += 1
union = set(str1) | set(str2)
intersection = set(str1) & set(str2)
result = union - intersection