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%22Optional%20title%22?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 27819 results for "function"(8227ms)

FanFicScrapermain.tsx5 matches

@willthereader•Updated 8 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4// last stable version is v138
5function App() {
6 const [url, setUrl] = useState("");
7 const [result, setResult] = useState(null);
68}
69
70function client() {
71 console.log("Initializing client-side React application");
72 createRoot(document.getElementById("root")).render(<App />);
77}
78
79async function scrapePage(url) {
80 console.log(`Starting to scrape page: ${url}`);
81 const apiKey = Deno.env.get("ScrapingBeeAPIkey");
163}
164
165async function getApiKey() {
166 const apiKey = Deno.env.get("ScrapingBeeAPIkey");
167 if (!apiKey) {
172}
173
174async function server(request) {
175 console.log(`Received ${request.method} request for path: ${new URL(request.url).pathname}`);
176 if (request.method === "POST" && new URL(request.url).pathname === "/scrape") {

getBlobAndRenderAsImageREADME.md2 matches

@ashryanio•Updated 8 months ago
15
16 - The client-side React component makes a fetch request to "/image".
17 - This request is handled by our server function.
18
19
202. Server-side handling:
21
22 - The server function calls `blob.get("test.png")`.
23 - This `blob.get()` method makes an HTTP request to the Val Town API.
24 - The API returns a Response object containing the image data.

zygomorphicPurpleStoatmain.tsx1 match

@seanodotcom•Updated 8 months ago
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=5";
3
4export async function aqi(interval: Interval) {
5 const location = "Philadelphia"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });

jsonVisualizerAppmain.tsx3 matches

@tmcw•Updated 8 months ago
8SyntaxHighlighter.registerLanguage('json', json);
9
10function App() {
11 const [jsonInput, setJsonInput] = useState('');
12 const [parsedJson, setParsedJson] = useState('');
57}
58
59function client() {
60 createRoot(document.getElementById("root")).render(<App />);
61}
63if (typeof document !== "undefined") { client(); }
64
65export default async function server(request: Request): Promise<Response> {
66 return new Response(`
67 <html>

count_visitsmain.tsx4 matches

@nicosql•Updated 8 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 const [websiteUrl, setWebsiteUrl] = useState("");
7 const [embedCode, setEmbedCode] = useState("");
61}
62
63function client() {
64 createRoot(document.getElementById("root")).render(<App />);
65}
69}
70
71async function server(request: Request): Promise<Response> {
72 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
73 const SCHEMA_VERSION = 1;
92import { useState, useEffect } from 'react';
93
94function VisitorCounter() {
95 const [count, setCount] = useState(0);
96

redditSearchmain.tsx4 matches

@nicosql•Updated 8 months ago
15
16// Use Browserbase (with proxy) to search and scrape Reddit results
17export async function redditSearch({
18 query,
19 apiKey = Deno.env.get("BROWSERBASE_API_KEY"),
46}
47
48function constructSearchUrl(query: string): string {
49 const encodedQuery = encodeURIComponent(query).replace(/%20/g, "+");
50 return `https://www.reddit.com/search/?q=${encodedQuery}&type=link&t=week`;
51}
52
53async function extractPostData(page: any): Promise<Partial<ThreadResult>[]> {
54 return page.evaluate(() => {
55 const posts = document.querySelectorAll("div[data-testid=\"search-post-unit\"]");
67}
68
69async function processPostData(postData: Partial<ThreadResult>[]): Promise<ThreadResult[]> {
70 const processedData: ThreadResult[] = [];
71

ablePinkDogmain.tsx5 matches

@nicosql•Updated 8 months ago
11};
12
13async function createSessionTable(tableName: string) {
14 await sqlite.execute(`CREATE TABLE ${tableName} (
15 id TEXT NOT NULL PRIMARY KEY,
19}
20
21async function createSession(tableName: string, valSlug: string): Promise<Session> {
22 try {
23 const expires_at = new Date();
39}
40
41async function getSession(tableName: string, sessionID: string, valSlug: string): Promise<Session> {
42 try {
43 const { rows, columns } = await sqlite.execute({
80</html>`;
81
82export function redirect(location: string): Response {
83 return new Response(null, {
84 headers: {
98const cookieName = "auth_session";
99
100export function passwordAuth(next, options?: PasswordAuthOptions) {
101 const sessionTable = options?.sessionTable || "password_auth_session";
102 return async (req: Request) => {

renderFormAndSaveDataREADME.md1 match

@nicosql•Updated 8 months ago
1# Render form and save data
2
3This val provides a web-based interface for collecting email addresses. It features a dual-functionality approach: when accessed via a web browser using a GET request, it serves an HTML form where users can submit their email address. If the script receives a POST request, it implies that the form has been submitted, and it proceeds to handle the incoming data.
4
5Fork this val to customize it and use it on your account.

harshAquamarineRoostermain.tsx7 matches

@nicosql•Updated 8 months ago
31
32// ------------
33// Functions
34// ------------
35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
49}
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
64}
65
66function createResError(body: string) {
67 try {
68 const e = zLibsqlError.parse(JSON.parse(body));
85}
86
87function normalizeStatement(statement: InStatement, args?: InArgs) {
88 if (Array.isArray(statement)) {
89 // for the case of an array of arrays
107}
108
109function upgradeResultSet(results: ImpoverishedResultSet): ResultSet {
110 return {
111 ...results,
116// adapted from
117// https://github.com/tursodatabase/libsql-client-ts/blob/17dd996b840c950dd22b871adfe4ba0eb4a5ead3/packages/libsql-client/src/sqlite3.ts#L314C1-L337C2
118function rowFromSql(
119 sqlRow: Array<unknown>,
120 columns: Array<string>,

hexmazemain.tsx6 matches

@pperi•Updated 8 months ago
14let colorIndex: number
15
16export function setup() {
17 console.log("setup")
18 // variables
77}
78
79function hexagon(x, y, r, c) {
80 let hx = (i) => x + sin((i * 2 * PI) / 6) * (i < 0 ? 0 : r)
81 let hy = (i) => y + cos((i * 2 * PI) / 6) * (i < 0 ? 0 : r)
201}
202
203function drawBorder(border, strokeW = 0) {
204 strokeWeight(0)
205 rect(0, 0, border, height)
216}
217
218export function draw() {}
219
220export function keyPressed() {
221 if (key == "i") {
222 saveCanvas("p5js-" + new Date().getTime(), "png")
226 }
227}
228// export function touchEnded() {
229// saveCanvas("p5js-" + new Date().getTime(), "png");
230// }

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.