Skip to content

Instantly share code, notes, and snippets.

Programming something in Rust, probably

Matthew J. Berger matthewjberger

Programming something in Rust, probably
View GitHub Profile
/// A compact graph representation. Edges are numbered in order of insertion.
/// Each adjacency list consists of all edges pointing out from a given vertex.
pub struct Graph {
/// Maps a vertex id to the first edge in its adjacency list.
first: Vec<Option<usize>>,
/// Maps an edge id to the next edge in the same adjacency list.
next: Vec<Option<usize>>,
/// Maps an edge id to the vertex that it points to.
endp: Vec<usize>,
matthewjberger /
Created February 17, 2023 02:00
Shepmaster's rust test timeout solution
use std::{sync::mpsc, thread, time::Duration};
fn oops() {
panic_after(Duration::from_millis(100), || {
fn panic_after<T, F>(d: Duration, f: F) -> T
matthewjberger / most-lines-added.ps1
Created February 16, 2023 08:05
Get the commit for a specific user that added more lines than all other commits
View most-lines-added.ps1
git log --shortstat --author="Matthew J. Berger" --pretty=format:"%H - %an, %ar : %s" | foreach {
if ($_ -match '([0-9a-fA-F]{40})') {
$commitHash = $matches[1]
if ($_ -match '(\d+)\s+insertion\S*.*(\d+)\s+deletion\S*') {
$insertions = [int]$matches[1]
$deletions = [int]$matches[2]
CommitHash = $commitHash
Insertions = $insertions
matthewjberger / Cargo.toml
Last active February 11, 2023 22:27
Async winit
View Cargo.toml
name = "window"
version = "0.1.0"
edition = "2021"
winit = "0.28.1"
async-std = "1.10.0"
matthewjberger /
Last active February 11, 2023 02:01
layered architecture in rust
// Layer 1: Domain
pub struct User {
pub id: i32,
pub name: String,
pub email: String,
// Layer 2: Data Access
pub trait UserRepository {
matthewjberger /
Created February 8, 2023 15:01
Monitor udev
udevadm monitor
matthewjberger /
Last active February 3, 2023 06:35
Tips for debugging a systemd unit
# Check the systemd journal for mentions of my-service
journalctl | grep -i my-service
# Show the status of the service
systemctl status my-service
# Service is at /lib/systemd/system/my-service.service
# After editing unit file on disk, reload the units
systemctl daemon-reload
matthewjberger /
Created January 30, 2023 23:37
Extract runtime device tree for viewing
dtc -I fs -O dts -s /proc/device-tree -o flattened.dts
matthewjberger /
Created January 30, 2023 23:29
list all available kernel modules (lsmod only shows loaded modules)
find /lib/modules/$(uname -r) -type f -name '*.ko*'

How to patch the device tree for a custom RPI CM4 board

Locating the kernel source

Run devtool modify linux-raspberrypi from the same shell you run bitbake my-image from. The kernel source tree will be copied to build/workspace/sources/linux-raspberrypi.

Make edits to the device tree at build/workspace/sources/linux-raspberrypi/arch/arm/boot/dts/bcm2711-rpi-cm4.dts and then run git diff > 0001-my-patch-description.patch.

Getting the name of the kernel recipe