Skip to content

Instantly share code, notes, and snippets.

Avatar
🦀
Programming something in Rust, probably

Matthew J. Berger matthewjberger

🦀
Programming something in Rust, probably
View GitHub Profile
View adjacency_list.rs
/// 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
matthewjberger / test.rs
Created February 17, 2023 02:00
Shepmaster's rust test timeout solution
View test.rs
use std::{sync::mpsc, thread, time::Duration};
#[test]
fn oops() {
panic_after(Duration::from_millis(100), || {
thread::sleep(Duration::from_millis(200));
})
}
fn panic_after<T, F>(d: Duration, f: F) -> T
@matthewjberger
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]
[pscustomobject]@{
CommitHash = $commitHash
Insertions = $insertions
@matthewjberger
matthewjberger / Cargo.toml
Last active February 11, 2023 22:27
Async winit
View Cargo.toml
[package]
name = "window"
version = "0.1.0"
edition = "2021"
[dependencies]
winit = "0.28.1"
async-std = "1.10.0"
@matthewjberger
matthewjberger / layered.rs
Last active February 11, 2023 02:01
layered architecture in rust
View layered.rs
// Layer 1: Domain
#[derive(Clone)]
pub struct User {
pub id: i32,
pub name: String,
pub email: String,
}
// Layer 2: Data Access
pub trait UserRepository {
@matthewjberger
matthewjberger / udev.sh
Created February 8, 2023 15:01
Monitor udev
View udev.sh
udevadm monitor
@matthewjberger
matthewjberger / systemd.sh
Last active February 3, 2023 06:35
Tips for debugging a systemd unit
View systemd.sh
# 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
matthewjberger / tree.sh
Created January 30, 2023 23:37
Extract runtime device tree for viewing
View tree.sh
dtc -I fs -O dts -s /proc/device-tree -o flattened.dts
@matthewjberger
matthewjberger / list.sh
Created January 30, 2023 23:29
list all available kernel modules (lsmod only shows loaded modules)
View list.sh
find /lib/modules/$(uname -r) -type f -name '*.ko*'
View rpi-yocto.md

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