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 / 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 / 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 / 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 / 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
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))
@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 / demo.cs
Created August 21, 2019 17:42
Simple layout anchor example
faceContainingImage.Image = UIImage.FromFile("docs.jpg");
//Put it on the screen
View.AddSubview(faceContainingImage);
faceContainingImage.TranslatesAutoresizingMaskIntoConstraints = false;
var dpConstraints = new[]
{
faceContainingImage.LeadingAnchor.ConstraintEqualTo(View.LayoutMarginsGuide.LeadingAnchor),
faceContainingImage.TrailingAnchor.ConstraintEqualTo(View.LayoutMarginsGuide.TrailingAnchor),
faceContainingImage.TopAnchor.ConstraintEqualTo(View.LayoutMarginsGuide.TopAnchor, 40.0f),
@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 / inner.fs
Created August 13, 2019 22:31
InnerXML in F#
let innerXml (node : XNode ) =
use rdr = node.CreateReader()
rdr.MoveToContent() |> ignore
rdr.ReadInnerXml()
@lobrien
lobrien / xor.py
Created August 13, 2019 22:29
Keras XOR
import numpy as np
from keras.models import Sequential
from keras.layers.core import Activation, Dense
from keras.optimizers import SGD
# Allocate the input and output arrays
X = np.zeros((4, 2), dtype='uint8')
y = np.zeros(4, dtype='uint8')
# Training data X[i] -> Y[i]