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 / 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 / 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.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>],
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 / 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)
@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 / 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 / pinia-broadcasts.ts
Last active December 12, 2024 04:46
Broadcast and share Pinia states to other tabs
import isEqual from "fast-deep-equal";
import { PiniaPlugin, StateTree } from "pinia";
import { onScopeDispose } from "vue";
// Web Locks API have very good support at this point, but it's disabled by
// Safari when lockdown mode is disabled. Let's gracefully handle this by not
// doing any of that initialization broadcast when it's not present.
const locks = navigator.locks as LockManager | undefined;
const PREFIX = "pinia-broadcast:";
import { type JSONContent } from '@tiptap/core';
import { graphemeLen } from '~/api/richtext/intl.ts';
import { type Facet, type FacetLink } from '~/api/richtext/types.ts';
const encoder = new TextEncoder();
type SerializedMarks = NonNullable<JSONContent['marks']>;
const findFeature = (marks?: SerializedMarks): FacetLink | undefined => {
@mary-ext
mary-ext / schema.json
Last active March 31, 2025 02:12
JSON schema for AT Protocol lexicon documents
{
"type": "object",
"properties": {
"lexicon": { "type": "number", "const": 1 },
"id": {
"type": "string",
"pattern": "^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\.[a-zA-Z]([a-zA-Z]{0,61}[a-zA-Z])?)$"
},
"revision": { "type": "integer", "minimum": 0 },
"description": { "type": "string" },