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=684&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 7316 results for "function"(929ms)

test_projectindex.ts4 matches

@charmainetest•Updated 2 months ago
6console.log("will this show up");
7
8export async function servePublicFile(path: string, metaImportUrl: string): Promise<Response> {
9 const text = await readFile(path, metaImportUrl);
10 const extname = tsToJSExtension(path).split(".").pop() ?? "";
17}
18
19async function readFile(path: string, metaImportUrl: string) {
20 const project = parseProject(metaImportUrl);
21 const esmURL = project.links.module.projectPinned + path.slice(1);
46}
47
48async function fetchText(url: string) {
49 const res = await fetch(url, {
50 headers: {
60}
61
62function tsToJSExtension(path: string) {
63 if (path.endsWith(".ts")) {
64 return path.slice(0, -3) + ".js";

test_projectscript.ts5 matches

@charmainetest•Updated 2 months ago
5import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
6
7function renderMath(text) {
8 if (!text) return "";
9 return text.replace(/\$\$(.*?)\$\$|\$(.*?)\$/g, (match, eq1, eq2) => {
21}
22
23function App() {
24 const [problem, setProblem] = useState(null);
25 const [userAnswer, setUserAnswer] = useState("");
112 <ul>
113 <li>
114 Functions: <code>sin(x)</code>, <code>cos(x)</code>, <code>tan(x)</code>
115 </li>
116 <li>
117 Inverse functions: <code>arcsin(x)</code> or <code>sin^{-1}(x)</code>
118 </li>
119 <li>
162}
163
164function client() {
165 createRoot(document.getElementById("root")).render(<App />);
166}

test_projectmain.js19 matches

@charmainetest•Updated 2 months 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

test_projectemailReminder1 match

@charmainetest•Updated 2 months ago
1import { email } from "https://esm.town/v/std/email?v=13";
2
3export default async function(interval: Interval) {
4 console.log(`math problem`);
5 email({

songsredirect1 match

@reckter•Updated 2 months ago
1import { blob } from "https://esm.town/v/std/blob?v=10";
2
3export default async function(request: Request): Promise<Response> {
4 const requestUrl = new URL(request.url);
5

researchAgentemailHandler2 matches

@charmaine•Updated 2 months ago
4import { OpenAI } from "npm:openai";
5
6function pm(...lines: string[]): string {
7 return lines.join("\n");
8}
9
10export async function emailValHandler(inboundEmail: Email) {
11 const userPrompt = pm(
12 `From: ${inboundEmail.from}`,

researchAgentemailHandler2 matches

@thesephist•Updated 2 months ago
4import { OpenAI } from "npm:openai";
5
6function pm(...lines: string[]): string {
7 return lines.join("\n");
8}
9
10export async function emailValHandler(inboundEmail: Email) {
11 const userPrompt = pm(
12 `From: ${inboundEmail.from}`,

researchAgentmorningAiNewsletter1 match

@thesephist•Updated 2 months ago
1import { emailValHandler } from "./emailHandler";
2
3export default async function(interval: Interval) {
4 const today = new Intl.DateTimeFormat("en-US", {
5 month: "short",

utilsREADME.md1 match

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

utilsindex.tsx7 matches

@charmaine•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);

getFileEmail4 file matches

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

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago