Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am dfee on github.
  • I am dfee (https://keybase.io/dfee) on keybase.
  • I have a public key ASC0E1cJpr9CJuyKtMmAVBusRIYT8HnmxIhUHRxeUWy5wAo

To claim this, I am signing this object:

@dfee
dfee / README.md
Last active April 27, 2018 09:04
Signature 2

signature pt. 2

consideration:

  • optional is a validator / converter in attrs
  • is Missing appropriate here? ... it is handled as a default param for inspect.Parameter
  • naming of constructors: sig.arg(), sig.args, sig.kwarg, sig.kwargs()
  • ... and package signature
  • should sig.args be passed out as args, kwargs, or is this an option for end users?

next:

@dfee
dfee / README.md
Created April 27, 2018 01:16
manifest_vk: convert **kwargs to explicit keyword arguments

Python: make explicit variable keywords in a function's signature

Python functions can take a variable keyword parameter, often known as **kwargs.

def myfunc(**kwargs):
    print(kwargs)

> myfunc(a=1, b=2)
{'a': 1, 'b': 2}
class stackify(object):
"""Wrapper for stack-based recursion with memoisation
When the function is called and argument is not in cache, push it to stack
Attempt to call the function on the arguments in the stack such that an
exception is raised if the function tries to recurse. In that case, add the
function argument to the stack and continue
The order of successful arguments also provides a topological sort
import asyncio
from inspect import iscoroutinefunction
import pytest
import rx
# pylint: disable=W0621, redefined-outer-name
def debug(value):
@dfee
dfee / graphene_subscription.py
Created November 25, 2017 03:17
Example of how subscriptions work with graphene
from collections import OrderedDict
import graphene
import rx
subject = rx.subjects.Subject()
class Author(graphene.ObjectType):
@dfee
dfee / Dockerfile
Last active March 12, 2018 10:36
Debian Dockerfile with pyenv, a default python, and pipenv.
FROM debian:stable
ARG PYTHON_VERSION=3.6.2
### Setup python:{version} ###
# helpful links:
# https://github.com/pyenv/pyenv/wiki/Common-build-problems
# https://github.com/pyenv/pyenv/blob/32922007863c4a54feca2a95226c8307cfdfea3d/plugins/python-build/README.md
# https://github.com/pyenv/pyenv/issues/990
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
@dfee
dfee / setup.oy
Created September 24, 2017 08:06
from setuptools import setup, find_packages
setup(
name='server',
version='0.1',
packages=find_packages(),
include_package_data=True,
install_requires=[
'aiohttp',
# 'aiohttp-graphql',
@dfee
dfee / executor.py
Last active May 17, 2017 22:41
Guarding functions in asphalt that should only run in an executor.
import asyncio
from asphalt.core import Context
import functools
def guard_executor(func):
no_ctx_msg = ('Context must be the first arg, or an instance variable of '
'`self` (if wrapping an instance method).')
not_in_executor_msg = '{} must be run in an executor'.format(func.__name__)
@dfee
dfee / ip_regex.py
Last active December 7, 2023 19:39
Python IPV4 / IPV6 Regular Expressions (REGEX)
# Constructed with help from
# http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
# Try it on regex101: https://regex101.com/r/yVdrJQ/1
import re
IPV4SEG = r'(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])'
IPV4ADDR = r'(?:(?:' + IPV4SEG + r'\.){3,3}' + IPV4SEG + r')'
IPV6SEG = r'(?:(?:[0-9a-fA-F]){1,4})'
IPV6GROUPS = (