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%22Image%20title%22?q=function&page=2357&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 27538 results for "function"(6513ms)

getWeathermain.tsx1 match

@escalona•Updated 9 months ago
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export async function getWeather(location: string): Promise<WeatherResponse> {
4 return fetchJSON(`https://wttr.in/${location}?format=j1`);
5}

getWeatherREADME.md1 match

@escalona•Updated 9 months ago
1## Get Weather
2
3Simple function to get weather data from the free [wttr.in](https://wttr.in/:help) service.
4
5```ts

sunsetNYCalendarmain.tsx3 matches

@ejfox•Updated 9 months ago
2// and creates a simple form to generate a calendar of events occurring before sunset.
3
4async function server(request: Request): Promise<Response> {
5 try {
6 const url = new URL(request.url);
79}
80
81async function generateSunsetEvents(action: string, minutesBefore: number, endDate: Date) {
82 const events = [];
83 let currentDate = new Date();
105}
106
107async function getSunsetTime(date: Date): Promise<Date> {
108 const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
109 const response = await fetch(`https://api.sunrise-sunset.org/json?lat=40.7128&lng=-74.0060&date=${formattedDate}&formatted=0`);

TopHackerNewsDailyEmailmain.tsx3 matches

@browserbase•Updated 9 months ago
27// we create a OpenAI Tool that takes our schema as argument
28const extractContentTool: any = {
29 type: "function",
30 function: {
31 name: "extract_content",
32 description: "Extracts the content from the given webpage(s)",
56
57// we retrieve the serialized arguments generated by OpenAI
58const result = completion.choices[0].message.tool_calls![0].function.arguments;
59// the serialized arguments are parsed into a valid JavaScript array of objects
60const parsed = schema.parse(JSON.parse(result));

redditSearchmain.tsx4 matches

@sarahxc•Updated 9 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

slackScoutmain.tsx10 matches

@sarahxc•Updated 9 months ago
15}
16
17export default async function(interval: Interval): Promise<void> {
18 try {
19 await createTable();
38
39// Create an SQLite table
40async function createTable(): Promise<void> {
41 await sqlite.execute(`
42 CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
50
51// Fetch Hacker news, Twitter, and Reddit results
52async function fetchHackerNewsResults(topic: string): Promise<Website[]> {
53 return hackerNewsSearch({
54 query: topic,
58}
59
60async function fetchTwitterResults(topic: string): Promise<Website[]> {
61 return twitterSearch({
62 query: topic,
67}
68
69async function fetchRedditResults(topic: string): Promise<Website[]> {
70 return redditSearch({ query: topic });
71}
72
73function formatSlackMessage(website: Website): string {
74 const displayTitle = website.title || website.url;
75 return `*<${website.url}|${displayTitle}>*
78}
79
80async function sendSlackMessage(message: string): Promise<Response> {
81 const slackWebhookUrl = Deno.env.get("SLACK_WEBHOOK_URL");
82 if (!slackWebhookUrl) {
104}
105
106async function isURLInTable(url: string): Promise<boolean> {
107 const result = await sqlite.execute({
108 sql: `SELECT 1 FROM ${TABLE_NAME} WHERE url = :url LIMIT 1`,
112}
113
114async function addWebsiteToTable(website: Website): Promise<void> {
115 await sqlite.execute({
116 sql: `INSERT INTO ${TABLE_NAME} (source, url, title, date_published)
120}
121
122async function processResults(results: Website[]): Promise<void> {
123 for (const website of results) {
124 if (!(await isURLInTable(website.url))) {

digitalYellowRoadrunnermain.tsx1 match

@athyuttamre•Updated 9 months ago
11const client = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY") });
12
13async function main() {
14 const stream = client.beta.chat.completions.stream({
15 model: "gpt-4o-mini",

twitterSearchmain.tsx2 matches

@alexdphan•Updated 9 months ago
11}
12
13function formatTweetText(text: string): string {
14 // Remove any URLs from the text
15 text = text.replace(/https?:\/\/\S+/g, "");
32}
33
34export async function twitterSearch({
35 query,
36 maxResults = 4,

ForestryFinancialModelmain.tsx3 matches

@jbwinters•Updated 9 months ago
21);
22
23function App() {
24 const [landSize, setLandSize] = useState(1000);
25 const [sections, setSections] = useState(5);
124}
125
126function client() {
127 createRoot(document.getElementById("root")).render(<App />);
128}
132}
133
134export default async function server(request: Request): Promise<Response> {
135 return new Response(`
136 <!DOCTYPE html>

hackerNewsSearchmain.tsx8 matches

@alexdphan•Updated 9 months ago
9}
10
11export async function hackerNewsSearch({
12 query = "Artificial Intelligence",
13 pages = 3,
101}
102
103async function scrapePageThreads(page) {
104 const scrollToBottom = async () => {
105 await page.evaluate(async () => {
122 await scrollToBottom();
123
124 return page.evaluate(async (dateConverterFunctionString) => {
125 const convertDateInBrowser = async (relativeDate) => {
126 try {
127 // Reconstruct the date converter function from its string representation
128 const dateConverterFunction = eval(`(${dateConverterFunctionString})`);
129 const result = await dateConverterFunction({ relativeDate });
130
131 // Check if the result is a Response object (from a potential fetch call)
172 // Return the array of thread data
173 return threads;
174 }, convertRelativeDateToString.toString()); // Pass the string representation of the original function
175}
176
177async function goToNextPage(page, currentPage) {
178 // Scroll to the bottom of the page
179 await page.evaluate(async () => {

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.