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/image-url.jpg%20%22Optional%20title%22?q=function&page=2407&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 28554 results for "function"(2960ms)

denoGameHTMLmain.tsx9 matches

@jongreer•Updated 7 months ago
27 };
28
29 function setup() {
30 createCanvas(800, 300);
31 resetGame();
32 }
33
34 function resetGame() {
35 dino = new Dino();
36 obstacles = [];
41 }
42
43 function draw() {
44 if (isGameOver) {
45 showGameOver();
94 }
95
96 function keyPressed() {
97 if (keyCode === 32) {
98 if (isGameOver) {
107 }
108
109 function gameOver() {
110 isGameOver = true;
111 let name = prompt("Enter your name (max 16 characters, no spaces):");
113 scoreboard.push({ name, score });
114
115 // Call the function to update the scoreboard on the Val Town API
116 updateScoreboard(name, score);
117 }
118
119 function updateScoreboard(name, score) {
120 const apiUrl =
121 "https://api.val.town/v1/run/rodrigotello.updateDinoScoreboard";
147 }
148
149 function showGameOver() {
150 background(255);
151 textAlign(CENTER);
176 }
177
178 function showGamePaused() {
179 background(255);
180 textAlign(CENTER);

smallAndCuteSnakeGamemain.tsx3 matches

@jake•Updated 7 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 const [count, setCount] = useState(0);
7
55}
56
57function client() {
58 createRoot(document.getElementById("root")).render(<App />);
59}
63}
64
65export default async function server(request: Request): Promise<Response> {
66 return new Response(`
67 <!DOCTYPE html>

mortgageDeductionCalculatormain.tsx5 matches

@mikaello•Updated 7 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function formatNumber(num: number): string {
6 return num.toLocaleString("no-NO", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
7}
8
9function QuestionMarkIcon() {
10 return (
11 <svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" className="question-mark-icon">
16}
17
18function App() {
19 const [mortgage, setMortgage] = useState<number | undefined>(undefined);
20 const [rentPercentage, setRentPercentage] = useState<number | undefined>(undefined);
197}
198
199function client() {
200 createRoot(document.getElementById("root")).render(<App />);
201}
202if (typeof document !== "undefined") { client(); }
203
204export default async function server(request: Request): Promise<Response> {
205 return new Response(
206 `

groceriesmain.tsx3 matches

@efoley•Updated 7 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 const [items, setItems] = useState([]);
7 const [newItem, setNewItem] = useState("");
75}
76
77function client() {
78 createRoot(document.getElementById("root")).render(<App />);
79}
83}
84
85export default async function server(request: Request): Promise<Response> {
86 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
87 const SCHEMA_VERSION = 1;

createFlashcardsValmain.tsx3 matches

@reginafoley•Updated 7 months ago
9cherry,a small round stone fruit with red skin`;
10
11function App() {
12 const [flashcards, setFlashcards] = useState([]);
13 const [currentCard, setCurrentCard] = useState(null);
95}
96
97function client() {
98 createRoot(document.getElementById("root")).render(<App />);
99}
103}
104
105export default async function server(request: Request): Promise<Response> {
106 const url = new URL(request.url);
107

browserbasePuppeteerExamplemain.tsx2 matches

@Joelsrubin•Updated 7 months ago
2import puppeteer from "npm:puppeteer-core";
3
4async function sendPDF() {
5 console.log("Initiating pdf sender");
6 const browser = await puppeteer.connect({
28}
29
30export default async function() {
31 console.log("RUnning");
32 await sendPDF();

generateDailyTwitterEmailmain.tsx3 matches

@Joelsrubin•Updated 7 months ago
1import { email } from "https://esm.town/v/std/email";
2
3async function fetchTweets(listId: string): Promise<any[]> {
4 const url = `https://news.ycombinator.com/`;
5 const response = await fetch(url);
17}
18
19function formatTweetsForEmail(tweets: any[]): string {
20 return tweets.map((tweet, index) => `
21 ${index + 1}. @${tweet.username} (${tweet.likes} likes)
25}
26
27export default async function(interval: Interval) {
28 const listId = "1359390628841480192";
29 const tweets = await fetchTweets(listId);

randomTextGeneratormain.tsx3 matches

@aleaf•Updated 7 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 const [paragraphs, setParagraphs] = useState(1);
7 const [text, setText] = useState("");
64}
65
66function client() {
67 createRoot(document.getElementById("root")).render(<App />);
68}
69if (typeof document !== "undefined") { client(); }
70
71export default async function server(request: Request): Promise<Response> {
72 const url = new URL(request.url);
73 const paragraphs = Number(url.searchParams.get("paragraphs")) || 1;

anthropicCachingmain.tsx8 matches

@jake•Updated 7 months ago
1/**
2 * This val creates an interactive webpage that demonstrates the functionality of the Anthropic API.
3 * It uses a React frontend with an input for the API key and buttons to trigger different operations.
4 * The Anthropic API key is stored in the frontend state and sent with each API request.
9import { createRoot } from "https://esm.sh/react-dom/client";
10
11function App() {
12 const [apiKey, setApiKey] = useState("");
13 const [outputs, setOutputs] = useState({
82}
83
84function client() {
85 createRoot(document.getElementById("root")).render(<App />);
86}
90}
91
92async function server(request: Request): Promise<Response> {
93 const url = new URL(request.url);
94
138}
139
140async function fetchContent(): Promise<string> {
141 const response = await fetch("https://www.gutenberg.org/cache/epub/1342/pg1342.txt");
142 const text = await response.text();
146}
147
148async function runNonCachedCall(apiKey: string): Promise<string> {
149 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
150 const client = new anthropic.Anthropic({ apiKey });
182}
183
184async function runCachedCall(apiKey: string): Promise<string> {
185 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
186 const client = new anthropic.Anthropic({ apiKey });
221}
222
223async function runMultiTurnConversation(apiKey: string): Promise<string> {
224 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
225 const client = new anthropic.Anthropic({ apiKey });

anthropicCachingmain.tsx8 matches

@stevekrouse•Updated 7 months ago
1/**
2 * This val creates an interactive webpage that demonstrates the functionality of the Anthropic API.
3 * It uses a React frontend with an input for the API key and buttons to trigger different operations.
4 * The Anthropic API key is stored in the frontend state and sent with each API request.
9import { createRoot } from "https://esm.sh/react-dom/client";
10
11function App() {
12 const [apiKey, setApiKey] = useState("");
13 const [outputs, setOutputs] = useState({
82}
83
84function client() {
85 createRoot(document.getElementById("root")).render(<App />);
86}
90}
91
92async function server(request: Request): Promise<Response> {
93 const url = new URL(request.url);
94
138}
139
140async function fetchContent(): Promise<string> {
141 const response = await fetch("https://www.gutenberg.org/cache/epub/1342/pg1342.txt");
142 const text = await response.text();
146}
147
148async function runNonCachedCall(apiKey: string): Promise<string> {
149 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
150 const client = new anthropic.Anthropic({ apiKey });
182}
183
184async function runCachedCall(apiKey: string): Promise<string> {
185 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
186 const client = new anthropic.Anthropic({ apiKey });
221}
222
223async function runMultiTurnConversation(apiKey: string): Promise<string> {
224 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
225 const client = new anthropic.Anthropic({ apiKey });

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 1 month ago
Simple functional CSS library for Val Town
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": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.