Skip to content

Instantly share code, notes, and snippets.

View hnordt's full-sized avatar

Heliton Nordt hnordt

View GitHub Profile
import { render } from "preact";
import { signal } from "@preact/signals";
function createEventSource(url: string) {
const source = new EventSource(url);
const status = signal(source.readyState);
function updateStatus() {
status.value = source.readyState;
}
@hnordt
hnordt / AGENTS.md
Last active January 14, 2026 13:33

Cognitive Model & Design Principles

This codebase follows a rule-driven, semantic-first design model. The goal is to reduce ambiguity, minimize cognitive load, and keep the system easy to reason about as it grows.

Do not introduce new structure without a clear, deliberate reason.

When writing or changing code, follow these principles strictly.

@hnordt
hnordt / counter.tsx
Created November 16, 2025 19:04
A type-safe, semantic custom counter element built with Custom Elements, the Invoker Commands API, and preact-render-to-string.
import { renderToStaticMarkup } from "preact-render-to-string";
declare global {
namespace preact.JSX {
interface IntrinsicElements {
"el-counter": preact.HTMLAttributes<HTMLElement>;
}
}
}
type TMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
type THandler = (
req: Request,
match: URLPatternResult | null,
) => Response | Promise<Response>;
class Route {
constructor(
private pattern: URLPatternInput,
@hnordt
hnordt / deno.json
Last active November 12, 2025 22:29
{
"compilerOptions": {
"lib": ["dom", "deno.ns"],
"jsx": "precompile",
"jsxImportSource": "preact"
},
"tasks": {
"dev": "deno run --allow-net --watch server.tsx",
},
"imports": {
import React from "react";
function usePress(onEnd: (isCancelled: boolean) => void, onStart?: () => void) {
return {
onPointerUp(e: React.PointerEvent<Element>) {
const rect = e.currentTarget.getBoundingClientRect();
onEnd(
!(
e.clientX >= rect.left &&
@hnordt
hnordt / Router.tsx
Last active September 17, 2025 00:33
import { useReducer, useEffect } from "react";
// pathToRegexp can be replaced with URLPattern once browser support improves
// https://developer.mozilla.org/en-US/docs/Web/API/URLPattern
import pathToRegexp from "path-to-regexp";
const Router = {
PushStateEventType: "pushstate",
ReplaceStateEventType: "replacestate",
PopStateEventType: "popstate",
import React from "react"
import { useLocation, useLoaderData, useFetcher } from "remix"
export default function useLoaderDataWithWindowFocusRefetching<LoaderData>() {
const loaderData = useLoaderData<LoaderData>()
const fetcher = useFetcher<LoaderData>()
const location = useLocation()
const pathnameRef = React.useRef(location.pathname)
React.useEffect(() => {
import React from "react"
import { useLocation, useNavigate } from "remix"
export default function useWindowFocusRefetching() {
const location = useLocation()
const navigate = useNavigate()
const pathnameRef = React.useRef(location.pathname)
React.useEffect(() => {
// add to your tailwind.config.js
const plugin = require("tailwindcss/plugin")
const radixPlugin = plugin(({ addVariant }) => {
const dataStates = [
"open",
"closed",
"active",
"inactive",