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=123&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 20741 results for "function"(1772ms)

Townie-05soundEffects.ts3 matches

@jxnblk•Updated 3 days ago
1/**
2 * Sound effects utility functions for the application
3 */
4
7 * @returns A Promise that resolves when the sound has started playing
8 */
9export function playBellSound(): Promise<void> {
10 return new Promise((resolve) => {
11 try {
69 * @returns A Promise that resolves when the sound has started playing
70 */
71export function playSimpleNotification(): Promise<void> {
72 return new Promise((resolve) => {
73 try {

Townie-05schema.tsx2 matches

@jxnblk•Updated 3 days ago
22}
23
24async function createTables() {
25 // archive a table
26 // await sqlite.execute(
68}
69
70async function deleteTables() {
71 await sqlite.execute(`DROP TABLE IF EXISTS ${USAGE_TABLE}`);
72 await sqlite.execute(`DROP TABLE IF EXISTS ${INFERENCE_CALLS_TABLE}`);

Townie-05requests.ts5 matches

@jxnblk•Updated 3 days ago
29}
30
31export function renderRequests(data: RequestRow[], pagination: PaginationData, baseUrl: string): string {
32 // Calculate totals
33 const totalRequests = pagination.totalItems;
39 // Client-side script for collapsible rows
40 const script = `
41 // Function to toggle inference details
42 function toggleInferenceDetails(usageId) {
43 const detailsElement = document.getElementById('inference-' + usageId);
44
153
154 // Add click event listeners to all collapsible rows
155 document.addEventListener('DOMContentLoaded', function() {
156 document.querySelectorAll('.collapsible').forEach(row => {
157 row.addEventListener('click', function() {
158 const usageId = this.getAttribute('data-id');
159 toggleInferenceDetails(usageId);

Townie-05requests.ts4 matches

@jxnblk•Updated 3 days ago
6 * Get paginated usage requests
7 */
8export async function getRequests(url: URL) {
9 const { page, pageSize } = getPaginationParams(url);
10
35 * Get a single request by ID
36 */
37export async function getRequestById(id: string) {
38 const result = await sqlite.execute(`
39 SELECT * FROM ${USAGE_TABLE}
51 * Get inference calls for a specific usage request
52 */
53export async function getInferenceCallsForRequest(usageId: string) {
54 const result = await sqlite.execute(`
55 SELECT
75 * Calculate totals from inference calls for a request
76 */
77export async function getInferenceTotalsForRequest(usageId: string) {
78 const calls = await getInferenceCallsForRequest(usageId);
79

Townie-05queries.tsx6 matches

@jxnblk•Updated 3 days ago
7// but in the meantime, we can cache user info in memory
8const userIdCache: { [key: string]: any } = {};
9export async function getUser(bearerToken: string) {
10 if (userIdCache[bearerToken]) return userIdCache[bearerToken];
11
16}
17
18async function last24Hours(userId: string) {
19 const usage = await sqlite.execute(
20 `SELECT
40 "devto": 100, // hardcoded limit of $100 per day for dev.to, billed later
41};
42export async function overLimit(bearerToken: string) {
43 const user = await getUser(bearerToken);
44 const last24HourUsage = await last24Hours(user.id);
49}
50
51export async function insertInferenceCall({
52 usage_id,
53 input_tokens,
103}
104
105export async function startTrackingUsage({
106 bearerToken,
107 val_id,
145}
146
147export async function finishTrackingUsage({
148 rowid,
149 input_tokens,

Townie-05pagination.ts5 matches

@jxnblk•Updated 3 days ago
21 * Parse pagination parameters from URL
22 */
23export function getPaginationParams(url: URL): { page: number; pageSize: number } {
24 const page = parseInt(url.searchParams.get("page") || "1", 10);
25 const pageSize = parseInt(url.searchParams.get("pageSize") || "50", 10);
35 * Calculate pagination metadata
36 */
37export function calculatePagination(params: PaginationParams): PaginationResult {
38 const totalPages = Math.ceil(params.totalItems / params.pageSize);
39
51 * Generate SQL LIMIT and OFFSET clauses for pagination
52 */
53export function getPaginationSQL(page: number, pageSize: number): string {
54 const offset = (page - 1) * pageSize;
55 return `LIMIT ${pageSize} OFFSET ${offset}`;
59 * Generate HTML for pagination controls
60 */
61export function renderPaginationControls(pagination: PaginationResult, baseUrl: string): string {
62 const url = new URL(baseUrl);
63
64 // Function to generate page URL
65 const getPageUrl = (page: number) => {
66 url.searchParams.set("page", page.toString());

Townie-05layout.ts3 matches

@jxnblk•Updated 3 days ago
10}
11
12export function renderLayout(content: string, options: LayoutOptions): string {
13 const { title, activeTab = "dashboard", scripts = [], styles = [] } = options;
14
149 // Default scripts
150 const defaultScripts = `
151 document.addEventListener('DOMContentLoaded', function() {
152 // Tab navigation
153 document.querySelectorAll('.tab').forEach(tab => {
154 tab.addEventListener('click', function(e) {
155 if (this.getAttribute('href') === '#') {
156 e.preventDefault();

Townie-05inference-calls.ts1 match

@jxnblk•Updated 3 days ago
29}
30
31export function renderInferenceCalls(
32 data: InferenceCallRow[],
33 pagination: PaginationData,

Townie-05inference-calls.ts1 match

@jxnblk•Updated 3 days ago
6 * Get paginated inference calls
7 */
8export async function getInferenceCalls(url: URL) {
9 const { page, pageSize } = getPaginationParams(url);
10 const usageId = url.searchParams.get("usage_id");

Townie-05index.ts1 match

@jxnblk•Updated 3 days ago
11 * Main entry point for the usage dashboard
12 */
13export default async function(req: Request) {
14 // Check authentication first
15 const authResponse = await basicAuthMiddleware(req);

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.