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=1076&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 17288 results for "function"(1763ms)

cerebras_codermain.tsx11 matches

@gunisettigokul•Updated 3 months ago
26const PoweredByInfo = "";
27
28function Hero({
29 prompt,
30 setPrompt,
47
48 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
49 Turn your ideas into fully functional apps in{" "}
50 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
51 less than a second!
121}
122
123function App() {
124 const previewRef = React.useRef<HTMLDivElement>(null);
125 const [prompt, setPrompt] = useState("");
175 });
176
177 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
178 setLoading(true);
179 setTimeout(() => handleSubmit(promptItem.prompt), 0);
180 }
181
182 async function handleSubmit(e: React.FormEvent | string) {
183 if (typeof e !== "string") {
184 e.preventDefault();
231 }
232
233 function handleVersionChange(direction: "back" | "forward") {
234 const { currentVersionIndex, versions } = versionHistory;
235 if (direction === "back" && currentVersionIndex > 0) {
920);
921
922function client() {
923 const path = window.location.pathname;
924 const root = createRoot(document.getElementById("root")!);
956}
957
958function extractCodeFromFence(text: string): string {
959 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
960 return htmlMatch ? htmlMatch[1].trim() : text;
961}
962
963async function generateCode(prompt: string, currentCode: string) {
964 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
965 if (starterPrompt) {
1006}
1007
1008export default async function cerebras_coder(req: Request): Promise<Response> {
1009 // Dynamic import for SQLite to avoid client-side import
1010 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1109 <meta property="og:site_name" content="Cerebras Coder">
1110 <meta property="og:url" content="https://cerebrascoder.com"/>
1111 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1112 <meta property="og:type" content="website">
1113 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">

getLatestYouTubeVideoFromChannelmain.tsx1 match

@samkingco•Updated 3 months ago
1export async function getLatestYouTubeVideoFromChannel(channelId: string): Promise<
2 {
3 title: string;

rm_ios_testmain.tsx8 matches

@arfan•Updated 3 months ago
215 * Generates the main HTML shell, injecting the CSS and the client script.
216 */
217function generateHTML(importMetaUrl: string) {
218 return `
219<!DOCTYPE html>
236
237/**
238 * Server function that handles HTTP routes, DB setup, and returns HTML.
239 */
240export default async function server(request: Request): Promise<Response> {
241 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
242 const KEY = "rm_ios_test";
341 * React component that shows an individual app icon & title.
342 */
343function AppCard({ app, onEdit }: { app: App; onEdit: (app: App) => void }) {
344 // Click or "Enter" => open via iOS Shortcut
345 const handleClick = () => {
378 * Overlay to add or edit an app.
379 */
380function AppOverlay({
381 app,
382 onSave,
512 * Overlay for changing settings (e.g., grouping by category).
513 */
514function SettingsOverlay({
515 groupByCategory,
516 onChangeGroupByCategory,
558 * Main React component that displays the header, categories, apps, & state.
559 */
560function App() {
561 const [selectedCategory, setSelectedCategory] = useState("All");
562 const [apps, setApps] = useState<App[]>([]);
779 * Client entry-point to render the React App.
780 */
781function client() {
782 createRoot(document.getElementById("root")!).render(<App />);
783}

emailValHandlerNomain.tsx14 matches

@martinbowling•Updated 3 months ago
60import { pdfText } from "jsr:@pdf/pdftext";
61
62// Main controller function
63export default async function emailValHandler(receivedEmail) {
64 const openaiUrl = "https://api.openai.com/v1/chat/completions";
65 const openaiKey = Deno.env.get("OPENAI_API_KEY");
102
103// Extract attachments (if any)
104async function extractAttachments(email) {
105 if (!email.attachments || email.attachments.length === 0) {
106 return [];
119
120// Extract links from email text
121function extractLinks(text) {
122 const urlRegex = /(https?:\/\/[^\s]+)/g;
123 return text.match(urlRegex) || [];
125
126// Extract website markdown content
127async function extractWebsiteMarkdown(links, apiKey) {
128 const markdownResults = [];
129 const requestsPerMinute = 5;
170
171// Process image attachments with GPT-4V
172async function analyzeImage(imageAttachment, apiKey, transformedPrompt) {
173 try {
174 const response = await fetch("https://api.openai.com/v1/chat/completions", {
214
215// Transform the original prompt using the prompt transformer
216async function transformPrompt(emailText, openaiUrl, apiKey, model) {
217 const promptTransformerText =
218 `You are an AI assistant tasked with transforming user queries into structured research or information requests. Your goal is to take a simple query and expand it into a comprehensive research objective with specific formatting requirements.
304
305// Process all attachments (PDFs and Images)
306async function processAttachments(attachments, apiKey, transformedPrompt) {
307 const pdfTexts = [];
308 const imageAnalysis = [];
324}
325
326async function extractPdfText(attachments) {
327 const pdfTexts = [];
328
358
359// Generate the final prompt with all context
360function generateFinalPrompt(transformedPrompt, pdfTexts, imageAnalysis, websiteMarkdown, email) {
361 let contextDump = [];
362
382}
383
384// Helper function to send a request to OpenAI
385async function sendRequestToOpenAI(prompt, transformedPrompt, openaiUrl, apiKey, model) {
386 try {
387 // Debug logging for the prompt and transformed prompt
434}
435
436// Helper function to send a response back via email
437async function sendResponseByEmail(toEmail, responseContent) {
438 const subject = "AI Response to Your Email";
439 const text = `${responseContent}`;

tolerantOlivePonymain.tsx2 matches

@shawnsomething•Updated 3 months ago
2
3const service = new InferableService({
4 description: "My functions",
5 token: "sk-inf-val-29f8be75-ab85-49ac-8f68-7ed55f18c6bf",
6});
7
8service.registerFunction({
9 name: "date",
10 description: "Get the current date",

kanbanTodoListmain.tsx16 matches

@stevekrouse•Updated 3 months ago
8import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
9
10function TaskBoard() {
11 const [taskLists, setTaskLists] = useState({
12 todo: [],
44 }, []);
45
46 function loadUserPreferences() {
47 const savedDarkMode = localStorage.getItem("app-theme") === "true";
48 setIsDarkMode(savedDarkMode);
59 }
60
61 function updateAppStyle(font, size) {
62 document.body.style.setProperty("--app-font", font);
63 document.body.style.setProperty("--app-font-size", `${size}px`);
64 }
65
66 function saveUserPreferences() {
67 localStorage.setItem("app-font", chosenFont);
68 localStorage.setItem("app-font-size", fontSize.toString());
72 }
73
74 async function fetchTasks() {
75 try {
76 const response = await fetch("/get-tasks");
82 }
83
84 async function addNewTask() {
85 if (!newTaskText.trim()) return;
86
102 }
103
104 async function handleTaskMove(result) {
105 const { destination, source, draggableId } = result;
106 if (!destination) return;
123 }
124
125 async function removeTask(taskId, column) {
126 try {
127 const response = await fetch("/delete-task", {
137 }
138
139 async function moveTaskForward(task, currentColumn) {
140 const currentIndex = listProgression.indexOf(currentColumn);
141 const nextColumn = listProgression[currentIndex + 1];
158 }
159
160 function toggleDarkMode() {
161 const newDarkMode = !isDarkMode;
162 setIsDarkMode(newDarkMode);
165 }
166
167 function openEditModal(task) {
168 setTaskBeingEdited(task);
169 setEditedTaskText(task.title);
171 }
172
173 async function saveEditedTask() {
174 if (!editedTaskText.trim() || !taskBeingEdited) return;
175 try {
191 }
192
193 function handleTaskInteraction(e, task, column) {
194 if (e.button === 1) {
195 e.preventDefault();
432}
433
434function client() {
435 createRoot(document.getElementById("root")).render(<TaskBoard />);
436}
439}
440
441export default async function server(request: Request): Promise<Response> {
442 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
443 const KEY = "kanbanTodoList";
517}
518
519async function getAllTasks(sqlite, KEY, SCHEMA_VERSION) {
520 const todo = await sqlite.execute(
521 `SELECT * FROM ${KEY}_tasks_${SCHEMA_VERSION} WHERE column = 'todo'`,

cerebras_codermain.tsx5 matches

@Danap•Updated 3 months ago
6import { STARTER_PROMPTS } from "https://esm.town/v/stevekrouse/cerebras_coder_prompts";
7
8function extractCodeFromFence(content: string): string {
9 const codeMatch = content.match(/```html\n([\s\S]*?)```/);
10 return codeMatch ? codeMatch[1].trim() : content.trim();
11}
12
13async function generateCode(prompt: string, currentCode: string) {
14 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
15 if (starterPrompt) {
56}
57
58function App() {
59 const [prompt, setPrompt] = useState('');
60 const [generatedCode, setGeneratedCode] = useState('');
255}
256
257function client() {
258 // Add Tailwind CSS for styling
259 const tailwindScript = document.createElement('script');
265if (typeof document !== "undefined") { client(); }
266
267export default async function server(request: Request): Promise<Response> {
268 if (request.method === 'POST' && new URL(request.url).pathname === '/generate') {
269 try {

townieIllustratorPromptmain.tsx4 matches

@charmaine•Updated 3 months ago
3First ask a user what app they would like you to illustrate. Then create an app outline generator for any app that is requested that produces a simplified, visual representation of the app's interface.
4
5Core Functionality
6
7- Accept an app name as input (e.g., "Zoom", "Slack", "Discord")
8- Generate a single val that renders a minimal, branded mockup of the app's main interface
9- Allow the user to export a png screenshot with transparent background with rounded corners (8px radius)
10- Move the `html2canvas` import inside the `client()` function.
11- Wrap the `exportAsPNG` function in a `useEffect` hook to ensure it's only defined on the client-side.
12- Use dynamic import for `html2canvas` inside the `exportAsPNG` function.
13- Make sure html2canvas is only loaded and used on the client-side
14

townieIllustratorPromptREADME.md4 matches

@charmaine•Updated 3 months ago
6First ask a user what app they would like you to illustrate. Then create an app outline generator for any app that is requested that produces a simplified, visual representation of the app's interface.
7
8Core Functionality
9
10- Accept an app name as input (e.g., "Zoom", "Slack", "Discord")
11- Generate a single val that renders a minimal, branded mockup of the app's main interface
12- Allow the user to export a png screenshot with transparent background with rounded corners (8px radius)
13- Move the `html2canvas` import inside the `client()` function.
14- Wrap the `exportAsPNG` function in a `useEffect` hook to ensure it's only defined on the client-side.
15- Use dynamic import for `html2canvas` inside the `exportAsPNG` function.
16- Make sure html2canvas is only loaded and used on the client-side
17

preciseScarletHerringmain.tsx3 matches

@stevekrouse•Updated 3 months ago
3import React, { useState } from "https://esm.sh/react@18.2.0";
4
5function App() {
6 const [messages, setMessages] = useState([]);
7 const [input, setInput] = useState("");
71}
72
73function client() {
74 createRoot(document.getElementById("root")).render(<App />);
75}
79}
80
81export default async function server(request: Request): Promise<Response> {
82 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
83 const { messages } = await request.json();

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": "*",