1export default async function(req: Request): Promise<Response> {
2 return Response.json({
3 idea: `imagine that https://www.${crypto.randomUUID()}.com was a cool web site about ${crypto.randomUUID()}`,
21export default router.fetch;
22
23export async function createScreenshot(code: string, theme: string = "dark-plus"): Promise<URL> {
24 const apiUrl = "https://sourcecodeshots.com/api/image/permalink";
25 const { url } = await ky.post(apiUrl, {
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI";
3
4export async function aqi(interval: Interval) {
5 const location = "Brooklyn Navy Yard, Brooklyn"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });
2
3const openai = new OpenAI();
4const functionExpression = await openai.chat.completions.create({
5 "messages": [
6 { "role": "user", "content": "whats the weather in sf" },
8 tools: [
9 {
10 function: {
11 name: "weather",
12 parameters: {
19 },
20 },
21 type: "function",
22 },
23 ],
26});
27
28console.log(functionExpression.choices);
1export function currentDate() {
2 return new Date();
3}
7The idea is simple: you write down a javascript snippet (named vals) in your browser, and it's instantly executed on a server. You can use it to:
8
9- execute a function on a cron schedule
10- host a small websites (this article [hosted on Val Town](https://www.val.town/v/pomdtr/love_letter))
11- send yourself emails
32
33// run every hour
34export default function(interval: Interval) {
35 // create the val table
36 await options.sqlite.execute(createQuery);
78
79// triggered each time an email is sent to pomdtr.sqlite_email@valtown.email
80export default async function(email: Email) {
81 // forward the email to my own email address
82 await sendEmail({
96## Publishing the Table
97
98The val.town stdlib provides a neat `rpc` function that provides a simple way to expose a function as an API. So I decided to write a simple val that would run a query on the table, and return the result.
99
100```ts
3// Send a pushover message.
4// token, user, and other opts are as specified at https://pushover.net/api
5export default async function pushover({
6 token,
7 user,
3const NEWSLETTER_URL = "https://bytes.dev/archives";
4
5function normalizeURL(url: string) {
6 return url.startsWith("http://") || url.startsWith("https://")
7 ? url
9}
10
11async function fetchText(url: string, options?: any) {
12 const response = await fetch(normalizeURL(url), {
13 redirect: "follow",
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
9};
10
11export function authMiddleware(
12 handler: (Request) => Promise<Response>,
13 options: Options,
56}
57
58export default async function(req: Request): Promise<Response> {
59 return new Response("This is middleware only");
60}
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.