Skip to content

Instantly share code, notes, and snippets.

View MattOates's full-sized avatar

Matt Oates MattOates

View GitHub Profile
@MattOates
MattOates / template
Created September 17, 2025 16:12
A template standalone script that has some testing and can be shipped as a single file readily
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = ["typer", "pytest"] # keep this minimal; add libs you actually use
# ///
# -*- coding: utf-8 -*-
from pathlib import Path
import typer
@MattOates
MattOates / find-primes.p6
Last active May 19, 2024 19:41
Combined primes benchmark with a parallel implementation that does well to keep up despite doing a lot more calculations!
#!/usr/bin/env perl6
use v6;
use Stats;
sub bench(Str $name, Int $upto, &code) {
my ($start,$end);
my @times;
for 1..20 {

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.

#include "DigiKeyboard.h"
//Command key is ord 37 and as a modifier 0x00000008
//See NX_DEVICELCMDKEYMASK http://svn.red-bean.com/bob/SDL-altivec/trunk/src/video/quartz/SDL_QuartzEvents.m
//For a look at available keys https://github.com/digistump/DigisparkArduinoIntegration/blob/master/libraries/DigisparkKeyboard/DigiKeyboard.h
#define MOD_CMD_LEFT 0x00000008
boolean do_hack = true;
void setup() {
@MattOates
MattOates / sqlitemagic.py
Last active December 23, 2021 16:40
Magical SQLite dumping directly over a pipe to the sqlite3 command line client, the .import command is roughly 5x faster at dumping data than using the Python SQLite bindings and doing looped inserts.
#!/usr/bin/env python
import os, sys, tempfile, csv
import re, inspect, ast
from subprocess import Popen, PIPE, STDOUT
"""
Class for dumping data into a SQLite database.
You will need the sqlite3 command line client in your PATH,
even if you are on Windows and not UNIX (maybe)
@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)