Skip to content

Instantly share code, notes, and snippets.

View al6x's full-sized avatar

Alex Kraft al6x

  • Australia
View GitHub Profile
@al6x
al6x / array.ts
Last active December 24, 2024 11:34
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 })
@al6x
al6x / julia.jl
Created December 21, 2024 09:29
Julia vs Ruby
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),
@al6x
al6x / js_call.ts
Last active December 20, 2024 09:11
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}` }
// 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
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
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
@al6x
al6x / play.coffee
Last active September 23, 2023 13:56
render = (lines) ->
@button ->
@text "Say hello!"
@onclick (e) ->
lines.add "Hello simulated universe"
for x in lines
@div ->
@text x
# impl
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
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 } |
import base, ../app, ../h
# Model --------------------------------------------------------------------------------------------
type TodoItemState = enum active, completed
type TodoItem = ref object
text: string
completed: bool