Skip to content

Instantly share code, notes, and snippets.

@colelawrence
colelawrence / qwik-tw-styled-components.tsx
Last active January 2, 2024 18:19
Qwik styled-components with Tailwind merge. To remix for your codebase at your option! Also supports `data-qwik-inspector` pasthrough.
import { Slot, component$ } from "@builder.io/qwik";
import type { JSX } from "@builder.io/qwik/jsx-runtime";
import { twMerge } from "tailwind-merge";
/** Comes from {@link tw} template. */
type TwString = string & {
_tw: true;
};
/** This applies types to somethign like `tw.div` or `tw.h1`, which will leverage the types from `JSX.IntrinsicElements` */
@colelawrence
colelawrence / DisposePool.ts
Created December 19, 2023 20:53
Dispose Pool (Subscription) class
export interface IDisposable {
dispose(): void;
}
export class DisposePool implements IDisposable {
#fns: null | (() => void)[] = [];
#pool: null | IDisposable[] = [];
get disposed() {
return this.#pool === null;
}
@colelawrence
colelawrence / dev-stringify.ts
Last active January 11, 2024 21:21
Tight JSON and JavaScript stringify
function jsReplacer() {
const seen = new WeakSet();
return (key: string, value: any) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) return "[Circular]";
seen.add(value);
}
if (value instanceof RegExp) return { regexp: value.toString() };
if (value instanceof Function) return { function: value.toString() };
if (value instanceof Error) return { error: value.toString() };
@richkuz
richkuz / obsidian-default-note-title.md
Created May 18, 2023 13:21
Obsidian: How to set the default title of a new note

How to set the default title of a new note in Obsidian

I wanted to set the default title of new notes created via Cmd+N to be formatted like "2023-05-18 New", "2023-05-18 New 2", ...

I also wanted all new notes created via Cmd+N to go in the new folder.

  1. Create a folder called e.g. new

  2. In "Files & Links" settings, set "Folder to create new notes in" to new

  3. Create a folder called e.g. templates and add a file called e.g. Default with this content:

@VictorTaelin
VictorTaelin / implementing_fft.md
Last active July 20, 2024 08:14
Implementing complex numbers and FFT with just datatypes (no floats)

Implementing complex numbers and FFT with just datatypes (no floats)

In this article, I'll explain why implementing numbers with just algebraic datatypes is desirable. I'll then talk about common implementations of FFT (Fast Fourier Transform) and why they hide inherent inefficiencies. I'll then show how to implement integers and complex numbers with just algebraic datatypes, in a way that is extremely simple and elegant. I'll conclude by deriving a pure functional implementation of complex FFT with just datatypes, no floats.

/**
* Generate a fragile object that will throw error at any operation.
*/
export function createErrorObj<T = any>(error: string): T {
return new Proxy(
{},
{
get(target, prop, receiver: unknown) {
throw new Error(
@colelawrence
colelawrence / createTrpcDurableObject.ts
Last active March 27, 2024 22:10
Create strongly typed Durable Objects with TRPC wrappers (requires trpc@10)
import { createTRPCProxyClient, httpLink } from "@trpc/client";
import { AnyRouter, initTRPC, MaybePromise, Router } from "@trpc/server";
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import type { ParserWithInputOutput, ParserWithoutInput } from "@trpc/server/dist/core/parser";
import type { AnyRouterDef } from "@trpc/server/dist/core/router";
import type { ResponseMetaFn } from "@trpc/server/dist/http/internals/types";
import { getParseFn } from "./getParseFn";
export type TrpcDurableObjectRouter<Router extends AnyRouter> = {
router: Router,
@nberlette
nberlette / SvelteKit_vs_NextJS.md
Last active March 29, 2022 05:53
Svelte vs. Next.js

SvelteKit 🆚 Next.js

Objectives: fast, easy, convention over configuration, & batteries included. Overwhelming choices < providing a clear path forward.

Contenders: [SvelteKit][sveltekit-url] (by [Svelte][svelte-url]) and [Next.js][next-url] (by [Vercel][vercel-url]).


Comparison of Major Features

@colelawrence
colelawrence / Tree-Sitter-grammar.d.ts
Last active September 19, 2019 20:42
Tree-Sitter "grammar.js" file TypeScript definitions
type Combinator = string | RegExp | any;
type Previous = {
members: RuleMember[];
};
type RuleMember = { name: string };
/**
* Every grammar rule is written as a JavaScript function that takes a parameter conventionally called $. The syntax $.identifier is how you refer to another grammar symbol within a rule.
@dakom
dakom / ECS notes.md
Last active May 27, 2024 10:42
ECS with sparse array notes (EnTT style)

Intro

The below is a breakdown / bird's eye view of how a sparse-array backed ECS like EnTT or Shipyard works.

Please see the thanks and references at the bottom - without their help I would not have been able to share this breakdown with you... everything here is really just notes and rephrasing of what they've written already :)

Also, these notes do not cover archetype systems (like unity) nor adaptations of archetypes (like in Flecs). Though there's a couple comparative footnotes at the end.

Here we go!