Skip to content

Instantly share code, notes, and snippets.

@intrnl
intrnl / mui-rte.tsx
Created January 26, 2023 00:47
Material UI v4 Rich Text Editor component
import React, {type ReactNode} from 'react'
import {type CreateEditorStateProps} from 'remirror'
import {
BoldExtension,
ItalicExtension,
UnderlineExtension,
BulletListExtension,
OrderedListExtension,
HardBreakExtension,
@intrnl
intrnl / lazy-swr.ts
Last active January 25, 2023 04:41
useLazySWR hook for lazily querying
import React from 'react'
import useSWR, { type Fetcher, type Key, type SWRConfiguration, type SWRResponse } from 'swr'
type ArgumentsTuple = [any, ...unknown[]] | readonly [any, ...unknown[]]
type StrictTupleKey = ArgumentsTuple | null | undefined | false
type StrictKey = StrictTupleKey | (() => StrictTupleKey)
type SetKey<T> = React.Dispatch<React.SetStateAction<T>>
export function useLazySWR<
/* eslint-env node */
import ts from 'typescript'
import {TypeGenAddonFactory} from 'ts-graphql-plugin'
import {astf} from 'ts-graphql-plugin/lib/ts-ast-util'
const typedQueryDocumentAddon: TypeGenAddonFactory = ({source}) => ({
operationDefinition({tsResultNode, tsVariableNode}) {
const lhs = astf.createIdentifier(`${tsResultNode.name.text}Document`)
const rhs = astf.createTypeReferenceNode(
@intrnl
intrnl / proton-compact-userchrome.css
Last active January 20, 2023 13:35
Revert Firefox Proton to Photon compact
/**
* Moved to a new repository.
* https://github.com/intrnl/firefox-revert-proton
*/
:root {
--tab-min-height: 28px !important;
--toolbarbutton-inner-padding: 6px !important;
--toolbarbutton-outer-padding: 1px !important;
--toolbar-start-end-padding: 1px !important;
@intrnl
intrnl / use-search-param.tsx
Last active January 14, 2023 00:37
React hook for managing search params with serialization (using react-router v6 and serialize-query-params)
import React, { type ReactNode } from 'react';
import { useSearchParams } from 'react-router-dom';
import { type QueryParamConfig } from 'serialize-query-params';
export * from 'serialize-query-params';
const SearchParamsContext = React.createContext<ReturnType<typeof useSearchParams> | null>(null);
interface SearchParamsProviderProps {
children?: ReactNode;
#!/usr/bin/env -S bash
## credits to https://paste.sh/1QS8Tgf6#aHTfRy1dOG4rcA5x_6kauwq3
#pkg=current/xbps-0.59.1_6.x86_64.xbps
pkg=current/dolphin-22.08.2_1.x86_64.xbps
otime=current/otime
file="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-results"
mirrormsg() { printf '%s\n' "getting mirrors from void-docs..." ; }
// This attendance counting function assumes the following:
// - You can attend multiple times in one day (and still be counted as one)
// - Attendance time is not counted, you can attend for several minutes and it still counts as one day
/** @typedef {string | number | Date} DateLike */
/**
* @param {Array<{ start: DateLike, end: DateLike }>} attendances
* @param {Date} startDate
* @param {Date} endDate
/**
* @typedef {object} Reader
* @property {(p: Uint8Array) => Promise<number | null>} read
*/
/**
* @typedef {object} Seeker
* @property {(offset: number) => Promise<number>} seek
*/
/**
* Create an async iterable for a readable stream
* @template T
* @param {ReadableStream<T>} stream
* @returns {AsyncIterableIterator<T>}
*/
function createStreamIterator (stream) {
// return if browser already supports async iterator in stream
if (stream[Symbol.asyncIterator]) {
return stream;
function assert (condition, message = 'Assertion failed') {
if (!condition) {
throw new Error(message);
}
}
export class ByteReader {
/**
* @param {ArrayBuffer} buffer
* @param {number} [offset]