Skip to content

Instantly share code, notes, and snippets.

View matthewjberger's full-sized avatar

Matthew J. Berger matthewjberger

View GitHub Profile
@matthewjberger
matthewjberger / message.rs
Created September 4, 2024 20:54
Pub/sub broker messaging in-process without an async executor using Send + Sync compatible types
use std::{
collections::HashMap,
sync::{Arc, RwLock, Weak},
};
use std::{
collections::VecDeque,
sync::{RwLockReadGuard, RwLockWriteGuard},
};
use uuid::Uuid;
@matthewjberger
matthewjberger / Cargo.toml
Last active August 28, 2024 15:09
Framegraphs in rust
[package]
name = "framegraph-system"
version = "0.1.0"
edition = "2021"
[dependencies]
petgraph = "0.6.3"
wgpu = "0.15"
pollster = "0.3"
@matthewjberger
matthewjberger / main.rs
Created August 27, 2024 16:52
Rust Job Graphs
// [dependencies]
// futures = "0.3.30"
// petgraph = "0.6.5"
// tokio = { version = "1.39.3", features = ["full"] }
use futures::future::join_all;
use petgraph::graph::{DiGraph, NodeIndex};
use std::{
collections::HashMap,
sync::{Arc, Mutex},
@matthewjberger
matthewjberger / shader.glsl
Created August 24, 2024 19:33
cube shader for shadertoy
#define MAX_STEPS 100
#define MAX_DIST 100.0
#define SURF_DIST 0.001
// Camera variables
vec3 cameraPos;
vec3 cameraTarget;
float cameraZoom = 5.0;
mat3 getCameraRotation(vec2 angle) {
@matthewjberger
matthewjberger / mapping.rs
Created August 21, 2024 03:38
serde_json error impl From<> in rust
impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
let class = match value.classify() {
serde_json::error::Category::Io => "io",
serde_json::error::Category::Syntax => "syntax",
serde_json::error::Category::Data => "data",
serde_json::error::Category::Eof => "eof",
};
Error::Deser {
@matthewjberger
matthewjberger / Cargo.toml
Created August 19, 2024 10:49
Standalone Winit Wgpu/Triangle
[package]
name = "app"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
path = "src/lib.rs"
name = "app_core"
@matthewjberger
matthewjberger / main.rs
Last active August 12, 2024 19:32
Alternatives to drain to preventable multiple mutable refs to self
use std::collections::VecDeque;
#[derive(Debug, Clone)]
struct Event(u32);
struct Context {
queued_events: VecDeque<Event>,
}
impl Context {
@matthewjberger
matthewjberger / main.rs
Created August 6, 2024 01:34
Analysis of how embassy uses rust types for pins and peripherals
use std::sync::atomic::{AtomicBool, Ordering};
use std::marker::PhantomData;
// Simulate hardware-specific types
mod hal {
pub mod peripherals {
pub struct TIMER0;
pub struct UART0;
pub struct GPIO;
@matthewjberger
matthewjberger / sync-main.rs
Last active August 4, 2024 09:59
Teleport interactively in rust
// thiserror = "1.0.63"
use std::{
io::{BufRead, BufReader, Write},
process::{Child, Command, Stdio},
sync::{
mpsc::{self, Sender},
Arc, Mutex,
},
thread,
time::Duration,
@matthewjberger
matthewjberger / Justfile
Created August 1, 2024 08:06
A rust justfile with common commands
set windows-shell := ["powershell.exe"]
export RUST_LOG := "info"
export RUST_BACKTRACE := "1"
@just:
just --list
build:
cargo build -r