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: Cloudinary upload
// Description: Upload an image to cloudinary
// Shortcut: command option control c
// Author: Kent C. Dodds
// Twitter: @kentcdodds
import path from 'path'
const cloudinaryCloudName = await env('CLOUDINARY_CLOUD_NAME')
const cloudinaryKey = await env('CLOUDINARY_API_KEY')
@kentcdodds
kentcdodds / useOnRead.tsx
Last active June 9, 2021 04:24
How I determine whether you've read a blog post.
function useOnRead({
parentElRef,
onRead,
enabled = true,
}: {
parentElRef: React.RefObject<HTMLElement>
onRead: () => void
enabled: boolean
}) {
React.useEffect(() => {
// Menu: Shorten
// Description: Shorten a given URL with a given short name via netlify-shortener
// Shortcut: command option control s
// Author: Kent C. Dodds
// Twitter: @kentcdodds
const dir = await env(
'SHORTEN_REPO_DIRECTORY',
'Where is your netlify-shortener repo directory?',
)
// 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 fs from 'fs'
import {fileURLToPath, URL} from 'url'
const exiftool = await npm('node-exiftool')
// Menu: Twimage Download
// Description: Download twitter images and set their exif info based on the tweet metadata
// Shortcut: fn ctrl opt cmd t
// Author: Kent C. Dodds
// Twitter: @kentcdodds
import fs from 'fs'
import {fileURLToPath, URL} from 'url'
const exiftool = await npm('node-exiftool')
@kentcdodds
kentcdodds / diff.js
Created April 29, 2021 17:23
A git diff for EpicReact workshops
const {spawnSync} = require('child_process')
const inquirer = require('inquirer')
const glob = require('glob')
async function go() {
const files = glob
.sync('src/+(exercise|final)/*.+(js|ts|tsx)', {
ignore: ['*.d.ts'],
})
.map(f => f.replace(/^src\//, ''))
@kentcdodds
kentcdodds / package.json
Last active February 6, 2023 14:57
Remove TS from EpicReact.dev workshops
{
"name": "remove-ts",
"version": "1.0.0",
"description": "I use this to automatically fix feedback links in my workshops",
"bin": "./remove-ts.js",
"dependencies": {
"@babel/core": "7.13.8",
"@babel/preset-typescript": "7.13.0",
"glob": "7.1.6"
}
@kentcdodds
kentcdodds / README.md
Last active February 6, 2025 01:55
Function syntaxes supported by TypeScript

TypeScript Function Syntaxes

I'm trying to create examples of all the different ways to write functions and function type definitions in TypeScript.

One requirement is these examples must work with strict mode (noImplicitAny, etc) enabled.

If I'm missing anything, please add comments below with examples. I'll eventually put this into a blog post.

@kentcdodds
kentcdodds / .gitignore
Last active November 28, 2023 17:31
This will create a Google Voice "native" app on your computer
node_modules
@kentcdodds
kentcdodds / index.js
Created December 6, 2020 05:46
Sync ConvertKit with TestingJavaScript.com
const fs = require('fs/promises')
const fetch = require('make-fetch-happen').defaults({
cacheManager: './node_modules/.cache/make-fetch-happen',
})
const csv = require('csvtojson')
const {CONVERT_KIT_API_KEY, CONVERT_KIT_API_SECRET} = process.env
const levels = ['standard-testing', 'basic-testing', 'pro-testing']