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=1446&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 18955 results for "function"(1555ms)

createFlashcardsValmain.tsx3 matches

@reginafoley•Updated 6 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 6 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 6 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 6 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 6 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 6 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 });

superiorHarlequinUrialmain.tsx1 match

@junkerman2004•Updated 6 months ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(req: Request): Promise<Response> {
4 if (req.method === "OPTIONS") {
5 return new Response(null, {

wallpapermain.tsx1 match

@Phaeris•Updated 6 months ago
1export default async function(req: Request): Promise<Response> {
2 const url =
3 "https://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=9&pid=hp&FORM=BEHPTB&uhd=1&uhdwidth=3840&uhdheight=2160&setmkt=zh-CN&setlang=en";

lastloginmain.tsx4 matches

@elliotbraem•Updated 6 months ago
1/** @jsxImportSource npm:hono/jsx */
2async function createSession(email: string, hostname: string) {
3 const { zip } = await import("https://esm.town/v/pomdtr/sql");
4 const { sqlite } = await import("https://esm.town/v/std/sqlite");
23}
24
25async function getSession(sessionID: string, hostname: string) {
26 const { zip } = await import("https://esm.town/v/pomdtr/sql");
27 const { sqlite } = await import("https://esm.town/v/std/sqlite");
52}
53
54async function deleteSession(sessionID: string) {
55 const { sqlite } = await import("https://esm.town/v/std/sqlite");
56
64const OAUTH_COOKIE = "oauth_store";
65
66export function lastlogin(
67 handler: (req: Request) => Response | Promise<Response>,
68) {

iosMobileConfigMultipleWebClipmain.tsx8 matches

@g•Updated 6 months ago
9import { v4 as uuidv4 } from 'https://esm.sh/uuid';
10
11function html() {
12 /*
13<!DOCTYPE html>
100}
101
102function css() {
103 /*
104body {
229}
230
231function js() {
232 /*
233import { v4 as uuidv4 } from 'https://esm.sh/uuid';
244addWebClipButton.addEventListener('click', addWebClip);
245
246function addWebClip() {
247 const webClip = document.createElement('div');
248 webClip.className = 'web-clip';
281}
282
283function attachIconChoiceListeners(index) {
284 const useDefaultIcon = document.getElementById(`useDefaultIcon-${index}`);
285 const useCustomIcon = document.getElementById(`useCustomIcon-${index}`);
290}
291
292function toggleCustomIconGroup(customIconGroup) {
293 customIconGroup.style.display = customIconGroup.style.display === 'none' ? 'block' : 'none';
294}
338});
339
340async function convertToBase64(file) {
341 return new Promise((resolve, reject) => {
342 const reader = new FileReader();
347}
348
349function generateMobileConfig(data, webClips) {
350 const webClipConfigs = webClips.map((clip, index) => `
351 <dict>

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 2 weeks 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": "*",