View createPublicS3Bucket.js
This file contains 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
// Create the bucket | |
const bucketName = await getBucketName() | |
const createBucketCommand = new CreateBucketCommand({ | |
Bucket: bucketName, | |
ObjectOwnership: "ObjectWriter", | |
}) | |
await s3.send(createBucketCommand) | |
// Delete the block public access | |
const deletePublicAccessBlockCommand = new DeletePublicAccessBlockCommand({ |
View scratchpad.js
This file contains 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 getNumMatchesAtCoordinate(matrix, x, y) { | |
const match = matrix[x][y]; // 1st is row, 2nd is col | |
let numMatches = 0; // at least 1 match | |
const maxLength = Math.min(matrix.length - x, matrix[0].length - y); | |
for (let i = 0; i < maxLength; i++) { | |
// increment row | |
let isMatch = true; | |
for (let j = 0; j <= i; j++) { | |
// increment col | |
// checks outermost row and column in the growing square |
View api-utils.ts
This file contains 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 { NextApiRequest, NextApiResponse } from "next"; | |
export async function handleApiRequest( | |
req: NextApiRequest, | |
res: NextApiResponse, | |
expectedReqMethod: string, | |
handleRequest: (body: any) => Promise<any> | |
): Promise<void> { | |
if (req.method === expectedReqMethod) { | |
try { |
View transferToS3.ts
This file contains 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 AWS from "aws-sdk" | |
AWS.config.update({ | |
region: process.env.AWS_REGION, | |
accessKeyId: process.env.AWS_ACCESS_KEY_ID, | |
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, | |
}) | |
const s3 = new AWS.S3() | |
const BUCKET = "your-bucket-name" |
View FadeIn.tsx
This file contains 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 React, { useEffect, useState } from "react" | |
const FadeIn = ({ | |
children, | |
}: { | |
children: JSX.Element | JSX.Element[] | string | |
}) => { | |
const [animate, setAnimate] = useState("opacity-0 translate-y-10") | |
useEffect(() => { |
View nextjs-api-stream-hooks.ts
This file contains 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
// use this hook to fetch data from a stream | |
// get the cumulative response as it is read | |
export const useStreamingDataFromPrompt = async ( | |
prompt: string, | |
onData: (data: string) => void, | |
onDone?: () => void | |
) => { | |
const response = await fetch("/api/generate", { | |
method: "POST", | |
headers: { |
View Fetch Example
This file contains 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
fetch('https://example.com').then(response => { | |
if (!response.ok) { | |
throw Error(response.statusText); | |
} | |
return response.json(); | |
}) | |
.then(data => { | |
res.status(200).json({ data }) | |
}) |
View CodeBlock.js
This file contains 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 Highlight, { defaultProps } from "prism-react-renderer" | |
import github from "prism-react-renderer/themes/github" | |
const CodeBlock = ({ children, className }) => { | |
const language = className ? className.replace(/language-/, "") : "javascript" | |
return ( | |
<Highlight | |
{...defaultProps} | |
code={children} | |
language={language} |
View stockBuySell.js
This file contains 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 stockBuySell = (days) => { | |
const best = days.reduce((bestResult, price, i) => { | |
const buyDays = days.slice(i+1) | |
if (buyDays.length) { | |
const highest = Math.max.apply(null, days.slice(i+1)) | |
const roi = highest - price | |
if (roi > bestResult.roi) { | |
bestResult = {buyDay: i, sellDay: days.indexOf(highest), roi} | |
} | |
} |
View prettier.package.json
This file contains 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
{ | |
"scripts": { | |
"format": "prettier --write \"**/*.{js,jsx,json,md}\"", | |
"format-watch": "npm run format && onchange \"**/*.{js,jsx,json,md}\" -- prettier --write {{changed}}", | |
}, | |
"devDependencies": { | |
"onchange": "^7.0.2", | |
"prettier": "^2.0.5" | |
} | |
} |
NewerOlder