Skip to content

Instantly share code, notes, and snippets.

@intrnl
intrnl / css-in-js.ts
Last active September 12, 2023 08:10
let uid = 0;
let inserted = false;
const stylesheet = /*#__PURE__*/ new CSSStyleSheet();
const build = (bake: (name: string, body: string) => string) => {
if (import.meta.env.DEV) {
const seen = new WeakSet<TemplateStringsArray>();
const cache = new Map<number, string>();
@intrnl
intrnl / solid-navigation-resource.ts
Created July 8, 2023 02:22
Solid.js cached resource tied to the navigation entry
/// <reference types="navigation-api-types" />
import {
type ResourceFetcher,
type ResourceReturn,
type ResourceSource,
createResource,
onCleanup,
} from 'solid-js';
[intrnl@azalea react-app]$ rm -rf node_modules/ oro-cache/
[intrnl@azalea react-app]$ ../../orogene-v0.3.6-x86_64-unknown-linux-gnu/oro restore --cache oro-cache --loglevel info
2023-03-07T08:52:19.766842Z INFO orogene: Running command: Restore(
RestoreCmd {
registry: Some(
Url {
scheme: "https",
cannot_be_a_base: false,
username: "",
password: None,
import { is_function } from './utils.js';
let undefined;
let RUNNING = 1 << 0;
let NOTIFIED = 1 << 1;
let OUTDATED = 1 << 2;
let DISPOSED = 1 << 3;
let HAS_ERROR = 1 << 4;
let TRACKING = 1 << 5;
import * as acorn from 'acorn';
import { walk } from 'estree-walker';
import MagicString from 'magic-string';
import { analyze } from 'periscopic';
const debuggableConfig = {
'@vanilla-extract/css': {
style: {
maxParams: 2,
@intrnl
intrnl / apollo-hasura-migration.js
Last active February 22, 2023 12:03
Hasura v2 migration package for Apollo Client
// NOTE: Hasura v1 to Hasura v2 conversion
/* eslint-disable import/export */
import {
useQuery as useApolloQuery,
useSubscription as useApolloSubscription,
} from '@apollo/react-hooks-unpatched'
import gql from 'graphql-tag'
export * from '@apollo/react-hooks-unpatched'
@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 / 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;