Skip to content

Instantly share code, notes, and snippets.

View lobrien's full-sized avatar
💭
About 7,000 miles away from lounge access.

Larry O'Brien lobrien

💭
About 7,000 miles away from lounge access.
View GitHub Profile
@lobrien
lobrien / led_segs.py
Last active April 9, 2024 09:59
Keras neural net that recognizes number in a 7-segment display
import numpy as np
from keras.models import Sequential
from keras.layers.core import Activation, Dense
from keras.optimizers import SGD
# Trains a neural net that recognizes the digit displayed by a 7-segment LED:
# "Lit segments" are indexed as:
# -- 0 --
# | |
# 1 2
@lobrien
lobrien / dockerfile
Created November 23, 2023 21:16
Dockerfile for FIRST Robotics with PyTorch, robotpy and Jupyter Server
#FROM bitnami/pytorch:latest
# Use Ubuntu as base image because Debian doesn't have g++-11, required by robotpy
FROM anibali/pytorch:2.0.1-cuda11.8
USER root
# Update the system and install basic dev packages
RUN apt-get update && apt-get install -y binutils gcc g++ make git wget libicu-dev gradle && \
apt install -y openjdk-11-jdk vim software-properties-common gnupg
# Install additional Python packages
@lobrien
lobrien / kmeans.py
Created August 13, 2019 22:28
k-means clustering 1d data
from sklearn.cluster import KMeans
import numpy as np
data = np.array([101, 107, 106, 199, 204, 205, 207, 306, 310, 312, 312, 314, 317, 318, 380, 377, 379, 382, 466, 469, 471, 472, 557, 559, 562, 566, 569])
kmeans = KMeans(n_clusters=5).fit(data.reshape(-1,1))
kmeans.predict(data.reshape(-1,1))
# array([4, 4, 4, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3,
# 3, 3, 3, 3], dtype=int32)
@lobrien
lobrien / apriltag_capture.py
Last active January 12, 2023 19:02
Apriltag Webcam Capture in Python
import cv2
import robotpy_apriltag
from wpimath.geometry import Transform3d
import math
# This function is called once to initialize the apriltag detector and the pose estimator
def get_apriltag_detector_and_estimator(frame_size):
detector = robotpy_apriltag.AprilTagDetector()
# FRC 2023 uses tag16h5 (game manual 5.9.2)
assert detector.addFamily("tag16h5")
@lobrien
lobrien / capture.cs
Last active December 21, 2022 17:23
High Performance CVPixelBuffer capture in Xamarin
Video Capture
previewLayer = new AVCaptureVideoPreviewLayer(captureSession);
//previewLayer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill;
previewView.Layer.AddSublayer(previewLayer);
previewView.TranslatesAutoresizingMaskIntoConstraints = false;
var previewConstraints = new[]
{
previewView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor),
previewView.RightAnchor.ConstraintEqualTo(View.RightAnchor),
@lobrien
lobrien / gist:e1283e86fef5a280d52e390c176efedd
Last active November 14, 2022 18:14
Avg & std dev for Wordle
import numpy as np
rs = np.array([ [1,1], [2, 11], [3, 77], [4, 111], [5, 74], [6, 20], [7.25, 6]])
vs = rs.take(indices = 0, axis=1)
ns = rs.take(indices = 1, axis=1)
mean = np.average(vs, weights = ns)
sd = np.sqrt(np.average((vs - mean)**2, weights=ns))
(mean, sd)
@lobrien
lobrien / action.yml
Created October 24, 2019 17:09
Inline Python Action
on: push
name: Inline Python Action
jobs:
my-job:
name: My job
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
@lobrien
lobrien / dockerfile
Created June 18, 2021 02:09
Detectron2 CPU-Only Torch 1.7 Dockerfile
# Update of the Dockerfile at https://towardsdatascience.com/detectron2-the-basic-end-to-end-tutorial-5ac90e2f90e3
FROM python:3.8-slim-buster
RUN apt-get update -y
# gcc compiler and opencv prerequisites
RUN apt-get -y install nano git build-essential libglib2.0-0 libsm6 libxext6 libxrender-dev
RUN apt-get install -y python3-opencv
# Detectron2 prerequisites
@lobrien
lobrien / FlexLayoutOptions.workbook
Last active May 6, 2021 00:47
Xamarin.Forms FlexLayout Major Steps
uti id title platforms packages
com.xamarin.workbook
7e650a9b-4216-4b28-945c-217cd85530b2
FlexLayout Options
Android
id version
Xamarin.Forms
3.0.0.482510
import nltk
nltk.download('words')
from nltk.corpus import words
tetrawords = set(w for w in words.words() if len(w) == 4)
from constraint import *
wordladder = Problem()
for v in ['b','c','d','e','f','g','h'] :
wordladder.addVariable(v, Domain(tetrawords))