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=2093&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 29395 results for "function"(3077ms)

test_projectmain.js19 matches

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

blob_admin_blobmain.tsx1 match

@gwoods22•Updated 3 months ago
38 return json.replace(
39 /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
40 function(match) {
41 var cls = "number";
42 if (/^"/.test(match)) {

twitterAlertREADME.md2 matches

@mxm•Updated 3 months ago
46- Key: `mentionsDiscord`
47- Value: Your Discord webhook URL.
48Notifications will be sent using this function:
49
50```ts
63
64- **Proxies via Val Town's [SocialDataProxy](https://www.val.town/v/stevekrouse/socialDataProxy)**: Limited to 10 cents per day for [**Val Town Pro users**](https://www.val.town/pricing). This API is *only* for Pro users.
65- **Need more calls?** Sign up for your own [SocialData API token](https://socialdata.tools) and configure the [`socialDataSearch`](https://www.val.town/v/stevekrouse/socialDataSearch) function.

twitterAlertmain.tsx1 match

@mxm•Updated 3 months ago
12const isProd = false;
13
14export async function twitterAlert({ lastRunAt }: Interval) {
15 // If isProd, search for tweets since that last time this interval ran
16 // if not, search for tweets since 48 hours ago for testing

researchAgentemailHandler2 matches

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

forwardermain.tsx1 match

@charmaine•Updated 3 months ago
5const { author, name } = extractValInfo(import.meta.url);
6
7export async function forwarder(e: Email) {
8 let attachments: AttachmentData[] = [];
9 for (const f of e.attachments) {
tuna

tuna9 file matches

@jxnblk•Updated 2 days ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
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.