Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=function&page=1027&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 16756 results for "function"(2026ms)

webAppForRDSBlueGreenmain.tsx3 matches

@BaronVonLeskis•Updated 2 months ago
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4
5function PostgreSQLParameterCalculator() {
6 const instanceTypes = [
7 {
261}
262
263function client() {
264 createRoot(document.getElementById("root")).render(<PostgreSQLParameterCalculator />);
265}
267if (typeof document !== "undefined") { client(); }
268
269export default async function server(request: Request): Promise<Response> {
270 return new Response(`
271 <html>

statusmain.tsx3 matches

@BaronVonLeskis•Updated 2 months ago
5import { renderToString } from "npm:react-dom/server";
6
7function StatusRow({ rows }) {
8 return (
9 <div className="w-full flex flex-col space-y-2">
28}
29
30function StatusSection({ url, rows }) {
31 const sectionRows = rows.filter(row => row[0] === url);
32 const percentUp = Math.round((sectionRows.filter(row => row[1]).length / sectionRows.length) * 100);
44}
45
46export default async function(req: Request): Promise<Response> {
47 const { rows } = await sqlite.execute(
48 "select url, ok, duration, timestamp from uptime order by timestamp desc limit 200",

isMyWebsiteDownmain.tsx1 match

@BaronVonLeskis•Updated 2 months ago
6);
7
8export async function uptimeCheck(url: string) {
9 let ok = true;
10 let reason: string;

OpenTowniesystem_prompt.txt17 matches

@AIWB•Updated 2 months ago
10 1. `http`: http vals export a default server request handler.
11 2. `script`: script vals can be imported into other vals, similar to an npm package.
12 3. `cron`: cron vals export a function that can automatically run at user-set intervals, similar to a cron command.
13 4. `email`: email vals export a function that runs when its associated email address receives an email.
14
15Follow these requirements for Val Town when generating code.
49</requirements>
50
51If the user asks for specific functionality, the Val Town standard library includes the following:
52
53<libraries>
63 ```
64
65 Blob storage only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
66 `const { blob } = await import("https://esm.town/v/std/blob");`
67 </library>
78 If you are changing a SQLite table's schema, you should also change the table's name so it creates a fresh table, ie by adding _2 or _3 after it everywhere. Ensure that tables are created before they are used.
79
80 SQLite storage only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
81 `const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");`
82 </library>
99 ```
100
101 OpenAI only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
102 `const { OpenAI } = await import "https://esm.town/v/std/openai");`
103 </library>
113 ```
114
115 Email only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
116 `const { email } = await import "https://esm.town/v/std/email");`
117 </library>
131 Write the code in ```val code fences.
132 Include the val type as metadata on the code fence, e.g.: ```val type=script
133 If this is a new val, decide what val type is appropriate based on the user's prompt. Default to choosing http type vals unless the user has requested specific functionality that requires a different type.
134
135 * If the user requests diff format in their prompt, follow these steps:
157 * Use fetch to communicate with the backend server portion.
158 */
159function App() {
160 return (
161 <div>
167/**
168 * Client-only code
169 * Any code that makes use of document or window should be scoped to the `client()` function.
170 * This val should not cause errors when imported as a module in a browser.
171 */
172function client() {
173 createRoot(document.getElementById("root")).render(<App />);
174}
177/**
178 * Server-only code
179 * Any code that is meant to run on the server should be included in the server function.
180 * This can include endpoints that the client side component can send fetch requests to.
181 */
182export default async function server(request: Request): Promise<Response> {
183 /** If needed, blob storage or sqlite can be imported as a dynamic import in this function.
184 * Blob storage should never be used in the browser directly.
185 * Other server-side specific modules can be imported in a similar way.
232 ```val type=script
233 /** Use this template for creating script vals only */
234 export default function () {
235 return "Hello, world";
236 }
243 ```val type=cron
244 /** Use this template for creating cron vals only */
245 export default async function (interval: Interval) {
246 // code will run at an interval set by the user
247 console.log(`Hello, world: ${Date.now()}`);
270 // The email address for this val will be `<username>.<valname>@valtown.email` which can be derived from:
271 // const emailAddress = new URL(import.meta.url).pathname.split("/").slice(-2).join(".") + "@valtown.email";
272 export default async function (e: Email) {
273 console.log("Email received!", email.from, email.subject, email.text);
274 }

OpenTownieindex4 matches

@AIWB•Updated 2 months ago
5import { generateCodeAnthropic, makeFullPrompt } from "./backend/generateCode";
6
7function App() {
8 const [messages, setMessages] = useState<{ content: string; role: string }[]>([]);
9 const [inputMessage, setInputMessage] = useState("make a todo app");
11 const [bearerToken, _setBearerToken] = useState(localStorage.getItem("val-town-bearer"));
12
13 function setBearerToken(token: string) {
14 _setBearerToken(token);
15 localStorage.setItem("val-town-bearer", token);
79}
80
81function client() {
82 createRoot(document.getElementById("root")).render(<App />);
83}
84if (typeof document !== "undefined") { client(); }
85
86export default async function server(req: Request): Promise<Response> {
87 // console.log(req);
88 if (req.method === "POST") {

OpenTowniegenerateCode2 matches

@AIWB•Updated 2 months ago
1import OpenAI from "https://esm.sh/openai";
2
3function parseValResponse(response: string) {
4 const codeBlockRegex = /```val type=(\w+)\n([\s\S]*?)```/;
5 const match = response.match(codeBlockRegex);
25}
26
27export async function generateCodeAnthropic(messages: Message[]): Promise<ValResponse | null> {
28 const system = await (await fetch(`${import.meta.url.split("/").slice(0, -1).join("/")}/system_prompt.txt`)).text();
29

HorrorGamemain.tsx3 matches

@Manju•Updated 2 months ago
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4
5function HorrorGame() {
6 const [gameState, setGameState] = useState({
7 scene: "start",
88}
89
90function client() {
91 createRoot(document.getElementById("root")).render(<HorrorGame />);
92}
93if (typeof document !== "undefined") { client(); }
94
95export default async function server(request: Request): Promise<Response> {
96 return new Response(`
97 <html>

sereneTanWolfmain.tsx3 matches

@Manju•Updated 2 months ago
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4
5function LinkInBio() {
6 const links = [
7 // Placeholder links to be customized
63}
64
65function client() {
66 createRoot(document.getElementById("root")).render(<LinkInBio />);
67}
68if (typeof document !== "undefined") { client(); }
69
70export default async function server(request: Request): Promise<Response> {
71 return new Response(`
72 <html>

ThumbMakermain.tsx7 matches

@AIWB•Updated 2 months ago
2 * This application creates a thumbnail maker using Hono for server-side routing and client-side JavaScript for image processing.
3 * It allows users to upload images, specify output options, and generate a composite thumbnail image.
4 * The app uses the HTML5 Canvas API for image manipulation and supports drag-and-drop functionality.
5 *
6 * The process is divided into two steps:
18import { Hono } from 'npm:hono';
19
20function html() {
21 /*
22<!DOCTYPE html>
81}
82
83function css() {
84 /*
85body {
216}
217
218function js() {
219 /*
220const fileInput = document.getElementById('fileInput');
240let thumbnailMetadata;
241
242function updateUI() {
243 generateBtn.disabled = files.length === 0;
244 thumbWidth.disabled = keepAspectRatio.checked;
245}
246
247function resetToStep1() {
248 thumbnailOptions.style.display = 'block';
249 renderOptions.style.display = 'none';
375});
376
377function getImage(file) {
378 return new Promise((resolve) => {
379 const url = URL.createObjectURL(file);

openGreenVicunamain.tsx1 match

@ecezarif•Updated 2 months ago
15}
16
17export default function analyzeLotteryDraws() {
18 const drawData: LotteryDraw[] = [
19 { drawNumber: 14, date: "31.01.2024-21:30", numbers: [9, 13, 79, 83, 84, 89, 18, 4] },

getFileEmail4 file matches

@shouser•Updated 1 week ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblk•Updated 1 week ago
Simple functional CSS library for Val Town
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",