whenfilmedmain.tsx7 matches
13}
1415async function fetchRandomMovies() {
16const currentYear = new Date().getFullYear()
17const movies = []
35}
3637function generateQuizHTML(movies, uuid) {
38const currentYear = new Date().getFullYear()
39return `
52</style>
53<script>
54function updateInputs(index, value) {
55document.getElementById('guess' + index).value = value;
56document.getElementById('guessInput' + index).value = value;
91}
9293function calculateScore(movies, guesses) {
94return movies.reduce((score, movie, index) => {
95const actualYear = new Date(movie.release_date).getFullYear()
102}
103104function generateResultsHTML(movies, guesses, score) {
105return `
106<html>
152}
153154function generateAllGuessesHTML(allGuesses) {
155return `
156<html>
198}
199200export default async function main(req: Request): Promise<Response> {
201const { author, name } = extractValInfo(import.meta.url)
202const guessesKey = `${author}.${name}.guesses`
azureCheetahmain.tsx14 matches
16import { renderToString } from "npm:react-dom/server";
1718export default function(
19{ tempValsParentFolderId }: { tempValsParentFolderId: string },
20) {
38the simplest way to achieve the goal, though you can add some inline comments to explain your
39reasoning (not for every line, but for major groups of lines). Don't use any environment variables
40unless strictly necessary, for example use APIs that don't require a key, prefer internal function
41imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
42functions where possible. Unless specified, don't add error handling,
43make sure that errors bubble up to the caller.
44Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
51\`\`\`
52There should be no comments like "more content here", it should be complete and directly runnable.
53The val should create a "export default async function main" which is the main function that gets
54executed on every HTTP request.
55`.replace("\n", " ");
5657// Your response should start with \`\`\`ts and end with \`\`\`.
58// The val should create a "export default async function main() {" which
59// is the main function that gets executed, without any arguments. Don't return a Response object,
60// just return a plain Javascript object, array, or string.
6198const writer = writable.getWriter();
99const textEncoder = new TextEncoder();
100function write(text) {
101writer.write(textEncoder.encode(text));
102}
174</div>
175<script>
176function updateValName(valName) {
177const valUrl = valName ? \`https://val.town/v/${username}/\${valName}\` : "";
178const previewUrl = valName ? \`https://${username}-\${valName}.web.val.run\` : "";
182document.getElementById('open-link').href = previewUrl;
183}
184function saveVal() {
185if (window.codeMirrorEditor) {
186document.getElementById("save-icon").classList.remove("hidden");
202return false;
203})
204function openTab(tab) {
205const tabButtonCode = document.getElementById("tab-button-code");
206const tabButtonPreview = document.getElementById("tab-button-preview");
222}
223}
224function toggleTab() {
225openTab(document.getElementById("tab-panel-code").style.visibility === "visible" ? "preview" : "code");
226}
281(() => {
282const scrollingElement = document.getElementById("conversation-container");
283const callback = function (mutationsList, observer) {
284scrollingElement.scrollTo({ left: 0, top: scrollingElement.scrollHeight, behavior: "instant" });
285};
390window.setCodeMirrorContent({ doc: '', old: ''});
391let fullStr = "";
392window.addToken = function(str) {
393fullStr += str;
394const code = fullStr.replaceAll("\`\`\`ts\\n", "").replaceAll("\`\`\`", "").replace(/^ts\\n/, '');
429},
430);
431(async function() {
432try {
433await sleep(300);
16import { renderToString } from "npm:react-dom/server";
1718export default function(
19{ tempValsParentFolderId }: { tempValsParentFolderId: string },
20) {
38the simplest way to achieve the goal, though you can add some inline comments to explain your
39reasoning (not for every line, but for major groups of lines). Don't use any environment variables
40unless strictly necessary, for example use APIs that don't require a key, prefer internal function
41imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
42functions where possible. Unless specified, don't add error handling,
43make sure that errors bubble up to the caller.
44Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
51\`\`\`
52There should be no comments like "more content here", it should be complete and directly runnable.
53The val should create a "export default async function main" which is the main function that gets
54executed on every HTTP request.
55`.replace("\n", " ");
5657// Your response should start with \`\`\`ts and end with \`\`\`.
58// The val should create a "export default async function main() {" which
59// is the main function that gets executed, without any arguments. Don't return a Response object,
60// just return a plain Javascript object, array, or string.
6198const writer = writable.getWriter();
99const textEncoder = new TextEncoder();
100function write(text) {
101writer.write(textEncoder.encode(text));
102}
174</div>
175<script>
176function updateValName(valName) {
177const valUrl = valName ? \`https://val.town/v/${username}/\${valName}\` : "";
178const previewUrl = valName ? \`https://${username}-\${valName}.web.val.run\` : "";
182document.getElementById('open-link').href = previewUrl;
183}
184function saveVal() {
185if (window.codeMirrorEditor) {
186document.getElementById("save-icon").classList.remove("hidden");
202return false;
203})
204function openTab(tab) {
205const tabButtonCode = document.getElementById("tab-button-code");
206const tabButtonPreview = document.getElementById("tab-button-preview");
222}
223}
224function toggleTab() {
225openTab(document.getElementById("tab-panel-code").style.visibility === "visible" ? "preview" : "code");
226}
281(() => {
282const scrollingElement = document.getElementById("conversation-container");
283const callback = function (mutationsList, observer) {
284scrollingElement.scrollTo({ left: 0, top: scrollingElement.scrollHeight, behavior: "instant" });
285};
390window.setCodeMirrorContent({ doc: '', old: ''});
391let fullStr = "";
392window.addToken = function(str) {
393fullStr += str;
394const code = fullStr.replaceAll("\`\`\`ts\\n", "").replaceAll("\`\`\`", "").replace(/^ts\\n/, '');
429},
430);
431(async function() {
432try {
433await sleep(300);
ReactStream_migratedREADME.md4 matches
7import { render, React } from "https://esm.town/v/jxnblk/ReactStream";
89function App() {
10const [count, setCount] = React.useState(0);
11return (
62```tsx
63// example middleware
64async function api (req: Request, res: Response, next): Promise<Response> {
65if (req.pathname !== "/api") return next();
66if (req.method === "POST") {
78```tsx
79// example middleware
80async function getInitialProps (req: Request, res: Response, next) {
81// fetch data or do async work to pass as props to the component
82req.data = {
95import { render } from "https://esm.town/v/jxnblk/ReactStream";
9697function App () {
98return (
99<html>
valleGetValsContextWindowmain.tsx7 matches
1export default async function getValsContextWindow(model: any) {
2const readmeVals: any = await (await fetch("https://janpaul123-readmevals.web.val.run/")).json();
3183import { render } from "npm:preact-render-to-string";
184
185export default async function(req: Request) {
186return new Response(
187render(
212const FLAT_TEMPLATES = sections.flatMap((section) => section.templates);
213214function tsResponse(code) {
215return "```ts\n" + code + "\n```";
216}
383### Utilities
384
385Our Blob SDK also includes some utility functions to make working with blobs easier.
386
387##### Copy
507role: "assistant",
508content:
509"\n```ts\nexport default async function (req: Request): Promise<Response> {\n return Response.json(\"Hello world\")\n}\n```",
510},
511{
516role: "assistant",
517content:
518"\n```ts\nexport default async function(req: Request): Promise<Response> {\n const query = new URL(req.url).searchParams;\n\n // Read name from the querystring or body. Defaults to \"you\" if not present.\n const name = query.get(\"name\") || (await req.json().catch(() => ({}))).name || \"you\";\n\n // Returns the HTML response\n return new Response(`<h1>Hi ${name}!</h1>`, {\n headers: { \"Content-Type\": \"text/html\" },\n });\n}\n```",
519},
520{
533role: "assistant",
534content:
535"```ts\nexport default async function(req: Request): Promise<Response> {\n const apiKey = Deno.env.get(\"METEO_KEY\");\n const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=40.6782&longitude=-73.9442&hourly=temperature_2m¤t_weather=true&apikey=${apiKey}`;\n\n const response = await fetch(apiUrl);\n const weatherData = await response.json();\n\n return new Response(JSON.stringify(weatherData), { headers: { \"Content-Type\": \"application/json\" } });\n}\n```",
536},
537{
infiniteSVGGraphmain.tsx6 matches
35// Database querying.
3637function parseResultSet<T>(row: ResultSet): T[] {
38return row.rows.map((r) => Object.fromEntries(r.map((c, i) => [row.columns[i], c]))) as T[];
39}
67};
6869// Client side javascript and template functions.
7071const clientJavascript = async () => {
135});
136137function createHeartBurst(event) {
138const button = event.currentTarget;
139const buttonContainer = button.closest(".heart-button-container");
174};
175176function escapeHTML(html: string): string {
177const escapeChars: { [char: string]: string } = {
178"&": "&",
408let encoder = new TextEncoder();
409410function isValidSVG(svgString) {
411const parser = new DOMParser({
412errorHandler: {
488489app.get("/:id/img.svg", async (c) => {
490function addSVGNamespace(svgString) {
491if (!/^<\?xml/.test(svgString)) svgString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + svgString;
492if (!/xmlns="http:\/\/www.w3.org\/2000\/svg"/.test(svgString))
twitterAlertmain.tsx1 match
3const query = "\"val.town\" OR \"val town\" -_ValTown_ -is:retweet"
45export async function twitterAlert({ lastRunAt }: Interval) {
6const results = await twitterSearch({
7query,
valTownBadgeSVGmain.tsx2 matches
9const padLeft = 48;
1011export function Badge({
12scale = 1,
13label = "View source on",
66}
6768export default async function(req: Request): Promise<Response> {
69const svg = renderToStaticMarkup(
70<Badge scale={1} />,
upgradeHTTPPreviewValsmain.tsx4 matches
3import OpenAI from "npm:openai";
45async function getVals(username, type, limit) {
6const res = await db.execute({
7sql: `
21}
2223async function checkHTTPPreviewUpgrade(code) {
24const openai = new OpenAI();
25const completion = await openai.chat.completions.create({
53content: `const number = Math.random();
54
55export default function(req: Request) {
56return Response.json(number);
57}`,
8081/* This example will return the contents of a documentID passed in as the path as JSON. */
82export default async function(req: Request): Promise<Response> {
83const docId = new URL(req.url).pathname.substring(1);
84
upgradeHTTPPreviewValsREADME.md5 matches
16"name": "harlequinChickadee",
17"probabilityUpgradeNeeded": true,
18"reason": "The current code structure has several functions and program logic outside the main handler, including word selection, game state management, and SVG generation. These parts would not re-run with the new runtime, potentially affecting functionality. They need to be moved inside the handler to ensure consistent behavior across requests."
19},
20{
31"name": "untitled_pinkRoundworm",
32"probabilityUpgradeNeeded": true,
33"reason": "The functions `addComment` and `getComments` as well as the initialization \nof the KEY variable perform actions that are intended to be run per request. These need to be moved \ninside the relevant HTTP handler to ensure the behavior remains consistent in the new runtime."
34},
35{
46"name": "untitled_maroonSwallow",
47"probabilityUpgradeNeeded": false,
48"reason": "All the code, including the check for authentication,\n is inside the handler function. This means the behavior will stay \n the same with the new runtime."
49},
50{
51"name": "wikiOG",
52"probabilityUpgradeNeeded": true,
53"reason": "The function `getWikipediaInfo` defined outside of the handler makes network requests and processes data for each request. In the new runtime, this function would only be executed once and cached. To ensure the same behavior in the new runtime, this function should be moved into the handler."
54},
55{
61"name": "discordEventReceiver",
62"probabilityUpgradeNeeded": false,
63"reason": "All the relevant code for handling requests and logging input is inside the handler.\n No code needs to be moved for the new runtime to function correctly."
64}
65]