Skip to content

Instantly share code, notes, and snippets.

View kmdouglass's full-sized avatar

Kyle M. Douglass kmdouglass

View GitHub Profile
@kmdouglass
kmdouglass / create_image.sh
Created March 25, 2018 12:06
Creates a chroot environment for creating custom Raspbian images and cross-compiling programs for the Raspberry Pi.
#!/bin/bash
# Creates a custom Raspbian image and cross-compilation environment.
#
# USAGE: ./create_image.sh
#
# This script must be run as either root or sudo.
#
# After creating the chroot environment, the script specified in the
# *script* variable will be executed from within the chroot. Your
# custom system setup commands should be located here. For example,
@kmdouglass
kmdouglass / copy-vs-move.rs
Created November 24, 2019 09:44
Variable locations in memory during copy and move operations in Rust
//! Demonstrates memory layout using copy and move semantics in Rust.
//!
//! # Examples
//!
//! The memory locations that you see by running this program will almost certainly be different
//! than what is found in the examples below. The important thing to pay attention to is the memory
//! location of the variable `x`.
//!
//! ```console
//! $ cargo run --release -- --copy
@kmdouglass
kmdouglass / safe_round.py
Created August 26, 2022 18:49
Round a list of floats to ints so that the sum of the ints is the integer portion of the sum of the floats
def safe_round(array: npt.ArrayLike, total: int) -> np.ndarray:
"""Rounds an array of floats, maintaining their integer sum."""
array = np.asanyarray(array)
# Round the array to the nearest integer
rounded_array: np.ndarray = np.rint(array)
error = total - np.sum(rounded_array)
if error == 0:
return rounded_array
@kmdouglass
kmdouglass / eda-simulator.py
Last active August 3, 2023 07:51
Reactive acquisitions with pymmcore-plus
"""Simple simulator demonstrating event-driven acquisitions with pymmcore-plus"""
from logging import getLogger
from queue import Queue
import random
import time
from typing import Any, Iterable
from pymmcore_plus import CMMCorePlus
from useq import MDAEvent
@kmdouglass
kmdouglass / acquire.py
Created July 4, 2024 15:24
A simple live image viewer for imaging experiments
"""Simulates image acquisiton and a live display of the images."""
from dataclasses import dataclass
import multiprocessing as mp
from multiprocessing.connection import PipeConnection
import time
from matplotlib import pyplot as plt
import numpy as np