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/?q=function&page=1400&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 16586 results for "function"(1613ms)

asciiNycCamerasmain.tsx7 matches

@maxm•Updated 10 months ago
51
52 // Load and render GeoJSON data
53 d3.json("/nyc.geojson").then(function(data) {
54 svg.selectAll("path")
55 .data(data.features)
67 .attr("r", 5)
68 .attr("class", "link")
69 .on("click", function(event, d) {
70 showCamera(d.id);
71 })
72 .on("mouseover", function(event, d) {
73 d3.select(this).transition()
74 .duration(200)
77 d3.select(this).raise();
78 })
79 .on("mouseout", function(event, d) {
80 d3.select(this).transition()
81 .duration(200)
237
238 const source = new EventSource("/camera-text-stream/${c.req.param("id")}");
239 source.onopen = function(e) {
240 loadingInterval = setInterval(() => {
241 loadingBox.textContent = brailleChars[brailleChars.length - charIndex - 1] + ' streaming ' + brailleChars[charIndex];
243 }, 100);
244 }
245 source.onmessage = function(e) {
246 document.querySelector('pre').innerHTML = JSON.parse(e.data);
247 }
248 source.onerror = function(e) {
249 if (loadingInterval) clearInterval(loadingInterval);
250 loadingBox.textContent = 'Error';

blackLobstermain.tsx7 matches

@kingishb•Updated 10 months ago
29
30// Format an ISO datetime like Sun 06:00 AM
31function fmtDate(d: string): string {
32 return new Date(d).toLocaleString("en-US", { weekday: "short", hour: "numeric", minute: "numeric", hour12: true });
33}
34
35// Format ISO datetime like 06:00 AM
36function fmtTime(d: string): string {
37 return new Date(d).toLocaleString("en-US", { hour: "numeric", minute: "numeric", hour12: true });
38}
39
40// Retry a function n times with exponential backoff.
41async function retry<T>(fn: () => Promise<T>, n: number): Promise<T> {
42 for (let i = 0; i < n; i++) {
43 try {
53
54// Sleep a random amount of seconds (to respect NOAA's API).
55async function sleepRand(seconds: number) {
56 const s = Math.random() * seconds * 1000;
57 await new Promise(r => setTimeout(r, s));
59
60// Find some weather intervals!
61async function run(): Promise<string> {
62 try {
63 await sleepRand(15);
103}
104
105export default async function(interval: Interval) {
106 const msg = await retry(run, 3);
107 await email({ subject: "🚲 Good times to bike!", text: msg });

sqliteKVmain.tsx2 matches

@stevekrouse•Updated 10 months ago
5await setupSQLiteKV();
6
7export async function set(key, value) {
8 await sqlite.execute({
9 sql: `insert into kv (key, value) values (?, ?)
14}
15
16export async function get(key) {
17 return (await sqlite.execute({
18 sql: `select value from kv where key = ?`,

asciiImageExamplemain.tsx1 match

@maxm•Updated 10 months ago
1import { imageToAscii } from "https://esm.town/v/maxm/imageToAscii";
2
3export default async function(req: Request): Promise<Response> {
4 const { string, stringColor } = await imageToAscii(
5 "https://webcams.nyctmc.org/api/cameras/9fa5b0dd-e955-449e-97e1-9c53ad9c23a8/image",

pollRSSFeedsmain.tsx1 match

@squirals•Updated 10 months ago
3import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems";
4
5export async function pollRSSFeeds({ lastRunAt }: Interval) {
6 return Promise.all(
7 Object.entries(rssFeeds).map(async ([name, url]) => {

geolocation_api_demomain.tsx4 matches

@stevekrouse•Updated 10 months ago
1import { html } from "https://esm.town/v/stevekrouse/html";
2
3export default async function (req: Request): Promise<Response> {
4 return html(`
5 <button id="find-me">Show my location</button><br />
7 <a id="map-link" target="_blank"></a>
8 <script>
9 function geoFindMe() {
10 const status = document.querySelector("#status");
11 const mapLink = document.querySelector("#map-link");
14 mapLink.textContent = "";
15
16 function success(position) {
17 const latitude = position.coords.latitude;
18 const longitude = position.coords.longitude;
23 }
24
25 function error() {
26 status.textContent = "Unable to retrieve your location";
27 }

imageToAsciimain.tsx1 match

@maxm•Updated 10 months ago
26// Converted from: https://github.com/victorqribeiro/imgToAscii/blob/ca7e181b9bb9770798ed3a0d3dfeb344c60953f2/src/imgToAscii.js
27import { createCanvas, loadImage } from "https://deno.land/x/canvas@v1.4.1/mod.ts";
28export async function imageToAscii(src: string, maxWidth?: number) {
29 let string = "";
30 let stringColor = "";

createTursoProxymain.tsx1 match

@pomdtr•Updated 10 months ago
2import { createClient } from "npm:@libsql/client";
3
4export function createTursoProxy(databaseUrl: string, authToken: string) {
5 const client = createClient({
6 url: `${databaseUrl}?authToken=${Deno.env.get("TURSO_AUTH_TOKEN")}`,

circlesmain.tsx6 matches

@pomdtr•Updated 10 months ago
37// });
38
39function parseResultSet<T>(row: ResultSet): T[] {
40 return row.rows.map((r) => Object.fromEntries(r.map((c, i) => [row.columns[i], c]))) as T[];
41}
51};
52
53function diffCircles(array1: Circle[], array2: Circle[]): Circle[] {
54 const changes: Circle[] = [];
55
74
75 const drag = (() => {
76 function dragstarted() {
77 d3.select(this).attr("stroke", "black");
78 }
79
80 function dragged(event, d) {
81 d3.select(this).raise().attr("cx", d.x = event.x).attr("cy", d.y = event.y);
82 }
83
84 function dragended() {
85 const x = d3.select(this).attr("cx");
86 const y = d3.select(this).attr("cy");
105 .call(drag)
106 .on("click", clicked);
107 function clicked(event, d) {
108 if (event.defaultPrevented) return; // dragged
109

linkInBioTemplatemain.tsx1 match

@morsczx•Updated 10 months ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 1 week 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": "*",