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 / output
Created September 21, 2021 22:15
esbuild failure logs (full logs)
<--- Last few GCs --->
[31642:0x7f9d20008000] 105486 ms: Mark-sweep 4036.6 (4130.1) -> 4029.6 (4136.2) MB, 4756.1 / 0.1 ms (average mu = 0.356, current mu = 0.022) allocation failure scavenge might not succeed
[31642:0x7f9d20008000] 110156 ms: Mark-sweep 4045.6 (4136.4) -> 4038.4 (4144.9) MB, 4559.2 / 0.1 ms (average mu = 0.223, current mu = 0.024) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0x1040ea3a5 node::Abort() (.cold.1) [/Users/kentcdodds/n/bin/node]
2: 0x102dc5869 node::Abort() [/Users/kentcdodds/n/bin/node]
3: 0x102dc59df node::OnFatalError(char const*, char const*) [/Users/kentcdodds/n/bin/node]
4: 0x102f44347 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/kentcdodds/n/bin/node]
5: 0x102f442e3 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/kentcdodds/n/bin/node]
// Menu: New Post
// Description: Create a new blog post
// Author: Kent C. Dodds
// Shortcut: command option control p
// Twitter: @kentcdodds
const dateFns = await npm('date-fns')
const prettier = await npm('prettier')
const YAML = await npm('yaml')
const slugify = await npm('@sindresorhus/slugify')
@kentcdodds
kentcdodds / tag.js
Created August 9, 2021 20:34
Tag subscribers of a ConvertKit sequence with a tag
const fetch = require('make-fetch-happen').defaults({
cacheManager: './node_modules/.cache/make-fetch-happen',
})
// add a .env file that has this in it:
// CONVERT_KIT_API_KEY=some_api_key
// CONVERT_KIT_API_SECRET=some_api_secret
require('dotenv').config()
const {CONVERT_KIT_API_KEY, CONVERT_KIT_API_SECRET} = process.env
@kentcdodds
kentcdodds / most-popular-posts.ts
Created July 30, 2021 19:09
Prisma is awesome. I love this!
@kentcdodds
kentcdodds / cachified.ts
Last active April 19, 2023 04:54
Turn any function into a cachified one. With forceFresh support and value checking (for when the data type changes). This uses redis, but you could change it to use whatever you want.
type CacheMetadata = {
createdTime: number
maxAge: number | null
expires: number | null
}
function shouldRefresh(metadata: CacheMetadata) {
if (metadata.maxAge) {
return Date.now() > metadata.createdTime + metadata.maxAge
}
// Menu: Daily Story
// Description: Write a quick story
// Author: Kent C. Dodds
// Shortcut: command option control o
// Twitter: @kentcdodds
const dateFns = await npm('date-fns')
const filenamify = await npm('filenamify')
const prettier = await npm('prettier')
@kentcdodds
kentcdodds / parse-multipart-form-data.ts
Created July 14, 2021 21:13
I thought I needed this but turns out I didn't. None of the existing solutions worked well for me so I built this. Maybe it'll be useful someday...
import {typedBoolean} from './misc'
function headerValuesAsObject(headerValue: string) {
const valuesAsObject: Record<string, string> = Object.fromEntries(
headerValue
.split(', ')
.filter(h => h.includes('='))
.map(h => {
const [key, valueString] = h.split('=')
if (!valueString) return []
@kentcdodds
kentcdodds / index.js
Created July 9, 2021 21:40
Parsing HTML or Markdown and processing both as markdown then outputting to HTML
const unified = require('unified')
const parseMarkdown = require('remark-parse')
const parseHtml = require('rehype-parse')
const remark2rehype = require('remark-rehype')
const rehype2remark = require('rehype-remark')
const rehypeStringify = require('rehype-stringify')
const visit = require('unist-util-visit')
async function go() {
const inputString = `
// Menu: ConvertKit > Lookup
// Description: Query convertkit
// Author: Kent C. Dodds
// Twitter: @kentcdodds
const CONVERT_KIT_API_SECRET = await env('CONVERT_KIT_API_SECRET')
const CONVERT_KIT_API_KEY = await env('CONVERT_KIT_API_KEY')
const query = await arg('query')
let url
@kentcdodds
kentcdodds / rmx-snippet-output.tsx
Created June 30, 2021 21:57
Remix snippet for a new module
import * as React from 'react'
import type {LoaderFunction, ActionFunction} from 'remix'
import {json, redirect, useRouteData, Form} from 'remix'
type LoaderData = {}
export const loader: LoaderFunction = async () => {
const data: LoaderData = {}
return json(data)
}