Skip to content

Instantly share code, notes, and snippets.

View mary-ext's full-sized avatar
💭
dreaming of bunnies

mary mary-ext

💭
dreaming of bunnies
View GitHub Profile
@mary-ext
mary-ext / pinia-persistence.ts
Last active December 12, 2024 04:45
Local storage persistence for Pinia states
import { PiniaPlugin, StateTree } from "pinia";
const PREFIX = "pinia:";
export interface PersistenceOptions<S extends StateTree> {
validate?: (state: StateTree) => state is S;
}
declare module "pinia" {
// eslint-disable-next-line no-undef, @typescript-eslint/no-unused-vars
@mary-ext
mary-ext / bluesky.txt
Created January 1, 2025 09:09
make bluesky good ublock filter
! remove `session_id` tracking parameter from videos
!
! ideally this would've been a redirect from `video.bsky.app/watch/<did>/<cid>/playlist.m3u8`
! to `video.cdn.bsky.app/hls/<did>/<cid>/playlist.m3u8`, as the latter is the actual CDN while
! the former is the middleware, however:
!
! - the raw playlist will not contain webvtt, that's added in by the middleware
! - ublock doesn't have a rule that allows redirecting to non-local neutered resource
!
||video.bsky.app$removeparam=session_id
@mary-ext
mary-ext / github.txt
Last active January 5, 2025 02:37
make github good ublock filter
! disable rails turbolinks/hotwire turbo
! page load via turbo is considerably slower than html streaming
! this won't affect the file explorer as the nav is handled in react (which is fine)
github.com##+js(set-attr, body, data-turbo, false)
! font adjustments
github.com##body:style(--fontStack-system: sans-serif; --fontStack-sansSerif: sans-serif; --fontStack-monospace: monospace)
github.com##:is(body, .markdown-body, .PageHeader .PageHeader-titleWrap.PageHeader-titleWrap--medium):style(font-family: var(--fontStack-sansSerif) !important)
github.com##:is(tt, pre, code, samp, .text-mono, .react-code-text, .react-blob-print-hide, .blob-code-inner, .blob-num, .input-monospace, .file-info, .commit .sha-block, .commit .sha):style(font-family: var(--fontStack-monospace) !important)
github.com##:is(.markdown-body .highlight pre, .markdown-body pre):style(font-size: 12px !important)
const split = (str: string, delimiter: string, limit: number): string[] => {
const result: string[] = [];
let last = 0;
while (--limit > 0) {
const index = str.indexOf(delimiter, last);
if (index === -1) {
break;
}
@mary-ext
mary-ext / middleware.ts
Last active January 14, 2025 07:24
Middleware-style hook runner
type Middleware<TParams extends any[], TReturn> = (
...params: [...TParams, next: (...params: TParams) => TReturn]
) => TReturn;
const exhausted = () => {
throw new Error('middleware chain exhausted');
};
export const createMiddlewareRunner = <TParams extends any[], TReturn>(
middlewares: [...Middleware<TParams, TReturn>[], Middleware<TParams, TReturn>],
@mary-ext
mary-ext / openapi.ts
Last active January 15, 2025 05:31
TypeScript OpenAPI client
// #region Utility types
type RequiredKeysOf<TType extends object> = TType extends any
? Exclude<
{ [Key in keyof TType]: TType extends Record<Key, TType[Key]> ? Key : never }[keyof TType],
undefined
>
: never;
type HasRequiredKeys<TType extends object> = RequiredKeysOf<TType> extends never ? false : true;
@mary-ext
mary-ext / middleware-monkeypatch.ts
Last active January 16, 2025 06:24
Middleware-style function monkeypatcher
type Procedure = (...args: any[]) => any;
type Methods<T> = keyof {
[K in keyof T as T[K] extends Procedure ? K : never]: T[K];
};
type Properties<T> = {
[K in keyof T]: T[K] extends Procedure ? never : K;
}[keyof T] &
(string | symbol);
type Classes<T> = {
@mary-ext
mary-ext / resize-observer.ts
Created January 22, 2025 09:09
Solid.js useResizeObserver
import { batch, onCleanup } from 'solid-js';
export type ResizeCallback = (entry: ResizeObserverEntry) => void;
interface ObserverStorage {
l: ResizeObserverEntry | undefined;
c: ResizeCallback | ResizeCallback[];
}
const sym = Symbol('resize-observers');
@mary-ext
mary-ext / follow-abort-signal.ts
Created February 6, 2025 10:08
AbortSignal.any ponyfill
export const followAbortSignal = (signals: (AbortSignal | undefined)[]) => {
const controller = new AbortController();
const own = controller.signal;
for (let idx = 0, len = signals.length; idx < len; idx++) {
const signal = signals[idx];
if (!signal) {
continue;
}
@mary-ext
mary-ext / bsky-suggestions-block.txt
Last active February 14, 2025 06:22
block Bluesky's trending and suggestions
bsky.app##+js(user-bsky-suggestions-block.js)
main.bsky.dev##+js(user-bsky-suggestions-block.js)