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%22Optional%20title%22?q=function&page=6&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 40267 results for "function"(887ms)

social-proofscript.js19 matches

@Jamesllllllllllโ€ขUpdated 21 hours ago
1(function () {
2 "use strict";
3
28
29 // Inject CSS styles for purchase notifications
30 function injectStyles() {
31 if (document.getElementById("social-proof-styles")) return;
32
396
397 // Create notification container
398 function createNotificationContainer() {
399 let container = document.getElementById("social-proof-container");
400 if (container) return container;
409
410 // Sanitize HTML
411 function sanitizeHtml(str) {
412 if (typeof str !== "string") return "";
413
423
424 // Validate and sanitize config
425 function validateConfig(config) {
426 const sanitized = { ...config };
427
482
483 // Validate and sanitize product IDs
484 function validateProductIds(productIdsString) {
485 if (!productIdsString || typeof productIdsString !== "string") {
486 return [];
496
497 // Format time ago
498 function formatTimeAgo(dateString) {
499 const date = new Date(dateString);
500 const now = new Date();
512
513 // Create purchase notification element
514 function createPurchaseNotification(purchase) {
515 const notification = document.createElement("div");
516 notification.className = "social-proof-notification";
555
556 // Create event signup notification element
557 function createEventSignupNotification(
558 eventName,
559 signupCount,
640
641 // Stack existing notifications
642 function stackNotifications(container) {
643 const notifications = container.querySelectorAll(
644 ".social-proof-notification",
672
673 // Show purchase notification
674 function showPurchaseNotification(purchase) {
675 if (!isActive || displayCount >= config.maxDisplayCount) return;
676
703
704 // Show event signup notification
705 function showEventSignupNotification(
706 eventName,
707 signupCount,
742
743 // Hide notification
744 function hideNotification(notification) {
745 // Add smooth exit animation
746 notification.style.transition = "all 0.4s ease";
760
761 // Fetch recent purchases
762 async function fetchRecentPurchases(productIds) {
763 try {
764 const productIdsParam = Array.isArray(productIds)
782
783 // Fetch event signup data (count and first signup time)
784 async function fetchEventSignupData(eventName) {
785 try {
786 if (
837
838 // Show one-time event signup notification on page load
839 async function showEventSignupOnLoad(eventName) {
840 try {
841 const { signupCount, firstSignupTime } = await fetchEventSignupData(
855
856 // Start showing purchase notifications
857 function startPurchaseNotifications(productIds) {
858 if (!productIds || !isActive) return;
859
873
874 // Show next purchase notification in queue
875 function showNextPurchaseNotification() {
876 if (
877 !isActive || notificationQueue.length === 0 ||
891
892 // Initialize social proof
893 function initSocialProof() {
894 injectStyles();
895

webgpu_2main.tsx3 matches

@saolsenโ€ขUpdated 21 hours ago
3import module_path from "./module_path.tsx"
4
5async function main() {
6 const shader = await (await fetch(`${module_path}/shader.wgsl`)).text();
7
51 };
52
53 function render() {
54 renderPassDescriptor.colorAttachments[0].view =
55 context.getCurrentTexture().createView();
85}
86
87function fail(msg: string) {
88 alert(msg);
89}

webgpu_2server.tsx1 match

@saolsenโ€ขUpdated 21 hours ago
1import module_path from "./module_path.tsx"
2
3export default function (_req: Request): Response {
4 return new Response(
5 `

webgpu_2AGENTS.md12 matches

@saolsenโ€ขUpdated 21 hours 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

webgpu_1main.tsx3 matches

@saolsenโ€ขUpdated 21 hours ago
1/// <reference types="npm:@webgpu/types" />
2
3async function main() {
4 const shader = await (await fetch("https://esm.town/v/saolsen/webgpu_1/shader.wgsl")).text();
5
49 };
50
51 function render() {
52 renderPassDescriptor.colorAttachments[0].view =
53 context.getCurrentTexture().createView();
83}
84
85function fail(msg: string) {
86 alert(msg);
87}

eventsCalendarserver.ts4 matches

@roopโ€ขUpdated 21 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,

webgpu_1server.tsx1 match

@saolsenโ€ขUpdated 22 hours ago
1export default function (_req: Request): Response {
2 return new Response(
3 `

webgpu_1AGENTS.md12 matches

@saolsenโ€ขUpdated 22 hours 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

resultmain.ts2 matches

@cricks_unmixed4uโ€ขUpdated 22 hours ago
4};
5
6// Helper functions to create Result instances
7export function ok<Data>(data: Data): Result<Data, never> {
8 return ({
9 ok: true,

tijs_orgindex.tsx6 matches

@tijsโ€ขUpdated 22 hours ago
80const CACHE_DURATION = 60 * 60 * 1000; // 1 hour
81
82async function fetchBlogPosts(): Promise<Post[]> {
83 const cacheKey = "blog-posts";
84 const cached = cache.get(cacheKey);
120}
121
122async function resolveHandleToDID(handle: string): Promise<string> {
123 const cacheKey = `did-${handle}`;
124 const cached = cache.get(cacheKey);
168}
169
170async function resolvePDS(handle: string): Promise<string> {
171 const cacheKey = `pds-${handle}`;
172 const cached = cache.get(cacheKey);
225}
226
227async function fetchBookRecords(): Promise<{ books: Book[]; pdsUrl: string }> {
228 const cacheKey = "book-records";
229 const cached = cache.get(cacheKey);
299}
300
301async function fetchCheckins(): Promise<CheckinWithAddress[]> {
302 const cacheKey = "checkins";
303 const cached = cache.get(cacheKey);
390}
391
392export default async function handler() {
393 console.log("=== Handler starting ===");
394 const [posts, bookData, checkins] = await Promise.all([

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.