Skip to content

Instantly share code, notes, and snippets.

View spacejam's full-sized avatar
💭
internet denier

Tyler Neely spacejam

💭
internet denier
View GitHub Profile
@spacejam
spacejam / statem.rs
Created September 25, 2023 09:15
compile-time state transitions
// states:
// A can transition to B.
// B can transition to either A or End.
// End terminates.
#[derive(Debug)]
struct A;
#[derive(Debug)]
struct B;
@spacejam
spacejam / mut_iter.rs
Last active March 29, 2019 07:46
mutable iterator
struct MutableIter<'a, A> {
// reference to underlying buffer
inner: &'a mut [A],
// state to keep track of how far along we are
index: usize,
}
impl<'a, A> Iterator for MutableIter<'a, A> {
// associated types
type Item = &'a mut A;
pub struct Fib16 {
seed: u16,
lfsr: u16,
bit: u16,
}
impl Default for Fib16 {
fn default() -> Fib16 {
Fib16 {
seed: 0xACE1u16,
use std::io::{Result, Read, Write};
use std::net::{TcpListener, TcpStream};
fn handle_client(
mut stream: TcpStream,
state: &mut Vec<String>,
) -> Result<()> {
Ok(())
}
@spacejam
spacejam / playground.rs
Created January 15, 2018 23:35 — forked from anonymous/playground.rs
Rust code shared from the playground
#[macro_use]
extern crate quickcheck;
extern crate rand;
extern crate btree;
use self::quickcheck::{Arbitrary, Gen};
// The maximum key size. keeping it relatively
// small increases the chance of multiple
// operations being executed against the same
@spacejam
spacejam / playground.rs
Last active January 15, 2018 23:46 — forked from anonymous/playground.rs
Rust code shared from the playground
struct Node<K, V>
where
K: Ord
{
key: K,
value: V,
left: Option<Box<Node<K, V>>>,
right: Option<Box<Node<K, V>>>,
}
@spacejam
spacejam / playground.rs
Created January 15, 2018 22:16 — forked from anonymous/playground.rs
Rust code shared from the playground
struct Node<K, V>
where
K: Ord + Sized,
V: Sized,
{
key: K,
value: V,
left: Option<Box<Node<K, V>>>,
right: Option<Box<Node<K, V>>>,
}
#![feature(asm)]
#![feature(i128_type)]
fn cas128(val: &mut u128, old: u128, new: u128) -> Result<u128, u128> {
// old
let rdx: u64 = (old >> 64) as u64;
@spacejam
spacejam / rr-with-rust.md
Last active March 13, 2024 18:51
using rr with rust

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

@spacejam
spacejam / rust-rr-pp.md
Created September 24, 2017 18:22
pretty printing rust with rr

using rust pretty printers 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.

install

steps:

  1. get the rust pretty printer python script
  2. configure gdb to automatically load it