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/$%7Bsuccess?q=function&page=2353&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 28753 results for "function"(1836ms)

burnCaloriesCalculatormain.tsx3 matches

@Azazil•Updated 6 months ago
13};
14
15function CalorieCalculator() {
16 const [weight, setWeight] = useState('');
17 const [exercise, setExercise] = useState('walking');
87}
88
89function client() {
90 createRoot(document.getElementById("root")).render(<CalorieCalculator />);
91}
92if (typeof document !== "undefined") { client(); }
93
94export default async function server(request: Request): Promise<Response> {
95 return new Response(`
96 <html>

huntTheWumpusWebVersionmain.tsx6 matches

@roboninja•Updated 6 months ago
8const MAX_ARROWS = 3;
9
10function generateMap() {
11 const map = Array(ROOMS).fill(null);
12
40}
41
42function getAdjacentRooms(room) {
43 const row = Math.floor(room / GRID_SIZE);
44 const col = room % GRID_SIZE;
54}
55
56function checkNearbyHazards(map, playerRoom) {
57 const adjacentRooms = getAdjacentRooms(playerRoom);
58 const hazards = adjacentRooms.map(room => map[room]).filter(Boolean);
64}
65
66function WumpusGame() {
67 const [game, setGame] = useState(() => generateMap());
68 const [message, setMessage] = useState("Welcome to Hunt the Wumpus! Kill the Wumpus to reveal the treasure!");
517}
518
519function client() {
520 createRoot(document.getElementById("root")).render(<WumpusGame />);
521}
523if (typeof document !== "undefined") { client(); }
524
525export default async function server(request: Request): Promise<Response> {
526 return new Response(`
527 <html>

BadmintonMatchMakerAppmain.tsx3 matches

@botuha20•Updated 6 months ago
115}
116
117function App() {
118 const [players, setPlayers] = useState<Player[]>([]);
119 const [name, setName] = useState('');
242}
243
244function client() {
245 createRoot(document.getElementById("root")).render(<App />);
246}
247if (typeof document !== "undefined") { client(); }
248
249export default async function server(request: Request): Promise<Response> {
250 return new Response(`
251 <html>

authUtilsmain.tsx4 matches

@ideofunk•Updated 6 months ago
4 * @returns SVG string for avatar
5 */
6export function generateAvatar(email: string): string {
7 const hash = hashEmail(email);
8 const hue = parseInt(hash.slice(0, 3), 16) % 360;
31 * @returns Hexadecimal hash string
32 */
33export function hashEmail(email: string): string {
34 const encoder = new TextEncoder();
35 const data = encoder.encode(email.toLowerCase().trim());
44 * @returns Base32 encoded secret
45 */
46export function generateTOTPSecret(): string {
47 const array = new Uint8Array(20);
48 crypto.getRandomValues(array);
61 * @returns Boolean indicating code validity
62 */
63export function validateTOTPCode(secret: string, userCode: string): boolean {
64 // Simplified TOTP validation
65 const currentTime = Math.floor(Date.now() / 30000);

sqLiteDatabasemain.tsx5 matches

@ideofunk•Updated 6 months ago
5 * Includes users, login attempts, and verification tokens
6 */
7export async function initializeDatabase() {
8 // Use the val's unique identifier as a prefix for tables
9 const KEY = "sqLiteDatabase";
67
68/**
69 * Utility function to reset or clean up database
70 * Use with caution in production
71 */
72export async function resetDatabase() {
73 const KEY = "sqLiteDatabase";
74 const SCHEMA_VERSION = 3;
94
95/**
96 * Utility function to perform database migrations
97 * Call this when schema changes are needed
98 */
99export async function migrateDatabase() {
100 const KEY = "sqLiteDatabase";
101 const SCHEMA_VERSION = 3;

big5PersonalityTestmain.tsx20 matches

@manyone•Updated 6 months ago
1export default async function server(request: Request): Promise<Response> {
2 const { blob } = await import("https://esm.town/v/std/blob");
3 const QUIZ_KEY = "big5PersonalityTest" + "_quiz_data";
168
169 <script>
170 document.addEventListener('DOMContentLoaded', function() {
171 // Debugging function to log errors
172 function logError(message, error) {
173 console.error(message, error);
174 alert(message + ': ' + (error ? error.toString() : 'Unknown error'));
226 var barChart = document.getElementById('bar-chart');
227
228 function displayQuestion() {
229 if (currentQuestionIndex >= questions.length) {
230 showResultsBtn.style.display = 'block';
239
240 radioOptions.innerHTML = '';
241 [1, 2, 3, 4, 5].forEach(function(rating) {
242 var label = document.createElement('label');
243 var radio = document.createElement('input');
246 radio.value = rating;
247
248 var existingResponse = responses.find(function(r) { return r.index === currentQuestionIndex; });
249 if (existingResponse && existingResponse.response === rating) {
250 radio.checked = true;
251 }
252
253 radio.addEventListener('change', function() { handleResponse(rating); });
254
255 label.appendChild(radio);
261 }
262
263 function handleResponse(rating) {
264 var currentQuestion = questions[currentQuestionIndex];
265
266 responses = responses.filter(function(r) { return r.index !== currentQuestionIndex; });
267
268 responses.push({
272 });
273
274 responses.sort(function(a, b) { return a.index - b.index; });
275
276 currentQuestionIndex++;
283 }
284
285 function completeQuiz() {
286 fetch('/submit', {
287 method: 'POST',
293 var scoringDetails = [];
294
295 responses.forEach(function(item) {
296 var adjustedScore = item.response;
297 if (item.code < 0) {
311 });
312
313 var totalScore = scoreTotals.reduce(function(a, b) { return a + b; }, 0);
314
315 var percentageScores = scoreTotals.map(function(score) {
316 return totalScore > 0 ? Math.round((score / totalScore) * 100) : 0;
317 });
319 barChart.innerHTML = '';
320
321 percentageScores.forEach(function(score, index) {
322 var barRow = document.createElement('div');
323 barRow.className = 'bar-row';
357 }
358
359 startButton.addEventListener('click', function() {
360 // Use absolute URL for fetching questions
361 fetch(window.location.origin + '/questions')
362 .then(function(response) {
363 console.log('Fetch response status:', response.status);
364 if (!response.ok) {
367 return response.json();
368 })
369 .then(function(loadedQuestions) {
370 console.log('Loaded questions:', loadedQuestions);
371 questions = loadedQuestions;
374 displayQuestion();
375 })
376 .catch(function(error) {
377 logError('Error fetching questions', error);
378 });

createMovieSitemain.tsx4 matches

@temptemp•Updated 6 months ago
4const app = new Hono();
5
6async function fetchMovies(page = 1, limit = 20) {
7 const cacheKey = `movies_page_${page}_limit_${limit}`;
8
39const movieCache = new Map();
40
41// Utility function to generate movie poster URL
42function getMoviePosterUrl(movie) {
43 return movie.poster_path
44 ? `https://image.tmdb.org/t/p/w300${movie.poster_path}`
172 <script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.js"></script>
173 <script>
174 // Ensure modal close functionality
175 document.addEventListener('DOMContentLoaded', () => {
176 const modal = document.getElementById('movieModal');

plantIdentifierAppmain.tsx7 matches

@mahtabtattur•Updated 6 months ago
53
54// Plant Detail Card Component
55function PlantDetailCard({ plant, confidence }) {
56 return (
57 <div className="bg-white shadow-lg rounded-2xl p-6 animate-slide-up">
112}
113
114// Plant Identification Function
115async function identifyPlant(file) {
116 return new Promise(async (resolve, reject) => {
117 try {
212
213// Main Plant Identifier Application Component
214function PlantIdentifierApp() {
215 const [selectedImage, setSelectedImage] = useState(null);
216 const [plantInfo, setPlantInfo] = useState(null);
473}
474
475// Client-side rendering function
476function client() {
477 createRoot(document.getElementById("root")).render(<PlantIdentifierApp />);
478}
484
485// Server-side response handler
486export default async function server(request: Request): Promise<Response> {
487 return new Response(`
488 <html>

rollADicemain.tsx7 matches

@liyi•Updated 6 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5/** Utility functions */
6function generateValidRoll(): number {
7 return Math.floor(Math.random() * 6) + 1;
8}
9
10function getDiceEmoji(roll: number): string {
11 const diceEmojis = [
12 '⚀', // 1
20}
21
22function formatTime(timestamp: number): string {
23 const date = new Date(timestamp);
24 return date.toLocaleTimeString(undefined, {
36}
37
38function App() {
39 const [roll, setRoll] = useState(generateValidRoll());
40 const [isRolling, setIsRolling] = useState(false);
234}
235
236function client() {
237 createRoot(document.getElementById("root")).render(<App />);
238}
239if (typeof document !== "undefined") { client(); }
240
241export default async function server(request: Request): Promise<Response> {
242 const roll = generateValidRoll();
243

valuableLavenderOpossummain.tsx1 match

@ayaanpatel1790•Updated 6 months ago
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 1 month 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.