Skip to content

Instantly share code, notes, and snippets.

View clinuxrulz's full-sized avatar

Clinton Selke clinuxrulz

View GitHub Profile
export function projectMutableOverAutomergeDocV2<T extends object>(
json: any,
updateJson: (cb: (json: any) => any) => void,
typeSchema: TypeSchema<T>
): T {
if (typeof typeSchema != "object" || typeSchema.type != "Object") {
throw new Error("Expected object.");
}
let properties = typeSchema.properties;
let result = new Proxy<T>(
@clinuxrulz
clinuxrulz / index.ts
Created May 23, 2025 00:32
`Cont` monad being used for code generation (used as a Reified Monad)
import { Cont, do_, exec, execR, } from "prelude";
let freeVar = 0;
let code = "";
function main(): Cont<void> {
return do_(() => {
let name = ask(_("What is your name?"));
print(append(_("Hello "), name));
});
@clinuxrulz
clinuxrulz / index.ts
Created May 22, 2025 08:59
Monadic handles for return values in do-notation for Cont
import { Cont } from "prelude";
let div = document.createElement("div");
div.style.setProperty("position", "absolute");
div.style.setProperty("left", "20px");
div.style.setProperty("top", "20px");
div.style.setProperty("width", "300px");
div.style.setProperty("z-index", "100");
div.style.setProperty("background-color", "rgba(0,0,0,0.7)");
setTimeout(() => {
type Extract<Type, Union> = Type extends Union ? Type : never;
export type TypeSchema<A> =
TypeSchemaInvariantMap<unknown, A> |
TypeSchemaRecursive<A> |
{ type: "MaybeUndefined", elemTypeSchema: TypeSchema<NonNullable<A>>, } | (
A extends ({ has: true, value: unknown, } | { has: false, }) ? { type: "Optional", elemTypeSchema: TypeSchema<Extract<A, { value: unknown, }>["value"]>, } :
A extends boolean ? { type: "Boolean", } :
A extends number ? { type: "Number", } :
A extends string ? { type: "String", possibleValues?: string[], } :
import { SetStoreFunction, Store, createStore, reconcile, unwrap } from "solid-js/store";
import { parseJsonViaPropertiesSchema, writeJsonViaPropertiesSchema } from "../model/PropertiesSchema";
import { Result, err, ok } from "../model/Result";
import { Component, ComponentType, IsComponent, IsComponentType } from "./Component";
import { Registry } from "./Registry";
import { generateUUID } from "three/src/math/MathUtils";
import { parentComponentType } from "./components/ParentComponent";
import { childrenComponentType, ChildrenState } from "./components/ChildrenComponent";
import { Accessor, batch, createMemo, createSignal, onCleanup, untrack } from "solid-js";
@clinuxrulz
clinuxrulz / csv_into_excel_dump_2.ps1
Created March 22, 2024 11:45
csv into excel dump via powershell written by ChatGPT
function ProcessFile {
param(
[string]$inputFilename,
[string]$outputFilename
)
$csv = @()
$sr = New-Object System.IO.StreamReader($inputFilename)
try {
while ($true) {
@clinuxrulz
clinuxrulz / csv_into_excel_dump.ps1
Created March 22, 2024 08:20
Dump CSV into Excel via powerscript.
Add-Type -ReferencedAssemblies ("Microsoft.Office.Interop.Excel") -TypeDefinition @"
using System;
using System.Collections.Generic;
using Excel = Microsoft.Office.Interop.Excel;
public static class Program {
public static void Main(string[] args) {
if (args.Length != 2) {
Console.WriteLine("Please pass input file name and output file name as arguments.");
return;
@clinuxrulz
clinuxrulz / PropertiesSchema.ts
Last active August 12, 2023 01:14
Type checked JSON parsing
import { Vec2 } from "../math/Vec2";
import { Result, err, ok } from "./Result";
export type PropertiesSchema<A> = PropertiesSchemaInvMap<unknown,A> | PropertiesSchema2<A>;
type PropertiesSchemaInvMap<A,B> = {
type: "InvMap",
propertiesSchema: PropertiesSchema<A>,
fn1: (a: A) => B,
fn2: (b: B) => A,
@clinuxrulz
clinuxrulz / fgr.rs
Last active January 29, 2023 08:55
Alternative fine grain reactivity implementation (untested)
use std::cell::{Cell, RefCell};
use std::rc::{Rc, Weak};
use std::ops::{Deref, DerefMut};
pub struct FgrCtx {
observer: Rc<Node>,
dirty_nodes: Vec<Rc<Node>>,
transaction_depth: usize,
}
@clinuxrulz
clinuxrulz / parser.rs
Last active February 10, 2022 02:30
Iteratee parsing in Rust
#[derive(Debug, PartialEq, Eq)]
pub enum ChunkNextResult {
Empty,
Char(char),
Eof,
}
pub struct Chunk<'a> {
next: Box<dyn FnMut()->ChunkNextResult+'a>,
unnext_stack: Vec<char>,