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
@kentcdodds
kentcdodds / lifetime-contributions.js
Last active September 5, 2024 05:09
Calculate your total lifetime github contributions
// ⚠️ warning: This script was written by ChatGPT, not entirely reviewed, and is completely unmodified
// This counts your lifetime contributions so you can decide
// whether to block Twitter: https://x.com/mjackson/status/1831554887706169674
const GITHUB_API_URL = 'https://api.github.com/graphql'
// scope needed: "user:read" for public contributions and "repo" for private
// https://github.com/settings/tokens/new
const GITHUB_TOKEN = process.env.GITHUB_TOKEN
@kentcdodds
kentcdodds / screenshot-node.js
Created August 14, 2024 22:05
Create a screenshot of a DOM element (while preserving a transparent background).
const { default: html2canvas } = await import(
'https://unpkg.com/html2canvas@1.4.1/dist/html2canvas.esm.js'
)
async function captureElement(element, { scale = 1, backgroundColor = null } = {}) {
const canvas = await html2canvas(element, {
backgroundColor,
scale,
})
// Name: EpicShop Update
// Description: Update the EpicShop workshop app in all the epic web workshop repos
// Author: Kent C. Dodds
// Twitter: @kentcdodds
import '@johnlindquist/kit'
import {globby} from 'globby'
import {execa} from 'execa'
const workshopDirs = [
// Menu: Twimage Download
// Description: Download twitter images and set their exif info based on the tweet metadata
// Shortcut: command option control t
// Author: Kent C. Dodds
// Twitter: @kentcdodds
import '@johnlindquist/kit'
import fs from 'fs'
import {URL} from 'url'
import {getTweet} from '../lib/twitter'
import { useSyncExternalStore } from 'react'
/**
* This will call the given callback function whenever the contents of the map
* change.
*/
class ObservableMap extends Map {
constructor(entries) {
super(entries)
this.listeners = new Set()
@kentcdodds
kentcdodds / current-implementation.tsx
Created March 21, 2024 17:10
Simpler Control Props Implementation?
import { useReducer, useRef } from 'react'
import { Switch } from '#shared/switch.tsx'
function callAll<Args extends Array<unknown>>(
...fns: Array<((...args: Args) => unknown) | undefined>
) {
return (...args: Args) => fns.forEach(fn => fn?.(...args))
}
export type ToggleState = { on: boolean }
@kentcdodds
kentcdodds / notes.md
Created October 17, 2023 03:10
Survey notes
type ScaleSurveyQuestion = {
  id: string;
  question: string;
  type: 'multiple-choice'
  choices: Array<{label: string; answer: string}>;
};

type FreeformSurveyQuestion = {
  id: string;
import 'dotenv/config.js'
import chromadb from 'chromadb'
import { RetrievalQAChain } from 'langchain/chains'
import { ChatOpenAI } from 'langchain/chat_models/openai'
import { OpenAIEmbeddings } from 'langchain/embeddings/openai'
import { Chroma } from 'langchain/vectorstores/chroma'
const { OpenAIEmbeddingFunction, ChromaClient } = chromadb
const COLLECTION_NAME = 'test-collection'
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/full-stack-testing/exercises__sep__11.finish__sep__01.solution.finished/rbb60w04h7/.env var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/full-stack-testing/exercises__sep__11.finish__sep__01.problem.finished/rbb60w04h7/.env
index d049969..4ac848d 100644
--- var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/full-stack-testing/exercises__sep__11.finish__sep__01.solution.finished/rbb60w04h7/.env
+++ var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/full-stack-testing/exercises__sep__11.finish__sep__01.problem.finished/rbb60w04h7/.env
@@ -1,2 +1,6 @@
DATABASE_URL="file:./data.db"
SESSION_SECRET="super-duper-s3cret"
+RESEND_API_KEY="some-secret-key"
+GITHUB_TOKEN="MOCK_abc12392lfkjlsf0"
+GITHUB_CLIENT_ID="MOCK_Iv1.abc12392lfkjlsf0"
export const sessionKey = 'sessionId'
export const authenticator = new Authenticator<string>(sessionStorage, {
sessionKey,
})
authenticator.use(
new GitHubStrategy(
{
clientID: process.env.GITHUB_CLIENT_ID,