Skip to content

Instantly share code, notes, and snippets.

View MattOates's full-sized avatar

Matt Oates MattOates

View GitHub Profile

Business Plan: Privy - Revitalizing Public Facilities

Executive Summary

Privy aims to reinvent public sanitation facilities by offering a subscription-based service to access clean, well-maintained, and technologically advanced toilets and showers. Our mission is to uphold hygiene standards while enhancing the convenience and security of using public utilities.

Company Description

Privy is an emerging company that focuses on improving the sanitation landscape in urban areas. With the view that hygiene is a right, not a privilege, we intend to facilitate cleaner and more accessible toilets and showers through a subscription model. Our model ensures privacy, hygiene, and ease of access via a smartphone app.

@MattOates
MattOates / base.py
Created December 13, 2020 13:00
Attempt to make a nice Tortoise BaseModel to work with FastAPI
from typing import (
Type,
Optional,
)
from tortoise.models import Model
from tortoise.contrib.pydantic import (
pydantic_model_creator,
PydanticModel,
)
@MattOates
MattOates / observable.py
Last active July 24, 2020 13:04
Observer pattern in Python, but has some annoying problems with respect to mypy typing
from typing import Any, Callable, Dict, List, Optional, Set
from abc import ABC, abstractmethod
import logging
LOGGER = logging.getLogger(__name__)
class Observer(ABC):
@abstractmethod
def update(self, observed: "Observable", event: Any) -> None:
things = {"hi":10,"bye":3}
def flatten_counter(counter):
for value, count in counter.items():
for i in range(count):
yield value
print(list(flatten_counter(things)))
@MattOates
MattOates / collatz_numba.py
Last active February 26, 2020 13:41
Helper functions for investigating the collatz graph and paths
#!/usr/bin/env python3
import numpy as np
from numba import njit, uint64
from numba.typed import Dict
collatz_graph = Dict.empty(key_type=uint64, value_type=uint64)
collatz_path_lengths = Dict.empty(key_type=uint64, value_type=uint64)
def collatz(n: uint64, collatz_graph: Dict, collatz_path_lengths: Dict):
# collatz_path_lengths[n] = collatz_iter(n, collatz_graph)
@MattOates
MattOates / collatz.py
Created February 26, 2020 10:03
Some functions for exploring the Collatz graph
from typing import Dict
import numpy as np
collatz_graph: Dict[int, int] = dict()
collatz_path_lengths: Dict[int, int] = dict()
def collatz(n: int):
collatz_path_lengths[n] = collatz_iter(n)
return collatz_path(n)
@MattOates
MattOates / descriptor_typing_problem.py
Last active February 17, 2020 16:52
The general problem is that mypy doesn't really understand that a descriptor on an attribute is going to have the return value of __get__ not __call__/__init__
"""
If you run the following with mypy you will get the following type error
mypy descriptor_typing_problem.py
descriptor_typing_problem.py:36: error: Incompatible types in assignment (expression has type "attr_descriptor", variable has type "int")
"""
from enum import Enum
from typing import Type, Any
Sentinels = Enum("Sentinels", "NO_INIT")
@MattOates
MattOates / descriptor_typing_problem.py
Created February 17, 2020 16:37
The general problem is that mypy doesn't really understand that a descriptor on an attribute is going to have the return value of __get__ not __call__/__init__
from enum import Enum
from typing import Type, Any
Sentinels = Enum("Sentinels", "NO_INIT")
class attr_descriptor:
def __init__(self, default=Sentinels.NO_INIT):
self.default = default
@MattOates
MattOates / mandelbrot.pl6
Last active February 9, 2020 23:00
Dirty script to render the Mandelbrot set to the terminal
sub terminal-width(:$default=100) {
my $width = run('tput', 'cols', :out).out.slurp-rest.trim.Int;
return $width < $default ?? $default !! $width;
}
sub is-mandelbrot(Complex $z0, int $max=100) {
my Complex $z = $z0;
for ^$max -> $n {
return $n if ($z.abs() > 2e0);
$z = $z**2 + $z0;
from typing import NamedTuple
import json
class NamedTupleJSONEncoder(json.JSONEncoder):
def encode(self, o):
print(f"Encoding {type(o)}")
return super().encode(o)