Skip to content

Instantly share code, notes, and snippets.

View davipatti's full-sized avatar

David Pattinson davipatti

  • UW-Madison
  • New York, USA
View GitHub Profile
@davipatti
davipatti / set.py
Created July 21, 2025 12:57
Faffing around with the game 'set'.
#!/usr/bin/env python3
from typing import Generator, Union, Iterable
import random
from itertools import repeat, product
class Set(frozenset):
"""
A 'Set' of cards from the game set. This class is to avoid confusion with the
@davipatti
davipatti / pymc_multilevel_hierarchical_model.py
Created July 11, 2025 16:27
PyMC multilevel hierarchical model #pymc #hierarchical #censored
def titer_hierarchy_model(
df: pd.DataFrame,
l1_name: str = "day",
l2_name: str = "day_size",
transform: Callable = day_size_to_day,
) -> pm.Model:
"""
Args:
df: DataFrame
l1_name: Column that contains the first level.
@davipatti
davipatti / immich.py
Created May 8, 2025 20:47
Fetch a random image from an immich server that contains particular people, resize and pad that image, and return it in a fastapi response. Used for fetching and resizing images to display on a raspberry pi pico which an inky 7.3 e-ink screen.
#!/usr/bin/env python3
from typing import Annotated, Union
import io
import json
import requests
from fastapi import FastAPI, Query
from fastapi.responses import Response
from PIL import Image, ImageOps
@davipatti
davipatti / back-forth.py
Created March 27, 2025 23:55
Increment a counter up and down in marimo.
import marimo
__generated_with = "0.11.30"
app = marimo.App(width="medium")
@app.cell
def _():
import marimo as mo
return (mo,)
~/g/grounding-dino-tiny-ONNX[1]►imxconv-pt -i grounding-dino-tiny-ONNX/onnx/model.onnx -o imx500-conversion ghog-env 1.002s 08:22
2025-03-14 08:22:54,326 INFO : Running version 1.10.0 [~/.virtualenvs/ghog-env/lib/python3.10/site-packages/uni/common/logger.py:148]
2025-03-14 08:22:54,326 INFO : Converting grounding-dino-tiny-ONNX/onnx/model.onnx [~/.virtualenvs/ghog-env/lib/python3.10/site-packages/uni/common/logger.py:148]
2025-03-14 08:22:57,705 ERROR : CODE: [EXEC] 'NoneType' object cannot be interpreted as an integer [~/.virtualenvs/ghog-env/lib/python3.10/site-packages/uni/common/logger.py:160]
Traceback (most recent call last):
File "~/.virtualenvs/ghog-env/lib/python3.10/site-packages/uni/common/main.py", line 143, in execute
g, metadata = self.convert_model(args.input_path, vis_dir)
File "~/.virtualenvs/ghog-env/lib/python3.10/site-packages/uni/common/main.py", line 61, in convert_model
parser = self.get_parser(model_path, vis_dir)
RuleException:
CalledProcessError in file /home/babujee/milkviruses_92224/workflow/irma.smk, line 239:
Command 'set -euo pipefail; cat > results/primary/seq/milkvirus4_S4_combined/aa.fasta' died with <Signals.SIGINT: 2>.
File "/home/babujee/milkviruses_92224/workflow/irma.smk", line 239, in __rule_concat_segment_aa
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
RuleException:
CalledProcessError in file /home/babujee/milkviruses_92224/workflow/irma.smk, line 250:
Command 'set -euo pipefail; cat > results/primary/seq/milkvirus4_S4_combined/nt.fasta' died with <Signals.SIGINT: 2>.
File "/home/babujee/milkviruses_92224/workflow/irma.smk", line 250, in __rule_concat_segment_nt
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
@davipatti
davipatti / gist:f42772a6a1c38fd72fa49ba17616b2b7
Created November 25, 2024 14:40
Python datrie installation failure
Building wheels for collected packages: connection-pool, datrie
Building wheel for connection-pool (setup.py) ... done
Created wheel for connection-pool: filename=connection_pool-0.0.3-py3-none-any.whl size=4062 sha256=3e72f96c62dc89f5af94648812515626414f510305e2ee911aadc70999a2f8fc
Stored in directory: /home/babujee/.cache/pip/wheels/c6/4e/3d/7d5324ada36b1473e54d32916a8f70b90b62c9f2fedc9fd8c9
Building wheel for datrie (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for datrie (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [44 lines of output]
@davipatti
davipatti / pymc-ordered-distributions.ipynb
Created August 27, 2024 20:20
Investigating the behaviour of pymc.distributions.transforms.ordered
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davipatti
davipatti / find_maximal_subsets.py
Created August 14, 2024 16:43
Find maximal subsets
#!/usr/bin/env python3
from collections import defaultdict
from itertools import chain
def find_maximal_subsets(sets: list[set]) -> set[frozenset]:
"""
Find the maximal subsets of items that always appear together in a group of sets.
@davipatti
davipatti / mean-set-containment.py
Created August 14, 2024 13:27
[mean set containment] What is the probability a set of size N contains its mean?
#!/usr/bin/env python3
import random
import matplotlib.pyplot as plt
numbers = tuple(range(100))
def trial(N: int) -> bool:
S = random.choices(numbers, k=N)