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 from "react" | |
const PrintObject: React.FC<{ object: Record<string, unknown> }> = ({ object }) => { | |
return ( | |
<pre className="w-full max-w-5xl overflow-scroll text-sm border bg-black text-white rounded p-2 "> | |
<code>{JSON.stringify(object, null, 2)}</code> | |
</pre> | |
) | |
} |
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"; | |
import cn from "mxcn"; | |
// or if using shadcn: | |
// import { cn } from "@/lib/utils"; // https://github.com/shadcn-ui/ui/blob/main/apps/www/lib/utils.ts | |
const AnimateIn = ({ | |
children, | |
delay = 0, | |
duration = 500, | |
className = "", |
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({ |
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 |
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 { |
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" |
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(() => { |
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: { |
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 }) | |
}) |
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} |
NewerOlder