This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{rc::Rc, vec}; | |
trait Unsafe { | |
// where Self: Sized allows us to hold | |
// values implementing this in arrays | |
// and pass it as function arguments as &dyn Unsafe | |
// or Box<dyn Unsafe> without not object-safe errors. | |
fn create() -> Self where Self: Sized; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(local_key_cell_methods)] | |
use std::{cell::RefCell, collections::HashMap}; | |
// Core idea: Rust lets you do this: | |
fn create_closure(initial: u32) -> Box<dyn FnMut()> { | |
let mut captured = initial; | |
Box::new(move || { | |
captured += 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn mount<T, P, B: FnMut(&mut P)>( | |
component: fn(this: Option<T>, props: P, block: B) -> T, | |
props: P, | |
block: B, | |
) { | |
component(None, props, block); | |
} | |
struct Props<T: FnMut()> { | |
on_click: T, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LinkedHeightContainer = ({ children, link }) => { | |
const ref = useRef(null); | |
useEffect(() => { | |
const observer = new ResizeObserver((entries) => { | |
const entry = entries[entries.length - 1]; | |
const height = `${entry.contentRect.height}px`; | |
ref.current.style.height = height; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const effects = []; | |
let isCollectingEffects = false; | |
const data = (init) => { | |
const deps = []; | |
let oldValue = init; | |
return (value) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type SubtractOne<T> = | |
T extends '9' ? '8' | |
: T extends '8' ? '7' | |
: T extends '7' ? '6' | |
: T extends '6' ? '5' | |
: T extends '5' ? '4' | |
: T extends '4' ? '3' | |
: T extends '3' ? '2' | |
: T extends '2' ? '1' | |
: T extends '1' ? '0' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Math.max(NaN, 100) === NaN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useDebug = (deps: Record<string, any>) => { | |
Object.entries(deps).forEach(([key, value]) => { | |
useEffect(() => console.log(`${key} Changed`), [value]); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(self.events.map(x => [x[0], x[1].type, x[2].sliceSerialize(x[1], true)]).map(x => x.join(' | ')).reduce((prev, curr) => { | |
if (curr.startsWith('enter')) { | |
prev = { i: prev.i, t: prev.t + '\n' + ' '.repeat(prev.i) + curr }; | |
prev.i+=2 | |
return prev | |
} else { | |
prev.i-=2 | |
return { i: prev.i, t: prev.t + '\n' + ' '.repeat(prev.i) + curr } | |
} | |
}, { i: 0, t: '' }).t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Engineer": { | |
"\"Warthog\" Auto 210": [ | |
{ | |
"id": 25, | |
"character_id": 1, | |
"gun_id": 1, | |
"overclock_type": "Clean", | |
"overclock_index": 1, | |
"overclock_name": "Stunner", |