16];
17
18// Function to fetch recent questions from Stack Overflow for multiple topics
19async function fetchRecentQuestions(): Promise<StackExchange.Question[]> {
20 const allQuestions: StackExchange.Question[] = [];
21
34}
35
36// Function to format questions into HTML
37function formatQuestionsHtml(questions: StackExchange.Question[]): string {
38 return questions.map(q => `
39 <h2><a href="${q.link}">${q.title}</a></h2>
44}
45
46// Main cron job function
47async function cronJob() {
48 const { email } = await import("https://esm.town/v/std/email");
49
69}
70
71export default async function(interval: Interval) {
72 await cronJob();
73}
49### Linking to the val
50
51These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the `val` argument:
52
53- `modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }})`
9 * @param val Define which val should open. Defaults to the root reference
10 */
11export function modifyHtmlString(
12 bodyText: string,
13 { val, style }: { val?: ValRef; style?: string } = {},
40 * @param val Define which val should open
41 */
42export function modifyFetchHandler(
43 handler: (req: Request) => Response | Promise<Response>,
44 { val, style }: { val?: ValRef; style?: string } = {},
34const resultCache = new Map();
35
36export default async function server(request: Request): Promise<Response> {
37 if (request.method === "GET") {
38 return new Response(html, {
171const openai = new OpenAI();
172
173async function getEmbeddings(texts) {
174 const response = await openai.embeddings.create({
175 model: "text-embedding-ada-002",
203
204 <script>
205 function runDemo() {
206 const testData = {
207 embeddings: Array.from({length: 100}, () => Array.from({length: 10}, () => Math.random())),
4import type { User } from "https://esm.town/v/stevekrouse/zod_demo_shared";
5
6export function App() {
7 const [user, setUser] = useState<User>({ username: "", email: "", age: 0 });
8 const [errors, setErrors] = useState<Partial<User>>({});
2import { UserSchema } from "https://esm.town/v/stevekrouse/zod_demo_shared";
3
4async function server(request: Request): Promise<Response> {
5 if (request.method === "POST" && new URL(request.url).pathname === "/register") {
6 try {
31console.log(text);
32
33export async function weatherGPT() {
34 await email({ subject: "Weather Today", text });
35}
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=5";
3
4export async function aqi(interval: Interval) {
5 const location = "downtown brooklyn"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });
82});
83
84export default async function server(req: Request): Promise<Response> {
85 return app.fetch(req);
86}
141. The application uses the Hono framework to create a simple web server.
152. HTMX is used for handling AJAX requests without writing JavaScript.
163. Alpine.js provides reactivity for the clipboard functionality.
174. The Turndown library is used to convert HTML to Markdown.
18
A helper function to build a file's email
Simple functional CSS library for Val Town
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": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.