This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getMostPopularPostSlugs({ | |
limit, | |
exclude, | |
}: { | |
limit: number | |
exclude: Array<string> | |
}) { | |
const result = await prisma.postRead.groupBy({ | |
by: ['postSlug'], | |
_count: true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type CacheMetadata = { | |
createdTime: number | |
maxAge: number | null | |
expires: number | null | |
} | |
function shouldRefresh(metadata: CacheMetadata) { | |
if (metadata.maxAge) { | |
return Date.now() > metadata.createdTime + metadata.maxAge | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createSimpleContext<ContextType>(name: string) { | |
const defaultValue = Symbol(`Default ${name} context value`) | |
const Context = | |
React.createContext<ContextType | null | typeof defaultValue>(defaultValue) | |
Context.displayName = name | |
function useValue() { | |
const user = React.useContext(Context) | |
if (user === defaultValue) { | |
throw new Error(`use${name} must be used within ${name}Provider`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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') |