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%22Image%20title%22?q=function&page=2309&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 28575 results for "function"(5160ms)

linearRegressionmain.tsx4 matches

@bao•Updated 5 months ago
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4
5function linearRegression(x: number[], y: number[]) {
6 const n = x.length;
7
22}
23
24function App() {
25 const [inputData, setInputData] = useState('');
26 const [result, setResult] = useState<{ slope?: number; intercept?: number }>({});
107}
108
109function client() {
110 createRoot(document.getElementById("root")).render(<App />);
111}
112if (typeof document !== "undefined") { client(); }
113
114export default async function server(request: Request): Promise<Response> {
115 return new Response(`
116 <html>

blob_adminmain.tsx8 matches

@dakota•Updated 5 months ago
13}
14
15function Tooltip({ children, content }: TooltipProps) {
16 const [isVisible, setIsVisible] = useState(false);
17 const tooltipRef = useRef<HTMLDivElement>(null);
52}
53
54function formatBytes(bytes: number, decimals = 2) {
55 if (bytes === 0) return "0 Bytes";
56 const k = 1024;
61}
62
63function copyToClipboard(text: string) {
64 navigator.clipboard.writeText(text).then(() => {
65 console.log("Text copied to clipboard");
69}
70
71function ActionMenu({ blob, onDownload, onRename, onDelete, onMoveToPublic, onMoveOutOfPublic }) {
72 const [isOpen, setIsOpen] = useState(false);
73 const menuRef = useRef(null);
76
77 useEffect(() => {
78 function handleClickOutside(event) {
79 if (menuRef.current && !menuRef.current.contains(event.target)) {
80 event.stopPropagation();
158}
159
160function BlobItem({ blob, onSelect, isSelected, onDownload, onRename, onDelete, onMoveToPublic, onMoveOutOfPublic }) {
161 const [isLoading, setIsLoading] = useState(false);
162 const decodedKey = decodeURIComponent(blob.key);
219}
220
221function App({ initialEmail, initialProfile }) {
222 const encodeKey = (key: string) => encodeURIComponent(key);
223 const decodeKey = (key: string) => decodeURIComponent(key);
645}
646
647function client() {
648 const initialEmail = document.getElementById("root").getAttribute("data-email");
649 const initialProfile = JSON.parse(document.getElementById("root").getAttribute("data-profile"));

dailyThoughtPromptmain.tsx1 match

@chrisputnam9•Updated 5 months ago
4import { email } from "https://esm.town/v/std/email";
5
6export default async function(interval: Interval) {
7 const TOPICS = [
8 "Productivity",

randoDiscmain.tsx8 matches

@stevekrouse•Updated 6 months ago
6console.log(AnimatePresence);
7
8function ErrorMessage({ message }) {
9 return (
10 <div className="min-h-screen bg-gray-100 flex items-center justify-center p-4">
17}
18
19function Loader() {
20 return (
21 <div className="flex flex-col items-center justify-center min-h-screen bg-gray-100">
57}
58
59function shuffleArray(array) {
60 const shuffledArray = [...array];
61 for (let i = shuffledArray.length - 1; i > 0; i--) {
66}
67
68function RecordCard() {
69 const [records, setRecords] = useState([]);
70 const [currentRecordIndex, setCurrentRecordIndex] = useState(0);
77
78 useEffect(() => {
79 async function fetchReleases() {
80 try {
81 const response = await fetch("https://ashryanio-getallreleasesfromdiscogs.web.val.run");
130
131 useEffect(() => {
132 function handleKeydown(event) {
133 if (
134 event.target.tagName.toLowerCase() !== "input"
340}
341
342function client() {
343 const rootElement = document.getElementById("root");
344 if (!rootElement) {
359}
360
361export default async function server(request: Request): Promise<Response> {
362 const url = new URL(request.url);
363

solicitousAmethystMeadowlarkmain.tsx1 match

@youtubefree•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, {

sendSassyEmailmain.tsx1 match

@transcendr•Updated 6 months ago
31};
32
33export default async function() {
34 const openai = new OpenAI();
35

Ms_Spanglermain.tsx11 matches

@arthrod•Updated 6 months ago
153 const typingIndicator = document.querySelector('.typing-indicator');
154
155 function addMessage(content, type) {
156 const messageElement = document.createElement('div');
157 messageElement.classList.add('message', type);
161 }
162
163 function loadChatHistories() {
164 try {
165 const savedChatsRaw = localStorage.getItem('chatHistories');
167
168 chatHistorySelect.innerHTML = '';
169 savedChats.forEach(function(chat, index) {
170 const option = document.createElement('option');
171 option.value = index;
178 }
179
180 function saveChat() {
181 try {
182 const chatName = prompt('Enter a name for this chat history:') || ('Chat ' + Date.now());
183 const messages = Array.from(chatMessages.children).map(function(msg) {
184 return {
185 content: msg.textContent,
200 }
201
202 function loadSelectedChat() {
203 try {
204 const selectedIndex = chatHistorySelect.value;
211 if (selectedChat) {
212 chatMessages.innerHTML = '';
213 selectedChat.messages.forEach(function(msg) {
214 addMessage(msg.content, msg.type === 'user' ? 'user-message' : 'ai-message');
215 });
221 }
222
223 function deleteSelectedChat() {
224 try {
225 const selectedIndex = chatHistorySelect.value;
239 }
240
241 async function sendMessage() {
242 const message = messageInput.value.trim();
243 if (!message) return;
270 loadButton.addEventListener('click', loadSelectedChat);
271 deleteButton.addEventListener('click', deleteSelectedChat);
272 messageInput.addEventListener('keypress', function(e) {
273 if (e.key === 'Enter') sendMessage();
274 });
308 } catch (error) {
309 console.error("OpenAI error:", error);
310 return c.json({ response: "Neural networks malfunctioning. Try again, human." });
311 }
312});

gameplay_agentmain.tsx5 matches

@arthrod•Updated 6 months ago
83 /** The name of the agent. */
84 agentname: string;
85 /** The agent function. */
86 agent: Connect4Agent<T> | Connect4AsyncAgent<T>;
87}
99 /** The name of the agent. */
100 agentname: string;
101 /** The agent function. */
102 agent: PokerAgent<T> | PokerAsyncAgent<T>;
103}
121 * a variety of different http server libraries.
122 *
123 * To see how to write the agent functions,
124 * see the {@link Connect4Agent} and {@link PokerAgent}
125 *
134 * used with an http server that supports the fetch interface.
135 */
136export function agentHandler<
137 T extends Json = Json,
138>(
139 agents: AgentSpec<T>[],
140): (req: Request) => Promise<Response> {
141 return async function(request: Request): Promise<Response> {
142 if (request.method === "GET") {
143 return Response.json({

whoIsHiringmain.tsx3 matches

@dxaginfo•Updated 6 months ago
7import About from "https://esm.town/v/vawogbemi/whoIsHiringAbout";
8
9function App() {
10 const tabs = { "/": "Home", "/about": "About" };
11 const [activeTab, setActiveTab] = useState("/");
335}
336
337function ServerApp() {
338 return (
339 <html>
358}
359
360export default async function(req: Request): Promise<Response> {
361 const url = new URL(req.url);
362 if (url.pathname === "/api/stories") {

lazyCookmain.tsx5 matches

@dxaginfo•Updated 6 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 const [numPeople, setNumPeople] = useState(4);
7 const [numRecipes, setNumRecipes] = useState(1);
229}
230
231function client() {
232 createRoot(document.getElementById("root")).render(<App />);
233}
234if (typeof document !== "undefined") { client(); }
235
236function extractJSONFromMarkdown(markdown: string): string {
237 const jsonMatch = markdown.match(/```json\n([\s\S]*?)\n```/);
238 return jsonMatch ? jsonMatch[1] : "";
239}
240
241export default async function server(request: Request): Promise<Response> {
242 if (request.method === "POST" && new URL(request.url).pathname === "/recipes") {
243 const { OpenAI } = await import("https://esm.town/v/std/openai");
338}
339
340async function generateImage(recipeName: string): Promise<string> {
341 const response = await fetch(`https://maxm-imggenurl.web.val.run/${encodeURIComponent(recipeName)}`);
342 if (!response.ok) {

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.