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/%7Bresult.originalUrl%7D?q=function&page=1&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 40467 results for "function"(782ms)

untitled-8264Main2.ts12 matches

@ziggywareโ€ขUpdated 20 mins ago
1export default async function (req: Request): Promise<Response> {
2 const fftSize = 2048;
3 const TWO_PI = 2.0 * 3.141592653579;
56 const errorBox = document.getElementById("errorBox");
57
58 function showError(e) {
59 console.error(e);
60 errorBox.style.display = "block";
63
64 // DPR-aware resize
65 function resize() {
66 const dpr = Math.min(window.devicePixelRatio || 1, 2);
67 const w = Math.floor(window.innerWidth * dpr);
178 \`;
179
180 function compileShader(type, src) {
181 const s = gl.createShader(type);
182 gl.shaderSource(s, src);
204 gl.bindVertexArray(vao);
205
206 function createAttrib(data, attribName, usage) {
207 const loc = gl.getAttribLocation(program, attribName);
208 if (loc === -1) throw new Error("Attrib not found or optimized out: " + attribName);
230
231 // Matrices
232 function mat4Perspective(fovDeg, aspect, near, far) {
233 const f = 1.0 / Math.tan((fovDeg * Math.PI) / 360);
234 const nf = 1 / (near - far);
241 return out;
242 }
243 function subtract(a, b) { return [a[0]-b[0], a[1]-b[1], a[2]-b[2]]; }
244 function normalize(v) {
245 const l = Math.hypot(v[0], v[1], v[2]) || 1;
246 return [v[0]/l, v[1]/l, v[2]/l];
247 }
248 function cross(a, b) {
249 return [a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]];
250 }
251 function dot(a, b) { return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; }
252 function mat4LookAt(eye, target, up) {
253 const z = normalize(subtract(eye, target));
254 const x = normalize(cross(up, z));
296
297 // Render loop
298 function render(ts) {
299 // Update audio only if ready
300 if (analyser) {

vtEditorFilesAGENTS.md12 matches

@jrmann100โ€ขUpdated 1 hour ago
4
5- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
20
21## Types of triggers
28
29```ts
30export default async function (req: Request) {
31 return new Response("Hello World");
32}
42
43```ts
44export default async function () {
45 // Scheduled task code
46}
56
57```ts
58export default async function (email: Email) {
59 // Process email
60}
66## Val Town Standard Libraries
67
68Val Town provides several hosted services and utility functions.
69
70### Blob Storage
120```
121
122## Val Town Utility Functions
123
124Val Town provides several utility functions to help with common project tasks.
125
126### Importing Utilities
200โ”‚ โ”œโ”€โ”€ database/
201โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
202โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
203โ”‚ โ”‚ โ””โ”€โ”€ README.md
204โ”‚ โ””โ”€โ”€ routes/ # Route modules
219โ””โ”€โ”€ shared/
220 โ”œโ”€โ”€ README.md
221 โ””โ”€โ”€ utils.ts # Shared types and functions
222```
223
226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229 ```ts
230 import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263
264## Common Gotchas and Solutions
362
363 // Handle main niche selection
364 nicheSelect.addEventListener('change', function() {
365 const selectedValue = this.value;
366
387 });
388
389 // Banner preview functionality
390 function updateBannerPreview(bannerNumber) {
391 const imageUrl = document.getElementById(`banner${bannerNumber}_image`).value;
392 const clickUrl = document.getElementById(`banner${bannerNumber}_url`).value;
422
423 // Handle form submission
424 form.addEventListener('submit', function(e) {
425 e.preventDefault();
426
486
487 // Auto-resize iframe
488 function resizeIframe() {
489 const height = document.body.scrollHeight;
490 parent.postMessage({

untitled-2952main.ts1 match

@xxxjjjโ€ขUpdated 2 hours ago
1// Learn more: https://docs.val.town/vals/http/
2export default async function (req: Request): Promise<Response> {
3 const searchParams = new URL(req.url).searchParams;
4
11- **Schedule**: Every minute
12- **Threshold**: Sessions older than 60 seconds without heartbeat updates
13- **Function**: Marks stale sessions as not viewing and syncs to Notion
14
15**How Viewing Sessions Work**:
39- **Purpose**: Cleans up orphaned agent blobs
40- **Schedule**: Every minute
41- **Function**: Deletes agent blobs where the agent ID doesn't match the demo's
42 "Glimpse agents" relation in Notion
43- **Read-Only Notion**: Only reads Notion data, never modifies it
9 * Hook for tracking user viewing status with automatic updates
10 */
11export function useViewingTracking(
12 glimpseId: string,
13 isAuthorized: boolean
63
64
65 // Cleanup function
66 return () => {
67 if (intervalRef.current) {

spotymain.ts1 match

@skirtownerโ€ขUpdated 3 hours ago
4};
5
6export default async function handler(req: Request) {
7 if (req.method !== "GET") {
8 return new Response("Method Not Allowed", { status: 405 });

untitled-7644new-file-7315.ts1 match

@coolmovesโ€ขUpdated 3 hours ago
1export default async function (interval: Interval) {
2 const f = await fetch("https://sih-2025-demo.onrender.com/");
3 const s = await f.text();
255```typescript
256// In route handler
257const result = await controllerFunction(params);
258
259if (!result.success) {
10**Returns:** `UseAuthReturn`
11- `userEmail` - Current user's email from window data
12- `isAuthorized(pageProperties)` - Function to check if user can access a page
13
14**Usage:**
29- `loading` - Loading state
30- `error` - Error state
31- `refetch` - Function to manually refetch data
32
33**Usage:**

ratelimit4 file matches

@unkeyโ€ขUpdated 1 month ago
Rate limit your serverless functions

discordWebhook2 file matches

@stevekrouseโ€ขUpdated 2 months ago
Helper function to send Discord messages
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.