Skip to content

Instantly share code, notes, and snippets.

@nhrones
nhrones / WS_clients.md
Created January 19, 2024 05:00
WebSocket Clients Collection

wsClient.ts module

Start with strongly typed Socket-Client

/** WS Client type */
type Client = {
  id: string;
  name: string;
  socket: WebSocket;
@nhrones
nhrones / systemEvents.ts
Last active January 1, 2024 20:53
DWM=ReactiveUI system events
import { activeNodes } from '../render/activeNodes.ts'
import { Host, ctx, dwmWindow, hasVisiblePopup } from '../render/renderContext.ts'
import type { View } from '../types.ts';
import { events } from './eventBus.ts'
//====================================================
// Sytem Events Module
// Watch for all host window generated events.
@nhrones
nhrones / preact-rant.md
Last active December 4, 2023 03:18
Preact Docs

Marvin;

When I came to Deno, I was a developer that had retired young in 2000 (I'm 75).
I avoided tech for many years, and took up wood-working as a hobby.
My only computer use was browsing for tools, materials and woodworking articles.

Sometime In 2014, I was approached to do a project for a California NGO working in Cambodia.
One of their engineers had seen one of my graphical real-time desktop apps running in a Toyota plant.
They needed something similar for the detection of underground Unexploded Ordnance (UXO).
I volunteered, and suggested the use of a three-tiered solution.

@nhrones
nhrones / mdToHtml.ts
Created October 31, 2023 18:17
Md to HTML with code highlighting
// Import GFM (GitHub Flavored Markdown rendering for Deno)
import { CSS, render } from "https://deno.land/x/gfm@0.2.1/mod.ts";
// Add prism - syntax highlighter for TypeScript, Bash, and Rust
import "https://esm.sh/prismjs@1.29.0/components/prism-typescript?no-check";
/**
* Export an html doc file builder (builds html from markdown)
*/
export function buildHtml( markdownName: string, srcFolder: string ) {
@nhrones
nhrones / Hot-Example.ts
Last active September 13, 2023 18:01
Hot Browser Refresh
//======================================
// server.ts
//======================================
import { inject } from './injector.ts' // SEE BELOW
import { registerWatcher } from './watcher.ts'
// in your server request handler ...
@nhrones
nhrones / codecBuffer.ts
Last active October 24, 2023 16:58
Expandable Codec Buffer
/** A resizable buffer */
export let accumulator = new Uint8Array( 1 << 14 ) // 16384
/** CodecBuffer class */
export class CodecBuffer {
/** The next available byte (tail-pointer) */
nextByte = 0
@nhrones
nhrones / textToLines.ts
Created August 19, 2023 20:47
Text To Lines
import { TextLine, ctx , logThis, Events } from '../deps.ts'
import { PLACEHOLDER } from './constants.ts'
/**
* splits a string into lines that will fit in a container
* Will attempt to split at word boundries.
*/
export function getLines(text: string, width: number) {
let lines: string[] = []
let maxWidth = width
@nhrones
nhrones / types.ts
Created July 25, 2023 23:25
EventBus Types
/**
* type for generic Event-Handler callbacks
*/
export type EventHandler<T = any> = (data: T) => void;
/**
* validate each Event Types callback parameters
*/
export type EventContract<T> = { [K in keyof T]: T[K] }
import {
Size,
WindowKeyboardEvent,
WindowInputEvent
} from "../mod.ts"
import { TextLine } from "../types.ts";
export type {Rect} from "../mod.ts"
@nhrones
nhrones / eventBus.ts
Created July 25, 2023 23:13
EventBus
import type {CoreEvents} from './coreEventTypes.ts'
import type {
EventBus,
EventContract,
EventHandler
} from '../types.ts'
/**
* A factory function that returns a generic strongly-typed EventBus instance