Skip to content

Instantly share code, notes, and snippets.

View zesterer's full-sized avatar

Joshua Barretto zesterer

View GitHub Profile
@zesterer
zesterer / priced_economy.rs
Created July 20, 2021 21:36
Economy with labour value but prices instead of derived consumption value
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 August 8, 2021 21:29
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
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 July 15, 2021 23:09
Lexer for pythonic indentation-aware language that converts identation to token blocks *and* correctly handles parentheses
#[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())];
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 January 17, 2021 01:43
Unsafe no-alloc block_on
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.
fn main() {
let s = r#"fn main() {
let s = @;
let x = s.find('@').unwrap();
println!("{}r#\"{}\"{}{}", &s[..x], s, '#', &s[x + 1..]);
}"#;
let x = s.find('@').unwrap();
println!("{}r#\"{}\"{}{}", &s[..x], s, '#', &s[x + 1..]);
}
use gui::{
widget::{Toggle, Button, Label, List},
layout::Direction,
event::Click,
Window, Widget,
};
fn main() {
enum Op {
Add,
diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl
index 315807549..d5bea01a3 100644
--- a/assets/voxygen/shaders/figure-frag.glsl
+++ b/assets/voxygen/shaders/figure-frag.glsl
@@ -146,7 +146,7 @@ void main() {
// DirectionalLight sun_info = get_sun_info(sun_dir, sun_shade_frac, light_pos);
float point_shadow = shadow_at(f_pos, f_norm);
- DirectionalLight sun_info = get_sun_info(sun_dir, point_shadow * sun_shade_frac, /*sun_pos*/f_pos);
+ DirectionalLight sun_info = get_sun_info(sun_dir, point_shadow * sun_shade_frac, /*sun_pos*/f_pos, view_dir);
#version 330 core
#include <globals.glsl>
#include <srgb.glsl>
#include <random.glsl>
in vec3 v_pos;
in uint v_col;
in uint v_norm_ao;
in vec3 inst_pos;
# General utility
type Str = [Char]
type Io A = Universe -> (A, Universe)
fn nothing |uni of Universe| ((), uni)
fn print |s, uni| ((), @print(s, uni))
fn input |uni| @input(uni)
data Maybe A =