17import jsQR from "https://esm.sh/jsqr";
18
19function App() {
20 const videoRef = useRef<HTMLVideoElement>(null);
21 const canvasRef = useRef<HTMLCanvasElement>(null);
133}
134
135function client() {
136 createRoot(document.getElementById("root")!).render(<App />);
137}
141}
142
143async function server(request: Request): Promise<Response> {
144 return new Response(`
145 <!DOCTYPE html>
3import { email } from "https://esm.town/v/std/email";
4
5export default async function(interval: Interval) {
6 let weather = await getWeather("Brooklyn, NY");
7 let feelsLike = weather.current_condition[0].FeelsLikeF;
12export type Handler = (req: Request) => Response | Promise<Response>;
13
14export function pwa(handler: Handler, manifest: Partial<ManifestOptions>): Handler {
15 return async (req: Request) => {
16 const url = new URL(req.url);
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}
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.