Skip to content

Instantly share code, notes, and snippets.

View rmorshea's full-sized avatar

Ryan Morshead rmorshea

View GitHub Profile
@rmorshea
rmorshea / idom_snake.py
Created February 28, 2019 22:47
The game Snake implemented in Python with iDOM (https://github.com/rmorshea/idom)
import idom
import enum
import time
import random
import asyncio
class WASD(enum.Enum):
w = (-1, 0)
@rmorshea
rmorshea / voluptuous_model.py
Last active January 17, 2019 21:14
Voluptuous sphinx documentation model.
# Copyright (c) 2019 by Cisco Systems, Inc.
from voluptuous import Schema, All
from collections import Mapping
from abc import ABCMeta
from typing import Dict, Any
class MetaModel(ABCMeta):
def __init__(self, name, bases, attrs):
attr_validators = self._attribute_validators.copy()
@rmorshea
rmorshea / component_application.py
Created December 15, 2018 18:31
component_application
import inspect
from weakref import finalize
class Component:
def _prepare(self):
pass
def _require(self):
@rmorshea
rmorshea / schema_compose.py
Created October 9, 2018 00:00
Compose two or more schemas into one - see https://github.com/keleshev/schema/pull/169 for details.
from schema import Schema, _priority, DICT, Optional
def compose(*schemas, **kwargs):
"""Compose two or more schemas into one.
See https://github.com/keleshev/schema/pull/169 for details.
"""
reduce = kwargs.pop("reduce", lambda schemas: schemas[0])
if not callable(reduce):
@rmorshea
rmorshea / actively.py
Created July 26, 2017 19:58
A single file module for creating staged actions.
import six
import inspect
class MetaEngine(type):
def __init__(cls, name, bases, classdict):
cls._cycle = []
rotation = cls.next_rotation(None)
while rotation is not None:
cls._cycle.append(rotation)
@rmorshea
rmorshea / metasuper.py
Last active May 26, 2016 02:42
call methods of a parent class during class construction.
import inspect
def metamethod(cls, name):
"""Get a method owned by a metaclass
The method is retrieved from the instantiating metaclass.
Parameters
----------
cls: class