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=680&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 7331 results for "function"(547ms)

cerebras_coderindex.html1 match

@Shazan•Updated 2 months ago
19 <meta property="og:site_name" content="Cerebras Coder">
20 <meta property="og:url" content="https://cerebrascoder.com"/>
21 <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."">
22 <meta property="og:type" content="website">
23 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">

cerebras_coderindex2 matches

@Shazan•Updated 2 months ago
3import { createProject, getCode, getNextVersionNumber, insertVersion } from "./database/queries";
4
5async function servePublicFile(path: string): Promise<Response> {
6 const url = new URL("./public/" + path, import.meta.url);
7 const text = await (await fetch(url, {
20await createTables();
21
22export default async function cerebras_coder(req: Request): Promise<Response> {
23 if (req.method === "POST") {
24 let { prompt, currentCode, versionHistory, projectId } = await req.json();

cerebras_coderindex7 matches

@Shazan•Updated 2 months ago
23);
24
25function Hero({
26 prompt,
27 setPrompt,
44
45 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
46 Turn your ideas into fully functional apps in{" "}
47 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
48 less than a second
115}
116
117function App() {
118 const previewRef = React.useRef<HTMLDivElement>(null);
119 const [prompt, setPrompt] = useState("");
169 });
170
171 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
172 setLoading(true);
173 setTimeout(() => handleSubmit(promptItem.prompt), 0);
174 }
175
176 async function handleSubmit(e: React.FormEvent | string) {
177 if (typeof e !== "string") {
178 e.preventDefault();
225 }
226
227 function handleVersionChange(direction: "back" | "forward") {
228 const { currentVersionIndex, versions } = versionHistory;
229 if (direction === "back" && currentVersionIndex > 0) {
973);
974
975function client() {
976 const path = window.location.pathname;
977 const root = createRoot(document.getElementById("root")!);

cerebras_codergenerate-code2 matches

@Shazan•Updated 2 months ago
2import STARTER_PROMPTS from "../public/starter-prompts.js";
3
4function extractCodeFromFence(text: string): string {
5 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
6 return htmlMatch ? htmlMatch[1].trim() : text;
7}
8
9export async function generateCode(prompt: string, currentCode: string) {
10 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
11 if (starterPrompt) {

playfulPeachChimpanzeesillyCats1 match

@charmaine•Updated 2 months ago
1export default async function(req: Request): Promise<Response> {
2 const response = await fetch("https://api.thecatapi.com/v1/images/search");
3 const data = await response.json();

sbDocexuberantChocolateCougar8 matches

@tri•Updated 2 months ago
3import React, { useMemo, useState } from "https://esm.sh/react@18.2.0";
4
5// Utility function to format date as MM/DD/YYYY
6function formatDate(date) {
7 return date.toLocaleDateString("en-US", {
8 month: "2-digit",
12}
13
14// Function to get the last full week
15function getLastFullWeek() {
16 const now = new Date();
17 const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
82].sort();
83
84function DocumentList() {
85 const [documents, setDocuments] = useState([]);
86 const [isLoading, setIsLoading] = useState(false);
353}
354
355function App() {
356 return <DocumentList />;
357}
358
359function client() {
360 createRoot(document.getElementById("root")).render(<App />);
361}
362if (typeof document !== "undefined") { client(); }
363
364export default async function server(request: Request): Promise<Response> {
365 if (request.method === "POST" && new URL(request.url).pathname === "/api/documents") {
366 try {
markdownBlogStarter

markdownBlogStarterLayout.tsx1 match

@stevekrouse•Updated 2 months ago
2import type { ReactNode } from "npm:react@18.2.0";
3
4export function Layout({ children }: { children: ReactNode }) {
5 return (
6 <html lang="en">

utilsREADME.md1 match

@shouser•Updated 2 months ago
11import { servePublicFile } from "https://esm.town/v/stevekrouse/utils@179-main/serve-public/index.ts";
12
13export default async function(req: Request): Promise<Response> {
14 const url = new URL(req.url);
15 if (url.pathname === "/") {

utilsindex.tsx7 matches

@shouser•Updated 2 months ago
13interface TestCase {
14 name: string;
15 function: () => void;
16}
17
18interface TestCaseResult {
19 name: string;
20 function: () => void;
21 passed: boolean;
22 duration: number;
23}
24
25async function runTest(test: TestCase) {
26 let pass, message;
27 let start = performance.now();
28 try {
29 await test.function();
30 pass = true;
31 } catch (e: any) {
40}
41
42function renderBadge({ label, passedCount, testCount }: { label?: string; passedCount: number; testCount: number }) {
43 return makeBadge({
44 label: label ?? "Tests",
48}
49
50function Badge({ label, passedCount, testCount }: { label?: string; passedCount: number; testCount: number }) {
51 const svgMarkup = renderBadge({ label, passedCount, testCount });
52 const srcDoc = `<body style="margin: 0"}>${svgMarkup}</body>`;
62}
63
64function renderTestResults(testGroups: TestGroup[], outputs: { [groupName: string]: TestOutput[] }) {
65 const totalPassed = Object.values(outputs).flat().filter((output: TestOutput) => output.pass).length;
66 const totalTests = testGroups.reduce((sum, group) => sum + group.tests.length, 0);

utilsindex.ts5 matches

@shouser•Updated 2 months ago
3import { contentType } from "npm:mime-types@2.1.35";
4
5export async function servePublicFile(path: string, metaImportUrl: string): Promise<Response> {
6 const text = await readFile(path, metaImportUrl);
7 const extname = tsToJSExtension(path).split(".").pop() ?? "";
14}
15
16export async function readFile(path: string, metaImportUrl: string) {
17 const project = parseProject(metaImportUrl);
18 const esmURL = project.links.module.projectPinned + path.slice(1);
42}
43
44export async function getProjectFiles(metaImportUrl: string) {
45 const project = parseProject(metaImportUrl);
46 const { id } = await (await fetch(`https://api.val.town/v1/alias/projects/${project.username}/${project.name}`))
65console.log(await getProjectFiles(import.meta.url));
66
67async function fetchText(url: string) {
68 const res = await fetch(url, {
69 headers: {
79}
80
81function tsToJSExtension(path: string) {
82 if (path.endsWith(".ts")) {
83 return path.slice(0, -3) + ".js";

getFileEmail4 file matches

@shouser•Updated 5 days ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago