Skip to content

Instantly share code, notes, and snippets.

View kentcdodds's full-sized avatar
🤓
working hard to make the world better with software

Kent C. Dodds kentcdodds

🤓
working hard to make the world better with software
View GitHub Profile
// Menu: Optical Character Recognition
// Description: Extract text from images
// Author: Kent C. Dodds
// Twitter: @kentcdodds
import '@johnlindquist/kit'
import Tesseract from 'tesseract.js'
const clipboardImage = await clipboard.readImage()
// Menu: Optical Character Recognition
// Description: Extract text from images
// Author: Kent C. Dodds
// Twitter: @kentcdodds
import '@johnlindquist/kit'
import Tesseract from 'tesseract.js'
const clipboardImage = await clipboard.readImage()
// Menu: Optical Character Recognition
// Description: Extract text from images
// Author: Kent C. Dodds
// Twitter: @kentcdodds
import '@johnlindquist/kit'
import Tesseract from 'tesseract.js'
const clipboardImage = await clipboard.readImage()
@kentcdodds
kentcdodds / starfield[.]svg.ts
Created March 6, 2023 17:15
Generate a starfield svg in a Remix Resource Route
import type { DataFunctionArgs } from '@remix-run/node'
export async function loader({ request }: DataFunctionArgs) {
const width = 1280
const height = 720
const starfieldSvg = /* html */ `
<svg id="starfield" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" style="background-color:#090909;">
<style>
@keyframes sparkle {
0% { opacity: 0.3; }
import { z } from 'zod'
export function preprocessFormData<Schema extends z.ZodTypeAny>(
formData: FormData,
schema: Schema,
) {
const shape = getShape(schema)
return mapObj(shape, ([name, propertySchema]) =>
transformFormDataValue(
getFormValue(formData, String(name), propertySchema),
[2021-11-18 18:49:03.381] [info] Protocols Prepared
[2021-11-18 18:49:03.386] [info] Tray created
[2021-11-18 18:49:03.389] [info] Shortcuts Assigned
[2021-11-18 18:49:03.398] [info] Prompt window created
[2021-11-18 18:49:03.399] [info] Tick started
[2021-11-18 18:49:03.399] [info] Kit.app is ready...
[2021-11-18 18:49:03.406] [info] SHORTCUTS DB CHANGED: /Users/kentcdodds/.kit/db/shortcuts.json
[2021-11-18 18:49:03.411] [info] Registered CommandOrControl+; to /Users/kentcdodds/.kit/main/index.js
[2021-11-18 18:49:03.412] [info] Registered CommandOrControl+Alt+Control+C to /Users/kentcdodds/.kenv/scripts/cloudinary-upload.js
[2021-11-18 18:49:03.413] [info] Registered CommandOrControl+Alt+Control+O to /Users/kentcdodds/.kenv/scripts/daily-story.js
@kentcdodds
kentcdodds / jokes.md
Created November 22, 2021 17:34
Headers and caching section removed from the Remix Tutorial because it was too long.

Headers and Caching

Caching is a big subject and it can get pretty complicated. Luckily, the browsers have done all the really hard work for us and we just need to #useThePlatform.

There are three types of caches you'll likely deal with in Remix applications:

  1. Application-level caches that you implement in your own code.
  2. Browser caches you can control through the Cache-Control header.
  3. CDN caches you also can control through the Cache-Control headers.
@kentcdodds
kentcdodds / session.server.ts
Created November 18, 2021 21:04
Authentication in Remix applications
import * as bcrypt from "bcrypt";
import { createCookieSessionStorage, redirect } from "remix";
import { db } from "./db.server";
export type LoginForm = {
username: string;
password: string;
};
@kentcdodds
kentcdodds / scroll-restoration.tsx
Created November 5, 2021 14:57
scroll-restoration.tsx
import * as React from 'react'
import {useLocation} from 'react-router-dom'
import {useTransition} from '@remix-run/react'
import {useBeforeUnload} from 'remix'
import {useSSRLayoutEffect} from './misc'
let firstRender = true
let positions: {[key: string]: number} = {}
const SESSION_STORAGE_KEY = 'kody_scroll_positions'
@kentcdodds
kentcdodds / cell.tsx
Created October 18, 2021 21:38
A real-world example of the prop getters pattern
function Cell({
value,
row: {values: user},
column: {id: propertyName},
}: {
value: string
row: {values: User}
column: {id: string}
}) {