Skip to content

Instantly share code, notes, and snippets.

View dbredvick's full-sized avatar

Drew Bredvick dbredvick

View GitHub Profile
@dbredvick
dbredvick / page.tsx
Created December 28, 2023 17:57
Stream markdown in RSC
import Markdown from "react-markdown"
import OpenAI from "openai"
import { OpenAIStream } from "ai"
async function Reader({
reader,
accumulatedText = "",
}: {
reader: ReadableStreamDefaultReader<Uint8Array>;
accumulatedText?: string;
@dbredvick
dbredvick / main.yml
Created May 13, 2022 21:36
github action
name: End-to-end tests
on: [deployment_status]
jobs:
cypress-run:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
containers: [1, 2, 3]
steps:
@dbredvick
dbredvick / example.js
Created January 3, 2022 17:54
Next.js Image caching / correct headers
// --- ✅ better caching
import imageSrc from '../public/images/image.png'
import Image from 'next/image'
return <Image src={imageSrc}/>
// --- ❌ worse caching
import Image from 'next/image'
@dbredvick
dbredvick / vercel.json
Last active September 9, 2021 18:39
create-react-app caching on Vercel
{
"headers": [
{
"source": "/static/:slug*",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=31536000"
}
]
const stanzaOne = `First they came for the socialists, and I did not speak out—
Because I was not a socialist.`
const stanzaTwo = `Then they came for the trade unionists, and I did not speak out—
Because I was not a trade unionist.`
const stanzaThree = `Then they came for the Jews, and I did not speak out—
Because I was not a Jew.`
const stanzaFour = `Then they came for me—and there was no one left to speak for me.`
@dbredvick
dbredvick / package.json
Created January 12, 2020 01:38
typescript nextjs twilio example package.json
{
"name": "resolution-reminder",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
@dbredvick
dbredvick / text.ts
Created January 12, 2020 00:22
NextJS Twilio Typescript example
import { NextApiResponse, NextApiRequest } from "next";
const twillio = require('twilio');
const authToken = process.env.TWILIO_AUTH_TOKEN;
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const myCellPhoneNumber = process.env.MY_NUMBER;
const superSecretAPIKey = 'ABCD1234';
export default async (req: NextApiRequest, res: NextApiResponse) => {
const client = twillio(accountSid, authToken);
const auth = req.headers.authorization;
@dbredvick
dbredvick / moment-holidays.js
Last active February 10, 2017 20:10 — forked from jrhames/moment-holidays.js
Holidays plugin for Moment.JS
//## Moment.JS Holiday Plugin
//
//Usage:
// Call .holiday() from any moment object. If date is a US Federal Holiday, name of the holiday will be returned.
// Otherwise, return nothing.
//
// Example:
// `moment('12/25/2013').holiday()` will return "Christmas Day"
//
//Holidays: