Skip to content

Instantly share code, notes, and snippets.

View matthewjberger's full-sized avatar

Matthew J. Berger matthewjberger

View GitHub Profile
@matthewjberger
matthewjberger / wasm.md
Last active November 19, 2023 23:05
Check if a rust crate is compatible with wasm + tips

Does it build in wasm?

cargo build --target wasm32-unknown-unknown

How do I specify crates just for the wasm target?

Here's an example using legion:

@matthewjberger
matthewjberger / semantic.rs
Created November 13, 2023 07:39
semantic version
use std::convert::TryFrom;
use std::num::ParseIntError;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
struct SemanticVersion {
major: u32,
minor: u32,
patch: u32,
}
@matthewjberger
matthewjberger / nodegraph.rs
Last active November 3, 2023 13:38
Nodegraph V2
use petgraph::graphmap::DiGraphMap;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, error::Error, fmt, hash::Hash};
#[derive(Debug)]
pub struct NodeGraphError {
details: String,
}
impl NodeGraphError {
fn contains_single_num_in_range(s: &str, section_index: usize, min: u8, max: u8) -> Option<u8> {
s.split('/')
.nth(section_index)?
.split('-')
.filter_map(|part| part.parse::<u8>().ok())
.find(|&num| (min..=max).contains(&num))
}
#[cfg(test)]
mod tests {
use petgraph::{graph::NodeIndex, prelude::*};
use std::ops::{Index, IndexMut};
pub trait Aggregatable: Clone + PartialEq + std::fmt::Debug {
fn aggregate(&self, parent: &Self) -> Self;
}
// The SceneGraph is now generic over the type of the transform
#[derive(Default)]
pub struct SceneGraph<T: Aggregatable>(pub Graph<T, ()>);
// ===========================
// Approach 1: Direct Function
// ===========================
struct DirectProcessor {
process: fn() -> &'static str,
}
impl DirectProcessor {
fn process_data() -> &'static str {
@matthewjberger
matthewjberger / DisplayFonts.ps1
Created July 29, 2016 16:20
PowerShell Font Listing
# From https://technet.microsoft.com/en-us/library/ff730944.aspx
# This will open an internet explorer window that will display all installed windows font names in their corresponding font.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$objFonts = New-Object System.Drawing.Text.InstalledFontCollection
$colFonts = $objFonts.Families
$objIE = New-Object -com "InternetExplorer.Application"
$objIE.Navigate("about:blank")
$objIE.ToolBar = 0
//! Tokio Async Topic-based Pub/Sub Messaging
//!
//! This module provides a broker-client communication system where
//! multiple clients can communicate with each other through a central broker.
//! The broker is responsible for routing messages between clients based on topics.
//!
//! # Structures
//!
//! - `Broker`: Represents the central message router. It manages topics and routes messages between subscribers.
//! - `Client`: Represents a client that can subscribe to topics, send, and receive messages through the broker.
@matthewjberger
matthewjberger / main.rs
Created September 30, 2023 16:37
Use serde Serialize and Deserialize attributes as re-exports
// From: https://github.com/serde-rs/serde/issues/1465#issuecomment-800686252
use common::serde::{self, Deserialize, Serialize}
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
#[serde(crate = "self::serde")] // must be below the derive attribute
struct Vertex {
position: [u32; 3],
}
@matthewjberger
matthewjberger / cargo.toml
Created June 6, 2018 04:51
SDL2/OpenGl in Rust
[package]
name = "chapter-01"
version = "0.1.0"
authors = ["Matthew J. Berger <matthewberger@nevada.unr.edu>"]
[dependencies]
gl = "0.10.0"
[dependencies.sdl2]
version = "0.31.0"