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=1576&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 18574 results for "function"(3363ms)

1const JWT = Deno.env.get("PINATA_JWT");
2
3async function main() {
4 try {
5 console.log("uploading file");

asciiNycCamerasmain.tsx7 matches

@maxm•Updated 11 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 11 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 11 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 = ?`,

threedEmojimain.tsx2 matches

@iamseeley•Updated 11 months ago
1import * as THREE from 'https://cdn.skypack.dev/three@0.128.0';
2
3export function create3DEmoji(emoji, width, height) {
4 // canvas element
5 const canvas = document.createElement('canvas');
57
58 // animation loop
59 function animate() {
60 requestAnimationFrame(animate);
61

asciiImageExamplemain.tsx1 match

@maxm•Updated 11 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 11 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 11 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 }

threedEmojiREADME.md1 match

@iamseeley•Updated 11 months ago
8```
9
10call the function after the DOM has loaded
11```JavaScript
12import { create3DEmoji } from 'https://esm.town/v/iamseeley/threedEmoji';

imageToAsciimain.tsx1 match

@maxm•Updated 11 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 = "";

getFileEmail4 file matches

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

tuna8 file matches

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