Skip to content

Instantly share code, notes, and snippets.

Avatar

Joshua Barretto zesterer

View GitHub Profile
View ub-if-goldbach-was-wrong.c
#include <stdio.h>
int bar(unsigned int x) {
for (int i = x - 1; i >= 2; i--)
for (int s = x; s >= 0; s -= i)
if (s == 0)
return 0;
return 1;
}
View nlp.rs
#[derive(Clone, Debug)]
pub enum Plural {
All,
Specific,
Exactly(i64),
}
#[derive(Clone, Debug)]
pub enum Logical {
And,
@zesterer
zesterer / rtsim2.rs
Created Jan 25, 2022
Veloren rtsim2 data model ideas
View rtsim2.rs
// Top-level rtsim state. The contents of this struct are entirely sufficient to describe the state of the world.
struct RtState {
temporal: &mut Temporal,
agents: &mut Agents,
}
// Contains tick-by-tick information such as decision tree state, short-term planning, aggro, current activity, etc.
// Agents can be both single characters and groups of characters (see `Groups`).
struct Agents { ... }
View graphics-api-mockup.rs
use graphael::*;
use winit::{
event::Event,
window::WindowBuilder,
event_loop::{ControlFlow, EventLoop},
};
#[derive(Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct Globals {
View inference.rs
use super::*;
use std::collections::VecDeque;
pub type InferMeta = (Span, TyVar);
pub type InferNode<T> = Node<T, InferMeta>;
#[derive(Clone, Debug)]
pub enum TyInfo {
Ref(TyVar),
Error,
@zesterer
zesterer / priced_economy.rs
Created Jul 20, 2021
Economy with labour value but prices instead of derived consumption value
View priced_economy.rs
use std::collections::BTreeMap as HashMap;//HashMap;
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum Good {
Log, // Units: Kg
Wood, // Units Kg
Meat, // Units: Kg
Food,
}
@zesterer
zesterer / materialist_economy.rs
Last active Aug 8, 2021
A simulation of a materialist economy: centrally-planned workforce allocation and propagation of labour value and consumption value across the supply chain, leading to pareto efficiency
View materialist_economy.rs
use std::collections::BTreeMap as HashMap;//HashMap;
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum Good {
Log, // Units: Kg
Wood, // Units Kg
Fish, // Units: Kg
Food,
}
@zesterer
zesterer / python-lex.rs
Last active Jul 15, 2021
Lexer for pythonic indentation-aware language that converts identation to token blocks *and* correctly handles parentheses
View python-lex.rs
#[derive(Debug)]
enum Token {
Num(i64),
Paren(Vec<Token>),
Block(Vec<Token>),
}
fn lex(src: &str) -> Result<Vec<Token>, String> {
let mut ident_depth = 0;
let mut token_stack = vec![(ident_depth, Vec::new())];
View breshenham.rs
fn ptr_at(pos: Vec2<isize>) -> *mut Px { ... }
type Px = u16;
pub unsafe fn line(&mut self, a: Vec2<isize>, b: Vec2<isize>, px: Px) {
let delta = b - a;
let delta_abs = delta.map(|e| e.abs() as usize);
let ptr = ptr_at(a.map(|e| e as usize));
let dx = if delta.x > 0 { 1 } else { -1 };
let dy = if delta.y > 0 { 1 } else { -1 } * WIDTH;
@zesterer
zesterer / block_on.rs
Created Jan 17, 2021
Unsafe no-alloc block_on
View block_on.rs
use super::*;
/// Synchronously block until a future completes.
///
/// # Safety
///
/// No waker provided to the future should ever be polled after the future returns `Poll::Ready`. The waker references
/// data on the blocking thread's stack and, as such, access to it after this point is UB because the data is no longer
/// a valid pointer.
#[allow(unused_unsafe)] // It's a stupid warning anyway. No such thing as unsafe code that's too explicit.