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=93&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 20286 results for "function"(1988ms)

SmartRoutesauth.ts2 matches

@Abbietech•Updated 2 days ago
3
4// Simple email verification token generation
5function generateToken(email: string): string {
6 const timestamp = Date.now().toString();
7 // In a real app, use a proper JWT or other secure token method
11
12// Verify token (simplified)
13export function verifyToken(token: string): string | null {
14 try {
15 const decoded = atob(token);

SmartRoutesREADME.md3 matches

@Abbietech•Updated 2 days ago
1# Database Layer
2
3This directory contains the database setup and query functions for the SmartRoutes application.
4
5## Files
6
7- `migrations.ts` - Contains the database schema definitions and migration functions
8- `queries.ts` - Contains typed query functions for interacting with the database
9
10## Database Schema

SmartRoutesqueries.ts8 matches

@Abbietech•Updated 2 days ago
30
31// User queries
32export async function createUser(email: string, name?: string): Promise<number> {
33 const result = await sqlite.execute(
34 `INSERT INTO ${USERS_TABLE} (email, name) VALUES (?, ?) RETURNING id`,
38}
39
40export async function getUserByEmail(email: string): Promise<User | null> {
41 const result = await sqlite.execute(
42 `SELECT * FROM ${USERS_TABLE} WHERE email = ?`,
46}
47
48export async function updateUserLastLogin(userId: number): Promise<void> {
49 await sqlite.execute(
50 `UPDATE ${USERS_TABLE} SET last_login = CURRENT_TIMESTAMP WHERE id = ?`,
54
55// Traffic report queries
56export async function createTrafficReport(
57 userId: number,
58 latitude: number,
70}
71
72export async function getRecentTrafficReports(
73 hours: number = 1,
74 limit: number = 100
84}
85
86export async function getTrafficReportsNearLocation(
87 latitude: number,
88 longitude: number,
106
107// Location queries
108export async function updateUserLocation(
109 userId: number,
110 latitude: number,
135}
136
137export async function getUserLocation(userId: number): Promise<Location | null> {
138 const result = await sqlite.execute(
139 `SELECT * FROM ${LOCATIONS_TABLE} WHERE user_id = ?`,

SmartRoutesmigrations.ts1 match

@Abbietech•Updated 2 days ago
7
8// Create tables if they don't exist
9export async function runMigrations() {
10 // Users table
11 await sqlite.execute(`

Jobsapp.js4 matches

@Fatima•Updated 2 days ago
27
28// Tab switching
29function switchTab(tabName) {
30 if (tabName === 'jobs') {
31 jobsTab.classList.add('tab-active');
55
56// Load jobs
57async function loadJobs() {
58 const jobs = await fetchJobs();
59 renderJobs(jobs, jobListings);
61
62// Load chat messages
63async function loadChatMessages() {
64 const messages = await fetchChatMessages();
65 renderChatMessages(messages, chatMessages);
67
68// Initialize the application
69async function initApp() {
70 // Try to load username from localStorage
71 const savedUsername = localStorage.getItem('username');

Jobschat.js9 matches

@Fatima•Updated 2 days ago
1// Chat functionality
2
3// Fetch chat messages
4export async function fetchChatMessages(limit = 50) {
5 try {
6 const response = await fetch(`/api/chat?limit=${limit}`);
16
17// Send a new chat message
18export async function sendChatMessage(userName, message) {
19 try {
20 const response = await fetch('/api/chat', {
42
43// Format date for display
44function formatDate(dateString) {
45 const date = new Date(dateString);
46 return date.toLocaleString();
48
49// Render chat messages
50export function renderChatMessages(messages, container) {
51 if (!messages || messages.length === 0) {
52 container.innerHTML = '<div class="text-center text-gray-500">No messages yet. Start the conversation!</div>';
87
88// Initialize chat form submission
89export function initChatForm(formElement, userNameInput, onSuccess) {
90 const chatSubmitButton = document.getElementById('chat-submit-button');
91 const usernameWarning = document.getElementById('username-warning');
92 const usernameRequired = document.getElementById('username-required');
93
94 // Function to check if username is provided
95 function checkUsername() {
96 const userName = userNameInput.value.trim();
97 const hasUsername = !!userName;
153
154// Poll for new messages
155export function startChatPolling(interval, callback) {
156 // Initial fetch
157 callback();

Jobsjobs.js6 matches

@Fatima•Updated 2 days ago
1// Job posting related functionality
2
3// Fetch all job postings
4export async function fetchJobs() {
5 try {
6 const response = await fetch('/api/jobs');
16
17// Create a new job posting
18export async function createJob(jobData) {
19 try {
20 const response = await fetch('/api/jobs', {
39
40// Format date for display
41function formatDate(dateString) {
42 const date = new Date(dateString);
43 return date.toLocaleString();
45
46// Render job listings
47export function renderJobs(jobs, container) {
48 if (!jobs || jobs.length === 0) {
49 container.innerHTML = '<li class="px-4 py-4 sm:px-6 text-gray-500">No job postings available.</li>';
69
70// Initialize job form submission
71export function initJobForm(formElement, onSuccess) {
72 formElement.addEventListener('submit', async (event) => {
73 event.preventDefault();

Jobstypes.ts2 matches

@Fatima•Updated 2 days ago
17}
18
19// Helper function to format dates
20export function formatDate(dateString: string): string {
21 const date = new Date(dateString);
22 return date.toLocaleString();

Jobsqueries.ts4 matches

@Fatima•Updated 2 days ago
20
21// Job posting queries
22export async function getAllJobs(): Promise<JobPosting[]> {
23 const result = await sqlite.execute(
24 `SELECT * FROM ${JOB_POSTINGS_TABLE} ORDER BY created_at DESC`
27}
28
29export async function createJob(job: Omit<JobPosting, "id" | "created_at">): Promise<JobPosting> {
30 const created_at = new Date().toISOString();
31
41
42// Chat message queries
43export async function getChatMessages(limit = 50): Promise<ChatMessage[]> {
44 const result = await sqlite.execute(
45 `SELECT * FROM ${CHAT_MESSAGES_TABLE}
51}
52
53export async function createChatMessage(message: Omit<ChatMessage, "id" | "created_at">): Promise<ChatMessage> {
54 const created_at = new Date().toISOString();
55

Jobsmigrations.ts1 match

@Fatima•Updated 2 days ago
5export const CHAT_MESSAGES_TABLE = "chat_messages_v1";
6
7export async function runMigrations() {
8 // Create job postings table
9 await sqlite.execute(`

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.