Skip to content

Instantly share code, notes, and snippets.

@tjpalmer
tjpalmer / things.py
Last active October 2, 2024 21:31
mypyc: Bad float type var in subtype
from abc import ABC, abstractmethod
from typing import Any, Generic, TypeVar
# from numbers import Real
T = TypeVar("T")
class JsonAdapter(ABC, Generic[T]):
@abstractmethod
@tjpalmer
tjpalmer / arcmutself.rs
Last active July 17, 2024 21:52
Arc Mutex as self
use std::sync::{Arc, RwLock};
use std::thread;
#[derive(Debug, Default)]
struct SharedDataStruct {
value: i32,
}
#[derive(Clone, Debug, Default)]
struct SharedData(Arc<RwLock<SharedDataStruct>>);
@tjpalmer
tjpalmer / fib.rs
Last active July 15, 2024 22:26
Rust 1.63-compatible RwLock static init example
pub fn init() {
static INIT_ONCE: std::sync::Once = std::sync::Once::new();
INIT_ONCE.call_once(|| {
let mut zero__2 = 0;
{
*ZERO__2.write().unwrap() = Some(zero__2);
}
zero__2 = zero__2;
{
*ZERO__2.write().unwrap() = Some(zero__2);