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 './mfun' | |
declare global { | |
function fsize<T>(a: T[]): number | |
function fempty7<T>(a: T[]): boolean | |
} | |
mfun(Array, function fsize<T>(a: T[]): number { return a.length }) | |
mfun(Array, function fempty7<T>(a: T[]): boolean { return a.length == 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
table = [ | |
sort( | |
map( | |
(c) -> (type = :Without, moneyness = c.moneyness), | |
filter((c) -> c.tenor == 856, normalized_jl) | |
) | |
)..., | |
sort( | |
map( | |
(c) -> (type = "With CPI", moneyness = c.moneyness), |
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 Req = { id?: string, target: string, args?: unknown[] } | |
type Res = { id?: string, is_error: true, error: string } | { id?: string, is_error: false, result: unknown } | |
const target_cache: { [name: string]: unknown } = {} | |
async function process({ id, target: path, args }: Req): Promise<Res> { | |
if (!(path in target_cache)) { | |
const [module_name, ...names] = path.split('.') | |
if (names.length < 1) return { id, is_error: true, error: `Invalid path: ${path}` } |
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 'Prettify Symbols Mode' VSCode Extension to display `foo7` as `foo?` | |
declare global { | |
function p(...args: unknown[]): void | |
function inspect(v: unknown): void | |
/** Converts anytihng to compact format `{ a: 1, b: [1, 'c']}`, | |
* could be parsed with the `from_s`, relaxed json or yaml. */ | |
function to_s(v: unknown): string | |
/** Parses both json, relaxed json, and output of the `to_s`, example `{ k: 1 }` */ | |
function from_s<T = unknown>(v: string): T | |
function equal7<T>(a: T, b: T): boolean |
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 | |
CommandKind = enum eval, replace | |
CodeCmd = object # not required, but makes my point clearer | |
kind: eval | |
code: string | |
ReplaceCmd = object | |
kind: replace | |
element_id: string | |
content: string | |
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 | |
CommandKind = enum eval, replace | |
CodeCmd = object # not required, but makes my point clearer | |
kind: eval | |
code: string | |
ReplaceCmd = object | |
kind: replace | |
element_id: string | |
content: string | |
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
render = (lines) -> | |
@button -> | |
@text "Say hello!" | |
@onclick (e) -> | |
lines.add "Hello simulated universe" | |
for x in lines | |
@div -> | |
@text x | |
# impl |
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 base, mono/[core, http], ext/persistence, std/os | |
# Model ------------------------------------------------------------------------------------------- | |
type | |
Square = enum | |
Empty, X, O | |
Board = array[3, array[3, Square]] | |
Game = ref object | |
board: Board |
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 SpecialInputKeys = 'alt' | 'ctrl' | 'meta' | 'shift' | |
interface ClickEvent { special_keys: SpecialInputKeys[] } | |
interface KeydownEvent { key: string, special_keys: SpecialInputKeys[] } | |
interface ChangeEvent { stub: string } | |
interface BlurEvent { stub: string } | |
interface InputEvent { value: string } | |
type InEvent = | |
{ kind: 'location', el: number[], location: string } | // el not needed for location but Nim requires it. | |
{ kind: 'click', el: number[], click: ClickEvent } | |
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 base, ../app, ../h | |
# Model -------------------------------------------------------------------------------------------- | |
type TodoItemState = enum active, completed | |
type TodoItem = ref object | |
text: string | |
completed: bool |