Skip to content

Instantly share code, notes, and snippets.

View al6x's full-sized avatar

Alex Kraft al6x

  • Australia
View GitHub Profile
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
@al6x
al6x / transform.js
Last active March 20, 2023 03:37
babel transformation
import * as parser from "@babel/parser";
import * as t from '@babel/types';
import _traverse from "@babel/traverse";
const traverse = _traverse.default;
import _generate from '@babel/generator';
const generate = _generate.default;
let code
code = `
{
"editor.tokenColorCustomizations": {
"textMateRules": [
// Nim ---------------------------------------------------------------------------------------
{ // Bold
"scope": [
"entity.name.function.nim",
],
"settings": { "foreground": "#111827", "fontStyle": "bold" } // #3730A3
},
"workbench.colorTheme": "Default Light+",
"editor.tokenColorCustomizations": {
// gray 900 #111827
"textMateRules": [
{
"scope": [
"punctuation.definition.comment",
],
"settings": { "foreground": "#047857", "fontStyle": "bold" }
},
import base/[basem, timem, jsonm, mathm, logm, docm]
import ext/[persistencem]
import std/os
export jsonm, timem # otherwise there will be bug
# Defaults -----------------------------------------------------------------------------------------
let default_retry_timeout = 5.minutes
let default_max_retry_timeout = 4.hours