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=96&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 20331 results for "function"(926ms)

untitled-2444scriptTypeDetector.ts5 matches

@all•Updated 2 days ago
21 technical: {
22 patterns: [
23 /\b(function|class|method|algorithm|implementation|interface|API|SDK)\b/i,
24 /\b(code|syntax|compiler|runtime|debug|exception|error|bug|fix)\b/i,
25 /\b(database|query|schema|table|index|key|value|record)\b/i,
68 * Detect the most likely script type from text
69 */
70export function detectScriptType(text: string): string {
71 // Sample the text if it's very long
72 const sampleText = text.length > 5000
120 * Check if text has screenplay formatting
121 */
122function hasScreenplayFormatting(text: string): boolean {
123 // Look for character name pattern (all caps, centered on line)
124 const lines = text.split("\n");
140 * Check if text has code blocks
141 */
142function hasCodeBlocks(text: string): boolean {
143 // Look for code block markers or indented code
144 return (
145 text.includes("```") ||
146 text.includes(" ") ||
147 /\b(function|class|const|let|var|import|export)\s+\w+/.test(text)
148 );
149}

untitled-2444tokenizer.ts1 match

@all•Updated 2 days ago
20 "ANGLE ON": 1, "POV": 1, "CLOSE UP": 1, "WIDE SHOT": 1, "MONTAGE": 1,
21 // Common programming tokens
22 "function": 1, "return": 1, "if": 1, "else": 1, "for": 1, "while": 1, "class": 1,
23 "const": 1, "let": 1, "var": 1, "import": 1, "export": 1, "from": 1, "async": 1, "await": 1,
24};

Assistantindex.ts4 matches

@charmaine•Updated 2 days ago
42const openai = new OpenAI();
43
44// Helper function to get session from cookies
45async function getSessionFromRequest(c: any) {
46 const sessionId = c.req.cookie("session_id");
47 if (!sessionId) {
52}
53
54// Helper function to set session cookie
55function setSessionCookie(c: any, sessionId: string) {
56 c.header("Set-Cookie", `session_id=${sessionId}; Path=/; HttpOnly; SameSite=Lax; Max-Age=2592000`);
57}

Assistantindex.html11 matches

@charmaine•Updated 2 days ago
211
212 // Initialize the app
213 function initApp() {
214 if (initialData.isLoggedIn) {
215 showMainApp();
274 }
275
276 function showLoginScreen() {
277 loginScreen.classList.remove('hidden');
278 mainApp.classList.add('hidden');
279 }
280
281 function showMainApp() {
282 loginScreen.classList.add('hidden');
283 mainApp.classList.remove('hidden');
285
286 // Load events from the API
287 async function loadEvents() {
288 try {
289 const response = await fetch('/api/events');
307
308 // Display events in the UI
309 function displayEvents(events) {
310 if (events.length === 0) {
311 eventsContainer.innerHTML = '<p class="text-center py-8 text-gray-500">No upcoming events</p>';
399
400 // Show event details in modal
401 function showEventDetails(event) {
402 currentEvent = event;
403
479
480 // Show reschedule modal
481 function showRescheduleModal() {
482 eventModal.classList.add('hidden');
483 rescheduleModal.classList.remove('hidden');
485
486 // Handle event deletion
487 async function handleDeleteEvent() {
488 if (!currentEvent) return;
489
517
518 // Handle event rescheduling
519 async function handleRescheduleEvent() {
520 if (!currentEvent) return;
521
564
565 // Handle assistant request
566 async function handleAssistantRequest() {
567 const message = assistantInput.value.trim();
568
668
669 // Show notification
670 function showNotification(message, isError = false) {
671 const notification = document.createElement('div');
672 notification.className = `fixed bottom-4 right-4 px-6 py-3 rounded-lg shadow-lg ${isError ? 'bg-red-500' : 'bg-green-500'} text-white`;

Assistantcalendar.ts10 matches

@charmaine•Updated 2 days ago
4const CALENDAR_API_BASE = "https://www.googleapis.com/calendar/v3";
5
6// Helper function to make authenticated requests to Google Calendar API
7async function makeCalendarRequest(
8 session: UserSession,
9 endpoint: string,
36
37// Get upcoming events from the user's primary calendar
38export async function getUpcomingEvents(
39 session: UserSession,
40 maxResults = 10,
68
69// Get a specific event by ID
70export async function getEvent(
71 session: UserSession,
72 eventId: string
81
82// Create a new calendar event
83export async function createEvent(
84 session: UserSession,
85 event: Partial<CalendarEvent>
96
97// Update an existing calendar event
98export async function updateEvent(
99 session: UserSession,
100 eventId: string,
112
113// Move an event to a new time
114export async function rescheduleEvent(
115 session: UserSession,
116 eventId: string,
129
130// Delete a calendar event
131export async function deleteEvent(
132 session: UserSession,
133 eventId: string
141
142// Search for events matching a query
143export async function searchEvents(
144 session: UserSession,
145 query: string,
163
164// Get available time slots for a given day
165export async function getAvailableTimeSlots(
166 session: UserSession,
167 date: string, // YYYY-MM-DD

Assistantauth.ts9 matches

@charmaine•Updated 2 days ago
12
13// Generate a random state for OAuth security
14export function generateState(): string {
15 const array = new Uint8Array(16);
16 crypto.getRandomValues(array);
19
20// Create the OAuth authorization URL
21export function getAuthUrl(state: string): string {
22 if (!GOOGLE_CLIENT_ID) {
23 throw new Error("GOOGLE_CLIENT_ID environment variable is not set");
38
39// Get the redirect URI based on the current environment
40function getRedirectUri(): string {
41 // This will be your Val Town URL
42 return `https://${Deno.env.get("VAL_HOSTNAME") || "your-username.val.run"}/auth/callback`;
44
45// Exchange authorization code for tokens
46export async function exchangeCodeForTokens(code: string): Promise<UserSession> {
47 if (!GOOGLE_CLIENT_ID || !GOOGLE_CLIENT_SECRET) {
48 throw new Error("Google OAuth credentials are not set");
95
96// Save user session to blob storage
97export async function saveSession(sessionId: string, session: UserSession): Promise<void> {
98 await blob.setJSON(`session_${sessionId}`, session);
99}
100
101// Get user session from blob storage
102export async function getSession(sessionId: string): Promise<UserSession | null> {
103 try {
104 return await blob.getJSON(`session_${sessionId}`);
109
110// Refresh access token if expired
111export async function refreshAccessToken(session: UserSession): Promise<UserSession> {
112 if (!GOOGLE_CLIENT_ID || !GOOGLE_CLIENT_SECRET) {
113 throw new Error("Google OAuth credentials are not set");
149
150// Generate a session ID cookie
151export function generateSessionId(): string {
152 const array = new Uint8Array(16);
153 crypto.getRandomValues(array);
156
157// Clear user session
158export async function clearSession(sessionId: string): Promise<void> {
159 await blob.delete(`session_${sessionId}`);
160}

base_user_codeindex.tsx1 match

@andreterron•Updated 2 days ago
4const baseUserCode = baseX("123456789BCDFGHJKLMNPQRSTVWXZ");
5
6function testCode(userCode = baseUserCode.encode(randomBytes(8))) {
7 console.log(userCode, userCode.length);
8}

untitled-2390new-file-3588.ts1 match

@amisplace•Updated 2 days ago
11 * @returns Response with the logs or error message
12 */
13export default async function(req: Request): Promise<Response> {
14 try {
15 // Get URL parameters

stevensDemogetWeather.ts5 matches

@kuanche•Updated 2 days ago
5const TABLE_NAME = `memories`;
6
7function summarizeWeather(weather: WeatherResponse) {
8 const summarizeDay = (day: WeatherResponse["weather"][number]) => ({
9 date: day.date,
21}
22
23async function generateConciseWeatherSummary(weatherDay) {
24 try {
25 // Get API key from environment
79}
80
81async function deleteExistingForecast(date: string) {
82 await sqlite.execute(
83 `
89}
90
91async function insertForecast(date: string, forecast: string) {
92 const { nanoid } = await import("https://esm.sh/nanoid@5.0.5");
93
108}
109
110export default async function getWeatherForecast(interval: number) {
111 const weather = await getWeather("New York City, NY");
112 console.log({ weather });

untitled-6906Main.tsx6 matches

@Get•Updated 2 days ago
4const openai = new OpenAI();
5
6// This function will be the main entry point for the Val
7export default async function handler(req: Request): Promise<Response> {
8 const url = new URL(req.url);
9 if (req.method === "POST") {
35}
36
37// Function to generate the HTML dashboard
38function generateHtml(initialText = "") {
39 return `
40<!DOCTYPE html>
189 });
190
191 function appendMessage(text, sender) {
192 const message = document.createElement('p');
193 message.classList.add('mud-text');
205}
206
207async function getOpenAIResponse(command: string): Promise<string> {
208 try {
209 const completion = await openai.chat.completions.create({

getFileEmail4 file matches

@shouser•Updated 3 weeks ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblk•Updated 3 weeks ago
Simple functional CSS library for Val Town
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.