Skip to content

Instantly share code, notes, and snippets.

@soruh
soruh / buffered_workers.rs
Last active January 14, 2021 21:16
Buffered Stream
use futures::{Stream, StreamExt};
use std::time::Duration;
use std::{collections::VecDeque, pin::Pin};
// Why do the spawned tasks that generate the streams in the code below
// not run in parallel with at most 2 tasks running at once?
static mut START: std::mem::MaybeUninit<std::time::Instant> = std::mem::MaybeUninit::uninit();
macro_rules! log {
{
unique_lock lock(mutex); // takes the lock
convar.wait(mutex) // wait
// do stuff with the lock
}
// the lock is no longer held
@soruh
soruh / replay.ts
Created April 6, 2022 10:39
replay proof of concept
type Replay = {
when: Date,
resolve: () => void,
};
// jobs that are waiting for a virtual timeout (for us to skip more time)
// this could be a btree set for more effieciency
let replay_buffer: Replay[] = [];
// current replay time. starts at the point the game was closed last time and ends when we have caught up to real-time.
let replay_time: Date | null = null;
@soruh
soruh / wordle.rs
Last active September 2, 2022 00:21
// # Cargo.toml
// [dependencies]
// memmap = "0.7.0"
// rayon = "1.5.3"
use std::{
fmt::{Display, Write},
path::Path,
time::Instant,
};
diff --git a/composer.json b/composer.json
index 25595571f..23b274391 100644
--- a/composer.json
+++ b/composer.json
@@ -44,6 +44,7 @@
"prologue/alerts": "~1.1.0",
"psr/cache": "~3.0.0",
"s1lentium/iptools": "~1.2.0",
+ "spatie/ignition": "~1.12.0",
"spatie/laravel-fractal": "~6.0.3",