Skip to content

Instantly share code, notes, and snippets.

keep on truckin'

Alec Nikolas Reiter justanr

keep on truckin'
Block or report user

Report or block justanr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
justanr /
Last active Apr 16, 2018
Setting up deprecations of Pluggy Hooks
import sys
import warnings
import inspect
from pluggy import HookimplMarker, HookspecMarker, PluginManager, _HookCaller, normalize_hookimpl_opts, HookImpl
class MetadataHookspecMarker(HookspecMarker):
Allows storing arbitrary metadata on the hookspec options
instead of what Pluggy sets by default.
from abc import ABCMeta, abstractmethod
ABC = ABCMeta('ABC', (object,), {})
class ConversionStrategy(ABC):
def convert(self, a):
raise NotImplementedError
class IntegerConversionStrategy(ConversionStrategy):
from datetime import datetime
class UncleVernonMiddleware(object):
def __init__(self, app): = app
def __call__(self, environ, start_response):
if environ['REQUEST_METHOD'].lower() == 'post' and == SUNDAY:
justanr /
Last active Jun 15, 2016
Proof of Concept for adding kinda Implicits to Python
class Thing:
def r(self):
class HasWhatever(metaclass=ImplicitMeta, companion=Thing):
whatever = lambda s: print(s, 1)
def nine(self):
return 'nine'
View tox.ini
envlist = cov-init,py27,py34,py35,py36,cov-report
usedevelop = True
setenv =
COVERAGE_FILE = .coverage.{envname}
commands =
py.test --cov={toxinidir}/flask_sleepy --cov-report term-missing
justanr /
Last active Feb 17, 2016
Test Builder
from copy import deepcopy
class Builder(object):
def __init__(self, target, *args, **kwargs):
self._target = target
self._kwargs = kwargs
self._args = list(args)
def having(self, *args, **kwargs):
justanr /
Last active Jul 20, 2016
Example of a small value object representing money.
import decimal
from functools import total_ordering
from numbers import Real
class Context(object):
def __init__(self, **kwargs):
self.context = decimal.Context(**kwargs)
def __enter__(self):
with decimal.localcontext(self.context) as c:
justanr /
Last active Jun 3, 2019
Clean Architecture In Python
from abc import ABC, ABCMeta, abstractmethod
from collections import namedtuple
from itertools import count
PayloadFactory = namedtuple('PayloadFactory', [
'good', 'created', 'queued', 'unchanged', 'requires_auth',
'permission_denied', 'not_found', 'invalid', 'error'
class UserNotFound(Exception):
def by_username(cls, username):
return cls("No user found with username: {0}".format(username))
def find_user(username):
user = User.query.filter_by(username==username).first()
if not user:
raise UserNotFound.by_username(username)
return user
justanr /
Last active Sep 17, 2015
Todo: Support loading from arbitrary data store (yaml, xml, Mongo, etc)
from .command_bus import DefaultCommandBus, ValidatingCommandBus, LoggingCommandBus, SupportsSelfExecution
from .command_name_formatters import (ChangeToOn_CommandName, ChangeToLowerCaseCommandName,
RemoveCommandFromName, MultipleCommandNameFormatter)
from .command_validators import LogsFailedValidationsValidator, GenerousMappingCommandValidator
from .commands import HelloPersonCommand, HelloPersonHandler
from .dependencies import DependencyStore, BasicDependencySatsifier
from .displayer import CallableDisplayer
from .formatter import StringFormatter
from .inflector import (CallableOrNextInflector, DefaultInflector, InstantiatingInflector
CommandNameInflector, MultipleCommandNameInflector, FirstOneWinsInflector)
You can’t perform that action at this time.