Skip to content

Instantly share code, notes, and snippets.

@heathhenley
heathhenley / combos_and_perms.py
Last active February 27, 2025 00:00
A bunch of different simple combination and permutation generators in Python. Yes I know about itertools 😁 just for funsies
from functools import reduce
import itertools
from collections.abc import Generator
def combinations[T](
lst: list[T], k: int, combo: list[T] = None) -> Generator[list[T]]:
""" Yield combinations of the list of size k """
if combo is None:
combo = []
@heathhenley
heathhenley / baud_me_babe.py
Last active February 19, 2025 21:26
Check bauds until it looks like it might be good nmea data
import serial
import serial.tools.list_ports
import sys
# Common NMEA baud rates
BAUD_RATES = [4800, 9600, 38400, 115200]
def main():
# Find available COM ports
ports = [port.device for port in serial.tools.list_ports.comports()]
@heathhenley
heathhenley / aliases.bat
Created February 14, 2025 15:22
Some aliases I like
@echo off
doskey gsu=git status -uno
doskey gs=git status
doskey gpr=git pull -r
doskey gf=git fetch
doskey gc=git commit $*
doskey ga=git add $*
doskey gch=git checkout $*
doskey gka=gitk --all
doskey gla=git log --graph --pretty=format:"%%Cred%%h%%Creset -%%C(yellow)%%d%%Creset %%s %%Cgreen(%%cr) %%C(bold blue)<%%an>%%Creset" --all
@heathhenley
heathhenley / tailrecursionpractice.ipynb
Created November 17, 2024 15:58
TailRecursionPractice.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@heathhenley
heathhenley / tr_examples.ml
Created November 17, 2024 15:38
Learning about tail recursion optimizations in Ocaml
(* Non tail-recursive list len function *)
let rec len lst =
match lst with
| [] -> 0
| _::t -> 1 + len t
(* Tail-recursive list len function *)
let len_tr lst =
let rec len_tr' lst current_len =
match lst with
@heathhenley
heathhenley / remove_file_or_dir.py
Created November 8, 2024 22:37
Remove a file or a directory (even if not empty)
def remove(path: pathlib.Path):
""" Remove a file or non-empty directory.
Unlink only works on files, and rmdir requires the directory to be empty
"""
if not path.is_dir():
path.unlink()
return
for child in path.iterdir():
remove(child)
@heathhenley
heathhenley / acesimulation.ipynb
Last active October 26, 2024 14:58
Expected number of draws - simple case and then for any number of aces for fun
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@heathhenley
heathhenley / acesimulation.ipynb
Created October 25, 2024 21:44
AceSimulation.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@heathhenley
heathhenley / get_signed_url_cloud_run.py
Last active October 23, 2024 20:14
Getting a signed url on cloud run (minor extra auth step)
from datetime import datetime, timedelta, timezone
import google.auth
from google.auth.transport import requests
from google.cloud import storage
def ingest():
"""This endpoint responds with a presigned URL for GCP upload."""
@heathhenley
heathhenley / ace_game.ipynb
Created October 22, 2024 16:35
ace_game.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.