Skip to content

Instantly share code, notes, and snippets.

View clinuxrulz's full-sized avatar

Clinton Selke clinuxrulz

View GitHub Profile
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>,
@clinuxrulz
clinuxrulz / Plugin.ts
Last active March 4, 2024 09:15
Browser Plugin Utility (bidirectional asynchronous function calls)
export class Plugin {
private src: String;
private callbacks: any;
private iframe?: HTMLIFrameElement;
private messageHandler: (e: MessageEvent) => void;
private recvMsgHandler: (msg: string) => void;
private nextCallId: number = 0;
private resolveMap: any;
onLoad: () => void = () => {};
@clinuxrulz
clinuxrulz / string_factory.rs
Created August 12, 2021 12:05
Recycling strings in Rust
use std::cell::RefCell;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::rc::Rc;
thread_local! {
static STRING_FACTORY: RefCell<StringFactory> = RefCell::new(StringFactory::new());
}
struct MyRc<A>(Rc<A>);
@clinuxrulz
clinuxrulz / Window.tsx
Last active May 13, 2024 19:46
SolidJS reusable draggable/resizable window example (requires bootstrap style sheet and an icon for grip drag corner "svgs/icons/resize%20grip.svg")
import { batch, Component, createEffect, createMemo, onCleanup, onMount } from 'solid-js';
import { createStore } from 'solid-js/store';
const Window: Component<{
title?: string,
width?: number,
height?: number,
initX?: number,
initY?: number,
}> = (props) => {