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 vector.rs
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7fe5dd26135d20297441093328c545c5
use std::ops::Add;
pub struct Vector<T, const LEN: usize>
where
[T; LEN]:,
{
elements: [T; LEN],
}
@matthewjberger
matthewjberger / instructions.md
Created Sep 6, 2022
Cross compile rust code for linux from windows
View instructions.md

Start docker, then run:

cargo install cross --git https://github.com/cross-rs/cross
cross build --target aarch64-unknown-linux-gnu
View cooleffect.wgsl
@fragment
fn fragment_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(0.2, sin(in.position.x), 0.5, 1.0);
}
@matthewjberger
matthewjberger / forward-plus.md
Last active Sep 3, 2022
Forward plus renderer explanation, summarizing ideas from https://github.com/bcrusco/Forward-Plus-Renderer
View forward-plus.md

Main

Load depth shader

Load light culling shader

Load light accumulation shader

Load HDR shader

View rr-with-rust.md

using rust with rr

rr is a great debugging tool. it records a trace of a program's execution, as well as the results of any syscalls it executes, so that you can "rewind" while you debug, and get deterministic forward and reverse instrumented playback. it works with rust, but by default if you try it out, it could be pretty ugly when you inspect variables. if this bothers you, configure gdb to use a rust pretty-printer

rr is probably in your system's package manager.

usage

View explanation.md

Let's break it down! 🚀

First let's look at where disconnect_receiver is declared.

let (disconnect_sender, mut disconnect_receiver) = mpsc::unbounded::<(String, Receiver<String>)>();

disconnect_receiver is an UnboundedReceiver

@matthewjberger
matthewjberger / main.rs
Created Aug 19, 2022
TCP roundtrip using async_std
View main.rs
use anyhow::Result;
use async_std::{
io,
net::{TcpListener, TcpStream},
prelude::*,
task,
};
fn main() -> Result<()> {
task::spawn(async move {
View main.rs
#[repr(u8)]
pub enum Opcode {
Null,
First,
}
fn main() {
println!("0b{:08b}", Opcode::First as u8);
}
@matthewjberger
matthewjberger / dump-github-context.md
Created Jul 28, 2022
Dump github context in a github action
View dump-github-context.md

To dump github context in a github action:

   - name: Dump Github context
        env:
          GITHUB_CONTEXT: ${{ toJSON(github) }}
        run: echo "$GITHUB_CONTEXT"
@matthewjberger
matthewjberger / convert.ts
Created Jul 26, 2022
convert a timestream query result to a mui-x datagrid compatible format
View convert.ts
private normalizeQueryOutput = (output: QueryCommandOutput) => {
const columns =
output.ColumnInfo?.map((column) => {
const name = column.Name ?? "Unknown"
return {
field: name,
headerName: name,
flex: 1,
}
}) ?? []