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 40464 results for "function"(881ms)

spotymain.ts1 match

@skirtownerUpdated 46 mins 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

@coolmovesUpdated 46 mins 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) {
9- **Schedule**: Every minute
10- **Threshold**: Sessions older than 60 seconds without heartbeat updates
11- **Function**: Marks stale sessions as not viewing and syncs to Notion
12
13**Multi-Layer Session Ending System**:
47- **Browser crashes**: No opportunity for graceful cleanup
48- **System sleep/hibernate**: Processes may be suspended mid-request
49- **Force quit scenarios**: No cleanup functions execute
50- **Mobile browser behavior**: Aggressive tab suspension/termination
51- **Development/debugging**: Stopping processes during testing
60- **Purpose**: Cleans up orphaned agent blobs
61- **Schedule**: Every minute (configurable in Val Town UI)
62- **Function**: Deletes agent blobs where the agent ID doesn't match the demo's "Glimpse agents" relation in Notion
63- **Read-Only Notion**: Only reads Notion data, never modifies it
64- **Blob Cleanup**: Removes mismatched/orphaned blobs to keep storage synchronized with Notion
9 * Hook for tracking user viewing status with automatic updates
10 */
11export function useViewingTracking(
12 glimpseId: string,
13 isAuthorized: boolean
90 window.addEventListener('beforeunload', handleBeforeUnload);
91
92 // Cleanup function
93 return () => {
94 if (intervalRef.current) {
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:**

eventsCalendartmp.ts1 match

@roopUpdated 2 hours ago
3import { marked } from "npm:marked";
4
5export default async function (req: Request) {
6 const vt = new ValTown();
7 const val_id = "4cbcd1ae-8b94-11f0-b01a-0224a6c84d84";

eventsCalendarserver.ts4 matches

@roopUpdated 2 hours ago
2Use with bookmarklet:
3
4javascript: (function () {
5 var HOST = "https://extract-event-data.val.run";
6 var TOKEN = "<REPLACE>";
209});
210
211function update(stream: SSEStreamingApi, payload: any) {
212 return stream.writeSSE({
213 event: "update",
219}
220
221function complete(
222 stream: SSEStreamingApi,
223 state: "success" | "error",
232}
233
234function fail(
235 stream: SSEStreamingApi,
236 message?: string,
130
131 // Load free version
132 document.getElementById('loadFreeVersion').addEventListener('click', function() {
133 nicheIframe.src = 'free-input-iframe.html';
134 toolContainer.classList.remove('hidden');
138
139 // Load premium version
140 document.getElementById('loadPremiumVersion').addEventListener('click', function() {
141 nicheIframe.src = 'premium-input-iframe.html';
142 toolContainer.classList.remove('hidden');
146
147 // Clear tool
148 document.getElementById('clearTool').addEventListener('click', function() {
149 toolContainer.classList.add('hidden');
150 outputContainer.classList.add('hidden');
156
157 // Listen for messages from iframe
158 window.addEventListener('message', function(event) {
159 // Security check - in production, verify event.origin
160
175
176 // Generate output page
177 function generateOutputPage(data) {
178 try {
179 currentOutputData = data;
200
201 // Download HTML file
202 document.getElementById('downloadPage').addEventListener('click', function() {
203 if (!currentOutputHTML) {
204 alert('No page generated yet!');
225
226 // Preview page
227 document.getElementById('previewPage').addEventListener('click', function() {
228 if (!currentOutputHTML) {
229 alert('No page generated yet!');
242
243 // Copy HTML code
244 document.getElementById('copyCode').addEventListener('click', function() {
245 if (!currentOutputHTML) {
246 alert('No page generated yet!');
248 }
249
250 navigator.clipboard.writeText(currentOutputHTML).then(function() {
251 updateStatus('📋 HTML code copied to clipboard!');
252
263 btn.classList.add('bg-purple-600');
264 }, 2000);
265 }).catch(function(err) {
266 console.error('Failed to copy: ', err);
267 updateStatus('❌ Failed to copy to clipboard');
270
271 // Close preview modal
272 document.getElementById('closePreview').addEventListener('click', function() {
273 previewModal.classList.add('hidden');
274 previewFrame.src = '';
276
277 // Close modal on background click
278 previewModal.addEventListener('click', function(e) {
279 if (e.target === previewModal) {
280 previewModal.classList.add('hidden');
284
285 // Update status message
286 function updateStatus(message) {
287 document.getElementById('outputStatus').textContent = message;
288 console.log('Status:', message);

TopTenVideosoutput-generator.js7 matches

@pmapowerUpdated 3 hours ago
261
262 // Show video details
263 function showVideoDetails(videoId) {
264 const video = videos.find(v => v.id === videoId);
265 if (!video) return;
305
306 // Track ad clicks
307 function trackAdClick(adId, url) {
308 analytics.clicks[adId] = (analytics.clicks[adId] || 0) + 1;
309 updateAnalytics();
312
313 // Track ad impressions
314 function trackAdImpression(adId) {
315 analytics.impressions[adId] = (analytics.impressions[adId] || 0) + 1;
316 updateAnalytics();
319
320 // Update analytics display
321 function updateAnalytics() {
322 const totalImpressions = Object.values(analytics.impressions).reduce((a, b) => a + b, 0);
323 const totalClicks = Object.values(analytics.clicks).reduce((a, b) => a + b, 0);
358 js += `
359 // Initialize page
360 document.addEventListener('DOMContentLoaded', function() {
361 // Auto-select first video
362 if (videos.length > 0) {
390
391 // Display single ad
392 function displayAd(ad) {
393 const content = document.getElementById('advertisementContent');
394 if (!content) return;
431
432 // Start ad rotation
433 function startAdRotation() {
434 if (weightedAds.length === 0) return;
435

ratelimit4 file matches

@unkeyUpdated 1 month ago
Rate limit your serverless functions

discordWebhook2 file matches

@stevekrouseUpdated 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.