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=2480&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 28783 results for "function"(4796ms)

grievingYellowAspmain.tsx3 matches

@stevekrouse•Updated 9 months ago
6import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
7
8// Utility functions
9const performSingleRequest = async (url) => {
10 const start = performance.now();
46};
47
48// Helper function to safely format numbers
49const safeToFixed = (number, decimalPlaces) => {
50 return number !== undefined && number !== null
286}
287
288export default async function(req: Request): Promise<Response> {
289 const stream = await renderToReadableStream(<App />, { bootstrapModules: [import.meta.url] });
290 return new Response(stream, { headers: { "content-type": "text/html" } });

checkHackerNewsForPatreonmain.tsx2 matches

@mikker•Updated 9 months ago
9const TABLE_NAME = `${KEY}_notified_stories`;
10
11async function initializeDatabase() {
12 await sqlite.execute(`
13 CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
19}
20
21async function checkHackerNewsForPatreon() {
22 await initializeDatabase();
23

serveUtilsmain.tsx4 matches

@g•Updated 9 months ago
1export function getFunctionComment(fn) {
2 try {
3 return fn.toString().match(/\/\*\s*(.+)\s*\*\//s)[1];
4 } catch (err) {
5 console.error(`Failed to get function comment: ${err.message}\n${fn.toString()}`);
6 throw err;
7 }
8}
9
10export function serve(fn, contentType = 'text/plain') {
11 return (ctx) => {
12 return new Response(getFunctionComment(fn), {
13 headers: {
14 'Content-Type': contentType,

timeZoneCompareToolmain.tsx6 matches

@paulkinlan•Updated 9 months ago
16];
17
18// Helper function to group timezones by country
19function groupTimezonesByCountry(timezones) {
20 return timezones.reduce((acc, zone) => {
21 const [continent, ...rest] = zone.split('/');
62];
63
64function TimezoneSelect({ onSelect }) {
65 const [selectedZone, setSelectedZone] = useState("");
66 const groupedTimezones = useMemo(() => groupTimezonesByCountry(DateTime.ZONE_NAMES || []), []);
101}
102
103function App({ initialTime }: { initialTime: string }) {
104 const [currentTime, setCurrentTime] = useState(DateTime.now());
105 const [userTimezone, setUserTimezone] = useState("");
163}
164
165function TimezoneRow({ zone, currentTime }: { zone: string; currentTime: DateTime }) {
166 const localTime = currentTime.setZone(zone || 'UTC');
167 const offset = localTime.offset / 60;
192}
193
194async function server(request: Request): Promise<Response> {
195 try {
196 // Set CORS headers

multipleBronzeCaterpillarmain.tsx1 match

@tbsvttr•Updated 9 months ago
1import { email } from "https://esm.town/v/std/email";
2
3export default async function handler(request: Request) {
4 if (request.method !== "POST") {
5 return Response.json({ message: "This val responds to POST requests." }, {

add_to_notion_w_aimain.tsx9 matches

@junhoca•Updated 9 months ago
35});
36
37function createPrompt(title, description, properties) {
38 let prompt =
39 "You are processing content into a database. Based on the title of the database, its properties, their types and options, and any existing descriptions, infer appropriate values for the fields:\n";
80}
81
82function processProperties(jsonObject) {
83 const properties = jsonObject.properties;
84 const filteredProps = {};
111}
112
113async function get_and_save_notion_db_processed_properties(databaseId)
114{
115 const response = await notion.databases.retrieve({ database_id: databaseId });
122}
123
124async function get_notion_db_info(databaseId) {
125 databaseId = databaseId.replaceAll("-", "");
126 let db_info = null;
137}
138
139async function get_and_save_notion_db_info(databaseId) {
140 databaseId = databaseId.replaceAll("-", "");
141 let db_info = await get_and_save_notion_db_processed_properties(databaseId);
144}
145
146function createZodSchema(filteredProps) {
147 const schemaObject = {};
148
193}
194
195function convertToNotionProperties(responseValues, filteredProps) {
196 const notionProperties = {};
197
268}
269
270async function process_text(dbid, text) {
271 const db_info = await get_notion_db_info(dbid);
272 const processed_message = await client.chat.completions.create({
283}
284
285async function addToNotion(databaseId, text) {
286 databaseId = databaseId.replaceAll("-", "");
287 const properties = await process_text(databaseId, text);

chatWithCerebrasmain.tsx3 matches

@lazyplatypus•Updated 9 months ago
5
6const MODELS = ["llama3.1-8b", "llama3.1-70b"];
7function App() {
8 const [messages, setMessages] = useState<Array<{ role: string; content: string }>>([]);
9 const [edits, setEdits] = useState<Array<{ id: number; content: string }>>(
128}
129
130function client() {
131 createRoot(document.getElementById("root")).render(<App />);
132}
136}
137
138async function server(request: Request): Promise<Response> {
139 if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
140 const { messages, model } = await request.json();

printedWhiteToadmain.tsx3 matches

@lazyplatypus•Updated 9 months ago
5
6const MODELS = ["llama3.1-8b", "llama3.1-70b"];
7function App() {
8 const [messages, setMessages] = useState<Array<{ role: string; content: string }>>([]);
9 const [edits, setEdits] = useState<Array<{ id: number; content: string }>>(
125}
126
127function client() {
128 createRoot(document.getElementById("root")).render(<App />);
129}
133}
134
135async function server(request: Request): Promise<Response> {
136 if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
137 const { messages, model } = await request.json();

honEmeraldSnailmain.tsx6 matches

@stevekrouse•Updated 9 months ago
5const MODEL = "claude-3-sonnet-20240229";
6
7function applyDiffs(html, diffs) {
8 console.log("Applying diffs. Initial HTML:", html);
9 console.log("Diffs to apply:", diffs);
54}
55
56function parseHTMLFromResponse(content) {
57 const htmlMatch = content.match(/```html\s*([\s\S]*?)\s*```/);
58 console.log("Parsed HTML from response:", htmlMatch && htmlMatch[1] ? htmlMatch[1].trim() : null);
60}
61
62function parseDiffsFromResponse(content) {
63 try {
64 const jsonMatch = content.match(/\{[\s\S]*\}/);
72
73
74function App() {
75 const [messages, setMessages] = useState<Array<{ role: string; content: string }>>([]);
76 const [edits, setEdits] = useState<Array<{ id: number; content: string }>>([]);
200}
201
202function client() {
203 createRoot(document.getElementById("root")).render(<App />);
204}
208}
209
210async function server(request: Request): Promise<Response> {
211 if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
212 const { Anthropic } = await import("https://esm.sh/@anthropic-ai/sdk@0.17.1");

selectHtmlmain.tsx7 matches

@yawnxyz•Updated 9 months ago
6import { JSDOM } from 'npm:jsdom';
7
8// Function to fetch HTML from a URL and remove <style> and <script> tags
9export async function fetchHtml(url, removeSelectors = "style, script, link, noscript, frame, iframe, comment") {
10 try {
11 const response = await fetch(url);
22}
23
24// Function to use Cheerio to select text from the html, and attempts to clean it a bit
25export function selectHtml(html, selector = "h1", removeSelectors = "style, script, link, noscript, frame, iframe, comment") {
26 const $ = cheerio.load(html); // Load the cleaned HTML into Cheerio
27 $(removeSelectors).remove(); // Remove unwanted tags
37}
38
39// Function to convert HTML to Pug using html2pug
40export function convertHtmlToPug(html, options = { tabs: true }) {
41 const pug = html2pug(html, options);
42 return pug;
59}
60
61export function convertHtmlToMarkdown(htmlStr: string, options?: ConversionOptions): string {
62 const dom = new JSDOM(htmlStr);
63 const markdown = semanticMarkdown(htmlStr, { ...options, overrideDOMParser: new dom.window.DOMParser() });

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.