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
export type LRUCache<K, V> = { | |
get: (key: K) => V | undefined | |
set: (key: K, value: V) => void | |
} | |
export function createLRUCache<K, V>(max: number): LRUCache<K, V> { | |
type Node = { prev?: Node; next?: Node; key: K, value: V } | |
const cache = new Map<K, Node>() | |
let oldest: Node | undefined | |
let newest: Node | undefined | |
const touch = (entry: Node) => { |
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
class LRUMap<TKey, TValue> extends Map<TKey, TValue> { | |
constructor(max: number) { | |
super() | |
const get = this.get.bind(this) | |
const set = this.set.bind(this) | |
this.get = (key: TKey) => { | |
const item = get(key) | |
if (item !== undefined) { | |
// refresh key | |
this.delete(key) |
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
//@ts-check | |
const Component = ({ names }: { names: [string] }) => ( | |
<p>{names[0]}</p> | |
) | |
export default function App() { | |
return <div>Hello world</div> | |
} |
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
import { Suspense } from "react"; | |
type CacheItem<T> = { | |
keys: any[] | |
promise: Promise<T> | |
error?: unknown | |
response?: T | |
} | |
const cache: CacheItem<any>[] = [] |
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 ACTIVATIONS = [ | |
/*'identity': */x => x, | |
/*'abs': */ x => Math.abs(x), | |
/*'clamped': */ x => Math.min(1, Math.max(-1, x)), | |
/*'cube': */ x => Math.pow(x, 3), | |
/*'exp': */ x => Math.exp(x), | |
/*'gauss': */ x => x, | |
/*'hat': */ x => Math.max(0, x < 0 ? 1 + x : 1 - x), | |
/*'inv': */ x => 1 / x, | |
/*'log': */ x => Math.log(x), |
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
import { useEffect, useRef, useState } from 'react' | |
import parse from './ast.js' | |
import { mapCaretToAST } from './mapInputToAST.js' | |
import AstParser from './AstClass.js' | |
import { | |
constPlugin, | |
groupPlugin, | |
numberPlugin, | |
stringPlugin, | |
leftUnaryOperatorsPlugin, |
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
{ | |
"scripts": [], | |
"styles": [] | |
} |
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
{ | |
"scripts": [], | |
"styles": [] | |
} |
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
{ | |
"scripts": [], | |
"styles": [] | |
} |
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
{ | |
"scripts": [], | |
"styles": [], | |
"themePreview": false | |
} |
NewerOlder