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=674&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 7802 results for "function"(649ms)

cerebras_codermigrations1 match

@jaballadares•Updated 1 month ago
7export const ITERATIONS_TABLE = "cerebras_coder_iterations";
8
9export async function createTables() {
10 await sqlite.execute(`
11 CREATE TABLE IF NOT EXISTS ${PROJECTS_TABLE} (

cerebras_coderindex.html1 match

@jaballadares•Updated 1 month 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

@jaballadares•Updated 1 month 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

@jaballadares•Updated 1 month 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

@jaballadares•Updated 1 month 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) {

getProjectsAsZipsindex.ts4 matches

@shouser•Updated 1 month ago
25});
26
27async function getAllProjects() {
28 let offset = 0;
29 const limit = 100;
88});
89
90function parseValTownProjectURL(url: string) {
91 // Use the URL constructor to parse the URL
92 const { pathname } = new URL(url);
102}
103
104async function getFilesWithContent(files: any[], projectId) {
105 const nonDirectoryFiles = files.filter(file => file.type !== "directory");
106
137}
138
139async function createZipFromEndpoints(
140 files: any[],
141 zipFileName: string,

replicate_starterApp.tsx1 match

@charmaine•Updated 1 month ago
3import React from "https://esm.sh/react@18.2.0";
4
5function ImageGenerator() {
6 const [prompt, setPrompt] = React.useState("");
7 const [images, setImages] = React.useState<any>([]);

replicate_starterApp.tsx1 match

@zeke•Updated 1 month ago
3import React from "https://esm.sh/react@18.2.0";
4
5function ImageGenerator() {
6 const [prompt, setPrompt] = React.useState("");
7 const [images, setImages] = React.useState<any>([]);

test_projectmain.js19 matches

@charmaine•Updated 1 month ago
7 * Remove common variations of "+ C" at the end of an indefinite integral.
8 */
9function stripPlusC(str) {
10 return str.replace(/\+\s*c\s*$/i, "").trim();
11}
15 * Remove or replace common LaTeX constructs.
16 */
17function latexToExpression(latex) {
18 // Remove display math delimiters: $$...$$ or $...$
19 let expr = latex.replace(/\${1,2}/g, "");
22 expr = expr.replace(/\\frac\s*\{([^}]+)\}\s*\{([^}]+)\}/g, "($1)/($2)");
23
24 // Some common function replacements for Algebrite
25 expr = expr.replace(/\\sin/g, "sin");
26 expr = expr.replace(/\\cos/g, "cos");
46 * Return the simplified string or null on error.
47 */
48function parseAndSimplify(expr) {
49 try {
50 // If it's an empty string, treat that as invalid
59 * Check if two expressions (already simplified) differ by at most a constant.
60 */
61function differByConstant(simpl1, simpl2) {
62 try {
63 const diff = Algebrite.simplify(`(${simpl1}) - (${simpl2})`).toString();
74 * Symbolic check: compare simplified forms, then see if they differ by a constant.
75 */
76function symbolicCheck(expr1, expr2) {
77 const s1 = parseAndSimplify(expr1);
78 const s2 = parseAndSimplify(expr2);
85 * Evaluate an expression numerically at x, returning a float or null if invalid.
86 */
87function safeEval(expr, x) {
88 try {
89 const val = parseFloat(Algebrite.eval(expr, { x }).toString());
100 * If the difference changes by more than a small tolerance, we reject it.
101 */
102function numericCheck(expr1, expr2, samples = [-2, 0, 2]) {
103 const diffs = [];
104
125 * Loose equivalence: first do a symbolic check, if that fails, do numeric check.
126 */
127function expressionsAreLooselyEquivalent(expr1, expr2) {
128 // 1) Symbolic check
129 if (symbolicCheck(expr1, expr2)) {
137 * GPT-4 call to generate a new math problem.
138 */
139async function handleProblemGeneration() {
140 const openai = new OpenAI();
141 const completion = await openai.chat.completions.create({
153 },
154 ],
155 functions: [
156 {
157 name: "generate_math_problem",
177 },
178 ],
179 function_call: { name: "generate_math_problem" },
180 });
181
182 const functionCall = completion.choices[0].message.function_call;
183 if (!functionCall || functionCall.name !== "generate_math_problem") {
184 return new Response("Failed to generate problem", { status: 500 });
185 }
187 let problem;
188 try {
189 problem = JSON.parse(functionCall.arguments);
190 } catch (error) {
191 console.error("Failed to parse function call arguments:", error);
192 console.log("Raw arguments:", functionCall.arguments);
193 return new Response("Failed to generate problem", { status: 500 });
194 }
213 * - Return result
214 */
215async function handleAnswerCheck(request) {
216 const { answer, problemId } = await request.json();
217 const problem = await blob.getJSON(`problem_${problemId}`);
257 * Main request handler.
258 */
259export default async function(req: Request): Promise<Response> {
260 const url = new URL(req.url);
261

markdownBlogStarterLayout.tsx1 match

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

getFileEmail4 file matches

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

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago