Skip to content

Instantly share code, notes, and snippets.

@kronick
kronick / forecast.txt
Created May 13, 2020 19:58
Forecast data
forecast = [
[1, 5.0],
[2, 6.2],
[3, 4.1],
[4, 6.0],
[5, 6.2],
[6, 6.8],
[7, 6.1],
[8, 4.9],
[9, 2.0],
@kronick
kronick / event-sourcing.py
Created July 3, 2019 01:20
Shared Issues Styles
class MaterializedDataAccess:
def __init__(self, eventSource):
# In-memory cache to hold all entity data materialized
# as a projection of the event stream.
# In a real world application, we would probably hydrate this in memory
# with state retrieved from a snapshot stored in a database rather than
# re-building it from the entire event stream history every time the
# application starts up. But if current entity state is a pure function
# of past domain events, there is no reason (performance concerns aside)
# we _couldn't_ hydrate state using only the event history.
@kronick
kronick / rules.py
Created April 25, 2019 21:15
Permissions rules
class Rule:
def __init__(self, type, checkFunction, reasonMessage=None):
# TODO: Perform sanity checks on input types
self.type = type
self.checkFunction = checkFunction
self.reasonMessage = reasonMessage
def check(self, roles, data=None):
# Evaluate check function
try:
@kronick
kronick / permissions.py
Created April 23, 2019 15:21
Permissions
from typing import List, Tuple, Any, Optional, Callable, TypeVar, Dict
""" Permission result is a tuple defining a decision and optional reason string(s) """
PermissionResult = Tuple[bool, Optional[List[str]]]
""" Validation result is a tuple defining a decision and optional error string(s)
Eventually it could return more detailed information about the location of
a validation error. """
ValidationResult = Tuple[bool, Optional[List[str]]]
@kronick
kronick / all-simpsons-tats
Created July 7, 2012 03:37
All possible 4x4 knuckle tattoos using the 5000 most common words spoken on the Simpsons
This file has been truncated, but you can view the full file.
[Word list from http://pastebin.com/anKcMdvk]
kids firm
isnt iron
Word says
mens tips
free luke
gang wash
make card