Skip to content

Instantly share code, notes, and snippets.

View eira-fransham's full-sized avatar

Eira Fransham eira-fransham

  • Berlin
View GitHub Profile
@eira-fransham
eira-fransham / lib.rs
Last active April 14, 2020 10:13
Rust prime sieve, intended to be compiled to Wasm, combined with a `main.rs` which generates assert statements to test execution of the resultant WebAssembly.
pub fn sieve(limit: usize) -> Option<impl Iterator<Item = usize>> {
let mk_func = |cmpsts: Vec<_>| {
move |i| {
if i < 0 {
Some(2)
} else {
if cmpsts.get(i as usize >> 5)? & (1u32 << (i & 31)) == 0 {
Some((i + i + 3) as usize)
} else {
None
use alloc::alloc;
use core::{
alloc::Layout,
convert::{TryFrom, TryInto},
fmt,
mem::{self, ManuallyDrop},
num::NonZeroU32,
ops::{self, Drop},
ptr,
name cranelift.bench ns/iter lightbeam.bench ns/iter diff ns/iter diff % speedup
+ misc::br_cannot_share_cc::compile 165,109 109,143 (1 MB/s) -55,966 -33.90% x 1.51
+ misc::br_cannot_share_cc::run 1,421 1,318 -103 -7.25% x 1.08
+ misc::call_indirect::compile 2,369,666 1,037,499 (1 MB/s) -1,332,167 -56.22% x 2.28
+ misc::call_indirect::run 7,676 7,513 -163 -2.12% x 1.02
+ misc::control_flow::compile 1,120,041 854,382 -265,659 -23.72% x 1.31
+ misc::control_flow::run 5,848 5,472 -376 -6.43% x 1.07
+ misc::div_rem::compile 593,102 402,117 -190,985 -32.20% x 1.47
+ misc::div_rem::run
#! /bin/sh
(cd $(dirname $0) && cargo run --release --features lightbeam -- --env 'RUST_BACKTRACE=1' --lightbeam "$@")
??g mustard powder
??ml rich, not too acidic wine or flat beer (e.g. shaoxing wine)
??ml vinegar (e.g. chinese dark vinegar)
??g molasses
?? eggs
??g hard fat (e.g. vegetable shortening)
Salt, spices and other dry flavourings(depending on desired result)
??g wheat gluten
??g other flour? (e.g. chickpea)
60ml soy sauce
60ml veggie stock (or stock of choice), I used a mixture of stock and vegetarian gravy because the latter has nutritional yeast in it
40ml rich wine (e.g. shaoxing)
20ml chinese dark vinegar
250g weizengluten
100g shop-bought hummus, I think the artificial emulsifier is an important ingredient because homemade doesn’t work
~1tsp Liquid smoke
~1/2tsp Tabasco, or more to taste
~2tsp Black pepper
1tbsp molasses

"Rare" Seitan

So this recipe works by making an emulsion so that the fat doesn't clog up the proteins of the seitan too badly and the seitan can still develop properly. The emulsion is made by copying a mayonnaise and mustard recipe, throwing out all the bits that make it taste like mayonnaise/mustard and keeping the bits that make it emulsify. Right now I'm still using egg as the emulsifier for the "mayonnaise", but I've seen recipes online that use silken tofu or even lecithin (the emulsifying agent in soy) extract directly to make their mayonnaise emulsify so I want to try that in the future

@eira-fransham
eira-fransham / threadpool.rs
Created September 24, 2021 08:39
Toy threadpool implementation
use std::{
any, mem, panic,
sync::atomic::{AtomicUsize, Ordering},
thread,
};
#[derive(PartialEq)]
enum Progress {
Continue,
Stop,
#![feature(allocator_api)]
mod cursed_lazy {
use std::{
alloc::{Allocator, Layout, AllocError},
ptr::NonNull,
};
pub struct LazyAlloc;
@eira-fransham
eira-fransham / cmykdots-shadertoy.glsl.frag
Last active September 19, 2024 12:12
Best shader for generating CMYK halftone dots for full colour images on the internet, to my knowledge (ShaderToy- and TouchDesigner-compatible)
#define SHADERTOY
#ifdef SHADERTOY
const float Frequency = 60.0;
const float Size = 0.7;
const float Saturation = 5.;
const float Exponent = 0.3;
const float ReduceColor = 0.3;
const float Lightness = 0.306;
const float LumMul = 2.;