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=52&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 18993 results for "function"(1120ms)

8const CREATION_LOCK_KEY = "map_vote_creation_first_half";
9
10// Basic Discord request function with rate limiting
11async function safeDiscordRequest(endpoint: string, options: RequestInit = {}) {
12 const token = Deno.env.get("DISCORD_BOT_TOKEN");
13
43}
44
45// Simplified test function that just checks channel access
46async function testChannelAccess(channelId: string) {
47 try {
48 console.log(`Testing access to channel ${channelId}`);
73}
74
75// Main function
76export default async function() {
77 console.log("🧪 SIMPLE TEST: Map Vote Tally Channel Access Test");
78

untitled-4783main.js10 matches

@StayNullUpdated 4 days ago
15
16// --- INITIALIZATION ---
17function init() {
18 // Scene
19 scene = new THREE.Scene();
77}
78
79function addBuilding(x, y, z, width, height, depth, color) {
80 const geometry = new THREE.BoxGeometry(width, height, depth);
81 const material = new THREE.MeshStandardMaterial({ color: color });
86
87// --- GAME LOOP & UPDATES ---
88function animate(currentTime) {
89 if (gameOver) {
90 scoreElement.innerText = `GAME OVER! Survived: ${Math.floor(gameTime / 1000)}s\nPress R to Restart`;
114let lastFrameTime = 0;
115
116function handlePlayerMovement() {
117 const moveDirection = new THREE.Vector3();
118 const rotationSpeed = playerTurnSpeed;
143}
144
145function updateCamera() {
146 const offset = new THREE.Vector3(0, 3, -6); // Camera offset from player
147 offset.applyQuaternion(player.quaternion); // Apply player's rotation to offset
150}
151
152function spawnCars(currentTime) {
153 if (currentTime - lastCarSpawnTime > CAR_SPAWN_INTERVAL) {
154 lastCarSpawnTime = currentTime;
179}
180
181function updateCars() {
182 cars.forEach((car, index) => {
183 car.position.z += car.userData.directionZ * car.userData.speed;
191}
192
193function checkCollisions() {
194 const playerBox = new THREE.Box3().setFromObject(player);
195 cars.forEach(car => {
204}
205
206function restartGame() {
207 gameOver = false;
208 gameTime = 0;
220
221// --- UTILITIES ---
222function onWindowResize() {
223 camera.aspect = window.innerWidth / window.innerHeight;
224 camera.updateProjectionMatrix();
5
6// Create a magic link token for the given email
7export async function createMagicLinkToken(userEmail: string): Promise<string> {
8 const token = generateSessionToken();
9 const now = Math.floor(Date.now() / 1000);
19
20// Send a magic link email
21export async function sendMagicLinkEmail(url: string, userEmail: string, token: string): Promise<boolean> {
22 try {
23 const magicLink = `${url}/auth/magic-link/${token}`;
47
48// Validate a magic link token and create a session
49export async function validateMagicLinkToken(token: string): Promise<{ valid: boolean; userId?: number }> {
50 const now = Math.floor(Date.now() / 1000);
51
11const CREATION_LOCK_KEY = "map_vote_creation_first_half";
12
13// Main function that runs as a scheduled val for tallying votes (testing version)
14export default async function() {
15 console.log("🧪 TEST MODE: First Half Map Vote Tally Test Job started");
16 console.log("⚠️ WARNING: This version skips time verification and is for testing only!");
86 const tallyStartTime = Date.now();
87
88 // Call the map vote tallying function
89 const tallyResult = await mapVoteTallying(channelId);
90
12const MINIMUM_VOTING_PERIOD_MS = 3 * 24 * 60 * 60 * 1000; // 3 days in milliseconds
13
14// Main function that runs as a scheduled val for tallying second half votes
15export default async function() {
16 console.log("🕒 Second Half Map Vote Tally Cron Job started");
17
111 const tallyStartTime = Date.now();
112
113 // Call the map vote tallying function
114 const tallyResult = await mapVoteTallying(channelId);
115
12const MINIMUM_VOTING_PERIOD_MS = 3 * 24 * 60 * 60 * 1000; // 3 days in milliseconds
13
14// Main function that runs as a scheduled val for tallying votes
15export default async function() {
16 console.log("🕒 Map Vote Tally Cron Job started");
17
110 const tallyStartTime = Date.now();
111
112 // Call the map vote tallying function
113 const tallyResult = await mapVoteTallying(channelId);
114

TowniePreviewFrame.tsx4 matches

@valdottownUpdated 4 days ago
9}
10
11export function PreviewFrame(props: PreviewProps) {
12 const previewKey = useRef<string>("new-chat");
13 const [count, setCount] = useState<number>(0);
73const TSRE = /\/$/;
74
75function URLInput({ url, pathname, setPathname }) {
76 const prefix = url.replace(TSRE, "");
77 return (
90}
91
92function PreviewSelect({ index, setIndex, files }) {
93 return (
94 <div>
116}
117
118function usePreviewURL({ files }) {
119 const [index, setIndex] = useState<number>(0);
120 const htmlVals = files?.filter(file => file.links?.endpoint !== undefined);
326 this.updateRateLimitFromException(routeKey, retryAfter);
327
328 // Check if retry time would exceed the function timeout
329 const MAX_WAIT_TIME = 8 * 60 * 1000; // 8 minutes (to stay safely under 10 min limit)
330 if (retryAfter * 1000 > MAX_WAIT_TIME) {
331 console.log(`⚠️ Retry time (${retryAfter}s) would exceed function timeout.`);
332 console.log(`Saving state to blob and failing with suggestion to retry later.`);
333
336
337 throw new Error(
338 `Rate limit retry time (${retryAfter}s) exceeds function timeout. `
339 + `Please try again later. State has been saved to resume properly.`,
340 );
367 const MAX_WAIT_TIME = 8 * 60 * 1000; // 8 minutes
368 if ((this.globalRateLimitUntil - Date.now()) > MAX_WAIT_TIME) {
369 console.log(`⚠️ Global rate limit wait time (${waitTime}s) would exceed function timeout.`);
370 console.log(`Saving state and failing with suggestion to retry later.`);
371
374
375 throw new Error(
376 `Global rate limit wait time (${waitTime}s) exceeds function timeout. `
377 + `Please try again later. State has been saved to resume properly.`,
378 );
616 console.log(`Rate limit exhausted for route ${routeKey}. Waiting ${waitTimeWithBuffer}ms until reset.`);
617
618 // Check if wait time would exceed the function timeout
619 const MAX_WAIT_TIME = 8 * 60 * 1000; // 8 minutes
620 if (waitTimeWithBuffer > MAX_WAIT_TIME) {
621 console.log(`⚠️ Wait time (${waitTimeWithBuffer}ms) would exceed function timeout.`);
622 console.log(`Saving state and failing with suggestion to retry later.`);
623
626
627 throw new Error(
628 `Rate limit wait time exceeds function timeout. `
629 + `Please try again later. State has been saved to resume properly.`,
630 );
672 console.log(`Global rate limit window full. Waiting ${waitTime}ms for a slot to open.`);
673
674 // Check if wait time would exceed the function timeout
675 const MAX_WAIT_TIME = 8 * 60 * 1000; // 8 minutes
676 if (waitTime > MAX_WAIT_TIME) {
677 console.log(`⚠️ Global rate limit wait time (${waitTime}ms) would exceed function timeout.`);
678 console.log(`Saving state and failing with suggestion to retry later.`);
679
682
683 throw new Error(
684 `Global rate limit wait time exceeds function timeout. `
685 + `Please try again later. State has been saved to resume properly.`,
686 );
692 }
693
694 // Helper function to create a delay
695 private delay(ms: number): Promise<void> {
696 return new Promise(resolve => setTimeout(resolve, ms));
11
12// Calculate days in a month, accounting for leap years
13function getDaysInMonth(year: number, month: number): number {
14 return new Date(year, month, 0).getDate();
15}
16
17// Format date as MM-DD
18function formatDate(date: Date): string {
19 return `${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
20}
21
22// Calculate the date range for the second half of current month
23function calculateSecondHalfCurrentMonth(): { startDate: string; endDate: string; rangeText: string } {
24 const now = new Date();
25 const year = now.getFullYear();
40}
41
42// Main function that runs as a scheduled val for second half
43export default async function() {
44 console.log("🕒 Second Half Map Vote Cron Job started");
45
11
12// Calculate days in a month, accounting for leap years
13function getDaysInMonth(year: number, month: number): number {
14 return new Date(year, month, 0).getDate();
15}
16
17// Format date as MM-DD
18function formatDate(date: Date): string {
19 return `${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
20}
21
22// Calculate the date range for the first half of next month
23function calculateFirstHalfNextMonth(): { startDate: string; endDate: string; rangeText: string } {
24 const now = new Date();
25
46}
47
48// Main function that runs as a scheduled val for first half
49export default async function() {
50 console.log("🕒 First Half Map Vote Cron Job started");
51

getFileEmail4 file matches

@shouserUpdated 2 weeks ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblkUpdated 2 weeks ago
Simple functional CSS library for Val Town
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
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": "*",