Skip to content

Instantly share code, notes, and snippets.

@intrnl
intrnl / solid-freeze.tsx
Last active December 17, 2023 07:27
Freezing component subtrees using Suspense in Solid.js
import { type JSX, Suspense, createMemo, createResource, For } from 'solid-js';
export interface FreezeProps {
freeze: boolean;
children: JSX.Element;
fallback?: JSX.Element;
}
type Deferred = Promise<undefined> & { r: (value: undefined) => void };
@intrnl
intrnl / use-media-query.ts
Created September 28, 2023 15:53
Solid.js media query
import { type Accessor, createSignal, onCleanup } from 'solid-js';
interface MediaStore {
/** State backing */
a: Accessor<boolean>;
/** Amount of subscriptions */
n: number;
/** Cleanup function */
c: () => void;
}
@intrnl
intrnl / reactive-localstorage.ts
Created September 28, 2023 15:50
Solid.js createReactiveLocalStorage
import { createEffect, createRoot } from 'solid-js';
import { type StoreNode, createMutable, modifyMutable, reconcile } from 'solid-js/store';
const parse = (raw: string | null, initialValue: any) => {
if (raw === null) {
return initialValue;
}
try {
const persisted = JSON.parse(raw);
@intrnl
intrnl / solid-meta.tsx
Created September 27, 2023 07:34
Solid.js SPA meta title provider
import {
createContext,
createEffect,
createMemo,
createSignal,
onCleanup,
onMount,
useContext,
} from 'solid-js';
import type { JSX } from 'solid-js/jsx-runtime';
const FOLLOWING = 4;
const CONTAINED_BY = 16;
const PRECEDING = 2;
const CONTAINS = 8;
export const collateNode = (a: Node, b: Node) => {
const position = a.compareDocumentPosition(b);
if (position & (FOLLOWING | CONTAINED_BY)) {
@intrnl
intrnl / App.svelte
Last active January 29, 2024 21:59
Svelte 5 deep reactivity
<svelte:options runes />
<script>
import { store, increment } from './reactive.js';
const deep = store.deep;
const remaining = $derived(store.items.filter((item) => !item.done).length);
function push() {
store.items.push({ text: 'bar', done: false });
export type IdleCallback = () => void;
const queue: IdleCallback[] = [];
let running = false;
const runTasks = (deadline: IdleDeadline) => {
while (deadline.timeRemaining() > 0) {
const callback = queue.shift();
if (!callback) {
@intrnl
intrnl / mangle.ts
Created August 12, 2023 17:23
Mangle all TS interface fields with a directive
// TODO: make sure this doesn't run if `git diff --stat HEAD -- src/` actually returns something
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import { type PropertySignature, InterfaceDeclaration, Project, SyntaxKind } from 'ts-morph';
import { ShortIdent } from '../lib/mangler/shortident.js';
const root = path.join(fileURLToPath(import.meta.url), '../..');
@intrnl
intrnl / bluesky-delete-all-post.ts
Last active August 6, 2023 08:11
script to delete all posts from a Bluesky account
import { Agent } from '@intrnl/bluesky-client/agent';
import type { UnionOf } from '@intrnl/bluesky-client/atp-schema';
import { pRateLimit } from 'p-ratelimit';
const agent = new Agent({ serviceUri: 'https://bsky.social' });
const limit = pRateLimit({ concurrency: 3, interval: 1000, rate: 5 });
const getRecordId = (uri: string) => {
const idx = uri.lastIndexOf('/');
@intrnl
intrnl / bad_domains.txt
Last active September 4, 2023 12:05
Mobile ad/tracker domains, from mobile apps, or sites with domains that weren't caught by browser extensions
trinitymedia.ai
a.vdo.ai
tru.am
ad.leap.app
netlify-rum.netlify.app
cdn.permutive.app
0f73e92f-4074-4fe3-85d3-ed3fc969859e.edge.permutive.app
6093eccf-6734-4877-ac8b-83d6d0e27b46.edge.permutive.app
68547f8f-2fd8-4ff3-9b63-51e86e2edee8.edge.permutive.app
a2a5c7f9-3fa0-4182-889a-15aa61acf59b.edge.permutive.app