Skip to content

Instantly share code, notes, and snippets.

View jeremy-code's full-sized avatar

Jeremy Nguyen jeremy-code

View GitHub Profile
@jeremy-code
jeremy-code / globals.css
Created April 18, 2026 23:13
Tailwind CSS Radix UI variants
@custom-variant data-horizontal (&[data-orientation="horizontal"]);
@custom-variant data-vertical (&[data-orientation="vertical"]);
@custom-variant data-open (&[data-state="open"]);
@custom-variant data-closed (&[data-state="closed"]);
@custom-variant data-active (&[data-state="active"]);
@custom-variant data-inactive (&[data-state="inactive"]);
@custom-variant data-checked (&[data-state="checked"]);
@custom-variant data-unchecked (&[data-state="unchecked"]);
@jeremy-code
jeremy-code / README.md
Last active April 14, 2026 06:09
Using Files or Blobs in @tanstack/react-query

If you're working with Files or Blob objects, you can't really do anything with them besides read their size and type unless you use one of its methods (e.g. bytes, arrayBuffer, slice, stream, text), all of which (besides stream) return a Promise.

For me, in React, if I'm expected to handle a Promise, my mind gravitates to either React Query or SWR. Something like this:

import { useQuery } from "@tanstack/react-query";

const Component = ({ file }: { file: File }) => {
  const { data: arrayBuffer } = useQuery({
    queryKey: ["Component", file],
@jeremy-code
jeremy-code / README.md
Created April 14, 2026 02:31
Blob tests
const data = new Uint8Array([1,0,1,0])
const blob = new Blob([data])
const newData = await blob.bytes() // [ 1, 0, 1, 0 ]
newData === data // false
data[1] = 1
await blob.bytes() // Uint8Array(4) [ 1, 0, 1, 0 ]
@jeremy-code
jeremy-code / useFileReader.tsx
Last active April 20, 2026 02:07
useFileReader.tsx
import { useSyncExternalStore } from "react";
enum ReadyState {
EMPTY,
LOADING,
DONE,
}
const useFileReader = () => {
const fileReader = new FileReader();
This file has been truncated, but you can view the full file.
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libint53.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libcore.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libsigs.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libccall.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libaddfunction.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libgetvalue.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libmath.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libpath.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libstrings.js
pre-processing JS library: /emsdk/upstream/emscripten/src/lib/libhtml5.js
@jeremy-code
jeremy-code / README.md
Created March 11, 2026 02:09
Border on Arrow in Popover from Radix UI

I needed to add a border to the arrow in the Popover component from radix-ui.

The HTML that is generated looks something like this:

<svg style="display: block;" width="10" height="5" viewBox="0 0 30 10" preserveAspectRatio="none">
  <polygon points="0,0 30,0 15,10"></polygon>
</svg>
@jeremy-code
jeremy-code / README.md
Last active January 27, 2026 03:05
List of large codebases using Radix Primitives
@jeremy-code
jeremy-code / globals.css
Created January 25, 2026 06:28
Tailwind CSS colors reference
@import "tailwindcss";
@theme inline {
--color-contrast-1: light-dark(var(--color-gray-50), var(--color-gray-950)); /* background */
--color-contrast-2: light-dark(var(--color-gray-100), var(--color-gray-900)); /* subtle */
--color-contrast-3: light-dark(var(--color-gray-200), var(--color-gray-800)); /* muted */
--color-contrast-4: light-dark(var(--color-gray-300), var(--color-gray-700));
--color-contrast-5: light-dark(var(--color-gray-400), var(--color-gray-600)); /* subtle foreground */
--color-contrast-6: light-dark(var(--color-gray-500), var(--color-gray-500));
--color-contrast-7: light-dark(var(--color-gray-600), var(--color-gray-400)); /* muted foreground */
@jeremy-code
jeremy-code / README.md
Created December 31, 2025 01:26
Dezoomify

Suppose you are using lovasoa/dezoomify-rs to extract an image.

Easiest way would be to use the dezoomify extension (lovasoa/dezoomify-extension), zooming in, clicking on the extension icon, which will pop up the dezoomify website with the url pre-filled.

Alternatively, inspect element, network tab, select XHR or Fetch/XHR and look for a JSON fetch request to a info.json of something like this:

{
  "@context": "http://iiif.io/api/image/2/context.json",
  "@id": "https://numerabilis.u-paris.fr/iiif/2/bibnum:90146x1805x09:0097",
@jeremy-code
jeremy-code / extractImagesFromPage.ts
Created August 23, 2025 03:13
Extract all images from a PDF page using PDF.js
import { OPS, type PDFPageProxy, type ImageKind } from "pdfjs-dist/legacy/build/pdf.mjs";
// https://github.com/mozilla/pdf.js/blob/master/src/core/image.js#L698
type ImageObject = {
width: number;
height: number;
interpolate: undefined;
kind: (typeof ImageKind)[keyof typeof ImageKind];
data: Uint8Array | Uint8ClampedArray;
dataLen: number;