Search
bookmarksHtml
@ramkarthik
An interactive, runnable TypeScript val by ramkarthik
Script
export const bookmarksHtml = (bookmarks: any[], header: string = "") => {
let emailHtml = "";
header = header || `<h3>Here are your bookmarks from Raindrop:</h3>`;
let footer =
`<p>Email from val.town. You can unsubscribe by clearing your interval here: https://val.town/@me.intervals</p>`;
emailHtml = header;
emailHtml += "<br /><ol>";
bookmarks.forEach((i, index) => {
emailHtml +=
`<li><a href='${i.link}'>${i.title}</a><p>${i.excerpt}</p></li>`;
claude
@yawnxyz
// Define a mapping for model shortcuts
Script
const anthropic = new Anthropic({
// apiKey: 'my_api_key', // defaults to process.env["ANTHROPIC_API_KEY"]
// Define a mapping for model shortcuts
const modelMap = {
opus: "claude-3-opus-20240229",
sonnet: "claude-3-sonnet-20240229",
haiku: "claude-3-haiku-20240307",
export async function prompt(
text,
{ mode = "text", model = "opus", max_tokens = 1024, messages = [] } = {},
resilientFetch
@easrng
resilientFetch : faster @std/fetch Try to fetch unproxied first, and fall back to proxied fetch if that fails.
Script
# `resilientFetch`: faster @std/fetch
Try to fetch unproxied first, and fall back to proxied fetch if that fails.
async function proxiedFetch(req: Request): Promise<Response> {
let query = new URLSearchParams({
url: req.url,
const headers = new Headers(req.headers);
headers.set("X-Valtown-Authorization", `Bearer ${Deno.env.get("valtown")}`);
return fetch(`${API_URL}/v1/fetch?${query}`, {
...req,
headers,
mdConvert
@nbbaier
mdConvert Inspired by markdown.rest . Converts markdown (plain text or base64 encoded) to HTML (plain text or base64 encoded)
HTTP
## mdConvert
Inspired by [markdown.rest](https://markdown.rest/). Converts markdown (plain text or base64 encoded) to HTML (plain text or base64 encoded)
// a
const reqBodySchema = z.object({
isBase64: z.boolean().optional(),
returnBase64: z.boolean().optional(),
content: z.string(),
export default async function handler(request: Request) {
if (request.method !== "POST") {
return html(`
imaginativeScarletPike
@Fahad61814
An interactive, runnable TypeScript val by Fahad61814
Cron
export default async function (interval: Interval) {
valle_tmp_968339782978865140044532832103386
@janpaul123
// This val will simply respond with "Hello, World!" to any incoming HTTP request.
HTTP
// This val will simply respond with "Hello, World!" to any incoming HTTP request.
export default async function main(req: Request): Promise<Response> {
return new Response("Hello, World!");
authUtils
@ideofunk
* Generate a deterministic avatar based on email hash - authentication utilities val
* @param email User's email address
* @returns SVG string for avatar
Script
* Generate a deterministic avatar based on email hash - authentication utilities val
* @param email User's email address
* @returns SVG string for avatar
export function generateAvatar(email: string): string {
const hash = hashEmail(email);
const hue = parseInt(hash.slice(0, 3), 16) % 360;
const saturation = 70;
const lightness = 50;
return `
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
upscaleThisUrl
@andrew
// Forked from @liamdanielduffy.upscaleThisUrl
Express (deprecated)
export const upscaleThisUrl = async (req, res) => {
const authToken = process.env.REPLICATE_API_TOKEN;
const url = "https://api.replicate.com/v1/predictions";
const jobId = req.body?.jobId;
const imageUrl = req.body?.imageUrl;
if (!jobId && !imageUrl) {
res.status(400).json({
error:
"You must pass either a jobId or an imageUrl. You did not pass either.",
if (jobId && imageUrl) {
dude
@stevekrouse
Run squint in val.town!
Script
Run squint in val.town!
import * as squint from "npm:squint-cljs";
globalThis.squint_core = squint;
const program = `(js/console.log (+ 1 2 3))`;
let theString = squint.compileString(program, { repl: true, "elide-imports": true });
console.log(theString);
theString = theString.replace(`'squint-cljs/core.js'`, `'npm:squint-cljs/core.js'`);
const AsyncFunction = Object.getPrototypeOf(async function() {}).constructor;
await new AsyncFunction(theString)();
asyncExample1
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export let asyncExample1 = {p: Promise.resolve(10)}
chat
@chatgpt
// Forked from @webup.chat
Script
export const chat = async (
prompt: string | object = "Hello world",
options = {},
// Initialize OpenAI API stub
const { Configuration, OpenAIApi } = await import("https://esm.sh/openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI,
const openai = new OpenAIApi(configuration);
// Request chat completion
const messages = typeof prompt === "string"
cityLookup
@rafter
// Cities named Brooklyn
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
// Cities named Brooklyn
export let cityLookup = fetchJSON(
"https://nominatim.openstreetmap.org/search.php?city=brooklyn&format=jsonv2"
getTelAvivMobilitySpots
@rustyb
An interactive, runnable TypeScript val by rustyb
Script
interface APIResponse {
type: string;
crs: unknown;
features: unknown[];
export async function getTelAvivMobilitySpots() {
// const url =
// "https://gisn.tel-aviv.gov.il/arcgis/rest/services/IView2/MapServer/860/query?where=1=1&outFields=*&f=geojson";
const url = "https://app.digital4grids.com/api";
const json_data = await fetchJSON(url);
return { "json_data": [] };
aqi
@adrianlee
AQI Alerts Get email alerts when AQI is unhealthy near you. Set up Click Fork Change location (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via nominatim's geocoder API . Click Run Background This val uses nominatim's geocoder to get your lat, lon, and air quality data from OpenAQ. It uses EPA's NowCast
AQI Index calculation and severity levels. Learn more: https://www.val.town/v/stevekrouse.easyAQI
Cron
# AQI Alerts
Get email alerts when AQI is unhealthy near you.
![](https://i.imgur.com/hB56X7o.png)
## Set up
1. Click `Fork`
2. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
export async function aqi(interval: Interval) {
const location = "japanese prespretarian church, seattle, wa, 98144"; // <-- change to place, city, or zip code
const data = await easyAQI({ location });
if (!interval.lastRunAt) {
raw
@pomdtr
Fetch the source of a val This val was created before the introduction of https://esm.town Usage curl https://pomdtr-raw.web.val.run/v/<author>/<name>.<extension>[?v=<version>] To see the code of this val, use https://pomdtr-raw.web.val.run/v/pomdtr/raw.ts Examples Fetching the val code $ curl https://pomdtr-raw.web.val.run/v/pomdtr/add.tsx You can also use js , jsx and ts extension (only the content-type change, there is no transpilation). Fetching private val Pass an api token as an username $ curl "https://<token>@pomdtr-raw.web.val.run/v/pomdtr/privateVal.ts" Fetching the val README $ curl https://pomdtr-raw.web.val.run/v/pomdtr/add.md Getting an image $ curl https://pomdtr-raw.web.val.run/v/pomdtr/add.png Fetching a specific version of a val $ curl https://pomdtr-raw.web.val.run/v/pomdtr/raw.ts?v=66 You need to be authenticated to use this method. Fetching the val metadata $ curl https://pomdtr-raw.web.val.run/v/pomdtr/add.json Running vals locally using Deno Create a new val.ts file referencing the @pomdtr.add import { add } from "https://pomdtr-raw.web.val.run/v/pomdtr/add.ts";
console.log(add(1, 2)); then use deno run $ deno run ./val.ts
3 If you val accept a request and return a response, you can pass it to Deno.Serve to run it locally! import {raw} from "https://pomdtr-raw.web.val.run/v/pomdtr/raw.ts";
Deno.serve(raw); If your val is private, you can set the DENO_AUTH_TOKENS env. DENO_AUTH_TOKENS=<val-town-token>@pomdtr-raw.web.val.run deno run val.ts
HTTP
# Fetch the source of a val
> This val was created before the introduction of https://esm.town
## Usage
```console
curl https://pomdtr-raw.web.val.run/v/<author>/<name>.<extension>[?v=<version>]
To see the code of this val, use <https://pomdtr-raw.web.val.run/v/pomdtr/raw.ts>
async function createScreenshot(code: string) {
const apiUrl = "https://sourcecodeshots.com/api/image";
const resp = await fetch(apiUrl, {
method: "POST",