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=1232&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 18497 results for "function"(8093ms)

scl_2024main.tsx17 matches

@stanley•Updated 4 months ago
4const cacheKey = "donation_data_cache";
5
6// Utility functions for formatting
7function formatDate(dateString: string): string {
8 return new Date(dateString).toLocaleString("en-US", {
9 year: "numeric",
16}
17
18function formatCurrency(amount: number, currencyCode: string): string {
19 return new Intl.NumberFormat("en-US", {
20 style: "currency",
23}
24
25function formatGoalAmount(amount: number): string {
26 if (amount >= 1000000) {
27 return `${Math.round(amount / 1000000)}M`;
33}
34
35function calculateBarWidth(totalRaised: number, goalAmount: number): string {
36 const percentage = (totalRaised / goalAmount) * 100;
37 return `${Math.min(Math.round(percentage), 100)}%`;
38}
39
40async function fetchAndCacheData() {
41 try {
42 console.log("Fetching URL:", url);
86}
87
88async function getFullData() {
89 const data = await fetchAndCacheData();
90 const donationGoal = data.checkoutLink.checkout_link_data.donation_goal;
106}
107
108async function getDonationProgress() {
109 const data = await fetchAndCacheData();
110 const donationGoal = data.checkoutLink.checkout_link_data.donation_goal;
120}
121
122async function getCheckoutDetails() {
123 const data = await fetchAndCacheData();
124 return Response.json({
129}
130
131async function getCampaignInfo() {
132 const data = await fetchAndCacheData();
133 const linkData = data.checkoutLink.checkout_link_data;
140}
141
142async function getScrapedData() {
143 const data = await fetchAndCacheData();
144 const donationGoal = data.checkoutLink.checkout_link_data.donation_goal;
156}
157
158function getDemoData() {
159 const goalAmount = 1000000; // $100,00
160 const totalRaised = Math.floor(Math.random() * goalAmount);
169}
170
171function get2023Data() {
172 const goalAmount = 1000000;
173 const totalRaised = 1654700;
182}
183
184async function getHtmlView() {
185 const scrapedData = await getScrapedData();
186 const demoData = await getDemoData();
253}
254
255async function getFundraiserHtml() {
256 const scrapedData = await getScrapedData();
257 const demoData = await getDemoData();
374 });
375}
376async function finalGoal() {
377 const goalAmount = 1000000;
378 const totalRaised = 729438;
398};
399
400export default async function(req: Request): Promise<Response> {
401 const { pathname } = new URL(req.url);
402 const handler = router[pathname];

blob_adminmain.tsx8 matches

@dave_smith•Updated 4 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"));

libgenopdsmain.tsx5 matches

@mintexists•Updated 4 months ago
5const LIBGEN_LI_DOWNLOAD_URL = "https://libgen.li";
6
7async function search(query: string) {
8 const url = new URL(
9 "https://annas-archive.org/search?index=&page=1&display=table&content=book_nonfiction&content=book_fiction&ext=epub&src=lgrs&sort=",
95}
96
97async function fetchMetadataLibgenRs(
98 url: string | undefined,
99 identifier: string | undefined = undefined,
150}
151
152async function fetchMetadataLibgenLi(
153 url: string | undefined,
154 identifier: string | undefined = undefined,
189}
190
191function generatePublication(libgenMetadata: any) {
192 return JSON.parse(JSON.stringify(
193 {
222}
223
224export default async function server(request: Request): Promise<Response> {
225 const url = new URL(request.url);
226 const pathname = url.pathname;

disposablemain.tsx1 match

@postpostscript•Updated 4 months ago
1export function disposable<T extends object>(
2 value: T,
3 onDispose: (value: T) => void,

lockmain.tsx5 matches

@postpostscript•Updated 4 months ago
10};
11
12export async function acquireLock(opts?: LockOptions): Promise<LockHandle> {
13 let id = opts?.id ?? parentReference().userHandle + "-" + parentReference().valName;
14 id = id.replace(/[^\w]+/g, "_");
15 const ttl = opts?.ttl ?? 3;
16
17 async function handleError(error: string) {
18 if (typeof opts?.retries === "number" && (opts.retry ?? 0) >= opts.retries) {
19 throw new LockError(`LockError: failed with message "${error || "unknown error"}"`);
51 resolve,
52 } = Promise.withResolvers();
53 async function release(): Promise<LockResponse | undefined> {
54 releasedRequest ??= makeRequest(id, "release", {
55 lease,
82};
83
84export async function makeRequest(id: string, method: "release" | "acquire", params): Promise<LockResponse> {
85 return fetchJSON(
86 `https://dlock.univalent.net/lock/${id}/${method}?${searchParams(params)}`,
88}
89
90export function createMemoryLock() {
91 let released = Promise.resolve(undefined);
92

zyloxAIChatAppmain.tsx3 matches

@gigmx•Updated 4 months ago
4import OpenAI from "https://esm.sh/openai@4.28.4";
5
6function App() {
7 const [messages, setMessages] = useState([]);
8 const [inputMessage, setInputMessage] = useState("");
177}
178
179function client() {
180 createRoot(document.getElementById("root")).render(<App />);
181}
182if (typeof document !== "undefined") { client(); }
183
184export default async function server(request: Request): Promise<Response> {
185 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
186 const { OpenAI } = await import("https://esm.town/v/std/openai");

compassionateBlackCatfishmain.tsx7 matches

@gigmx•Updated 4 months ago
1import OpenAI from "https://esm.sh/openai@4.28.4";
2
3export default async function(req: Request): Promise<Response> {
4 const LEPTON_API_TOKEN = Deno.env.get('LEPTON_API_TOKEN') || '';
5
83 const audioInput = document.getElementById('audio-input');
84
85 function createMatrixBackground() {
86 const canvas = document.createElement('canvas');
87 const ctx = canvas.getContext('2d');
106 }
107
108 function draw() {
109 ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
110 ctx.fillRect(0, 0, canvas.width, canvas.height);
129 createMatrixBackground();
130
131 function addMessage(role, content, isTyping = false, contentType = 'text') {
132 const msgParent = document.createElement("div");
133 msgParent.className = "mb-4 " + (role === 'user' ? 'text-right' : 'text-left');
158 if (file) {
159 const reader = new FileReader();
160 reader.onload = async function(e) {
161 const base64Audio = e.target.result.split(',')[1];
162 addMessage('user', file.name, false, 'audio');
218 });
219
220 document.getElementById("input").addEventListener("submit", async function(event) {
221 event.preventDefault();
222 const userMessage = event.target.message.value;
302
303// Add a separate API route handler for chat
304export async function handler(req: Request) {
305 if (req.method !== 'POST') {
306 return new Response('Method Not Allowed', { status: 405 });

stellarCrimsonPandamain.tsx11 matches

@myy•Updated 4 months ago
24);
25
26function Hero({
27 prompt,
28 setPrompt,
45
46 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
47 Turn your ideas into fully functional apps in{" "}
48 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
49 less than a second
116}
117
118function App() {
119 const previewRef = React.useRef<HTMLDivElement>(null);
120 const [prompt, setPrompt] = useState("");
170 });
171
172 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
173 setLoading(true);
174 setTimeout(() => handleSubmit(promptItem.prompt), 0);
175 }
176
177 async function handleSubmit(e: React.FormEvent | string) {
178 if (typeof e !== "string") {
179 e.preventDefault();
226 }
227
228 function handleVersionChange(direction: "back" | "forward") {
229 const { currentVersionIndex, versions } = versionHistory;
230 if (direction === "back" && currentVersionIndex > 0) {
974);
975
976function client() {
977 const path = window.location.pathname;
978 const root = createRoot(document.getElementById("root")!);
1010}
1011
1012function extractCodeFromFence(text: string): string {
1013 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
1014 return htmlMatch ? htmlMatch[1].trim() : text;
1015}
1016
1017async function generateCode(prompt: string, currentCode: string) {
1018 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
1019 if (starterPrompt) {
1060}
1061
1062export default async function cerebras_coder(req: Request): Promise<Response> {
1063 // Dynamic import for SQLite to avoid client-side import
1064 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1163 <meta property="og:site_name" content="Cerebras Coder">
1164 <meta property="og:url" content="https://cerebrascoder.com"/>
1165 <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."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">

cerebras_codermain.tsx11 matches

@myy•Updated 4 months ago
24);
25
26function Hero({
27 prompt,
28 setPrompt,
45
46 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
47 Turn your ideas into fully functional apps in{" "}
48 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
49 less than a second
116}
117
118function App() {
119 const previewRef = React.useRef<HTMLDivElement>(null);
120 const [prompt, setPrompt] = useState("");
170 });
171
172 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
173 setLoading(true);
174 setTimeout(() => handleSubmit(promptItem.prompt), 0);
175 }
176
177 async function handleSubmit(e: React.FormEvent | string) {
178 if (typeof e !== "string") {
179 e.preventDefault();
226 }
227
228 function handleVersionChange(direction: "back" | "forward") {
229 const { currentVersionIndex, versions } = versionHistory;
230 if (direction === "back" && currentVersionIndex > 0) {
974);
975
976function client() {
977 const path = window.location.pathname;
978 const root = createRoot(document.getElementById("root")!);
1010}
1011
1012function extractCodeFromFence(text: string): string {
1013 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
1014 return htmlMatch ? htmlMatch[1].trim() : text;
1015}
1016
1017async function generateCode(prompt: string, currentCode: string) {
1018 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
1019 if (starterPrompt) {
1060}
1061
1062export default async function cerebras_coder(req: Request): Promise<Response> {
1063 // Dynamic import for SQLite to avoid client-side import
1064 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1163 <meta property="og:site_name" content="Cerebras Coder">
1164 <meta property="og:url" content="https://cerebrascoder.com"/>
1165 <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."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">

calculateRequiredQuantityAppmain.tsx4 matches

@kalawaja•Updated 4 months ago
3import React, { useRef, useState } from "https://esm.sh/react@18.2.0";
4
5function PriceQuantityCalculator() {
6 const [calculation, setCalculation] = useState({
7 item: "",
204}
205
206function App() {
207 return <PriceQuantityCalculator />;
208}
209
210function client() {
211 createRoot(document.getElementById("root")).render(<App />);
212}
213if (typeof document !== "undefined") { client(); }
214
215export default async function server(request: Request): Promise<Response> {
216 return new Response(
217 `

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
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.