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
@matthewjberger
matthewjberger / systemd.sh
Last active Feb 3, 2023
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 Jan 30, 2023
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 Jan 30, 2023
list all available kernel modules (lsmod only shows loaded modules)
View list.sh
find /lib/modules/$(uname -r) -type f -name '*.ko*'
@matthewjberger
matthewjberger / instructions.md
Last active Jan 30, 2023
Install a nerd font on ubuntu
View instructions.md

1.) Download a Nerd Font

2.) Unzip and copy to ~/.fonts

3.) Run the command fc-cache -fv to manually rebuild the font cache

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

@matthewjberger
matthewjberger / instructions.md
Last active Jan 23, 2023
Setting up GPG with git for signed commits
View instructions.md
# Generate a key
# RSA and RSA
# 4096 bits
# Email from your .gitconfig
gpg --full-generate-key

# List key information
gpg --keyid-format LONG -k
@matthewjberger
matthewjberger / default-branch-rename.md
Created Jan 22, 2023
Instructions for syncing a local repo after a branch has been renamed upstream
View default-branch-rename.md

The default branch has been renamed! develop is now named main

If you have a local clone, you can update it by running the following commands.

git branch -m develop main git fetch origin git branch -u origin/main main git remote set-head origin -a

View builder.rs
fn main() {
let topic = TopicBuilder::new("lift", "report")
.with_subdevices(&["motor"])
.build();
println!("Topic: {:#?}", &topic);
}
#[derive(Debug)]
pub struct Topic {
display: String,
@matthewjberger
matthewjberger / state.rs
Created Jan 9, 2023
A generic state machine pattern in Rust
View state.rs
use thiserror::Error;
#[derive(Error, Debug)]
pub enum StateMachineError {
#[error("No states are present in the state machine.")]
NoStatesPresent,
}
type Result<T, E = StateMachineError> = std::result::Result<T, E>;
@matthewjberger
matthewjberger / profiling.rs
Last active Jan 7, 2023
A rust profiling macro
View profiling.rs
// let (entities, duration) = profile!(world.create_entities(1_000_000));
// println!("Creating 1 million entities completed in {:?}", duration);
//
// let results: Vec<(_, Duration)> = profile_n!(100, world.create_entities(1_000_000));
#[macro_export]
macro_rules! profile {
($($actions:tt)*) => {
{
let start = std::time::Instant::now();