Search
api
@romanewmedia
An interactive, runnable TypeScript val by romanewmedia
HTTP
export default async function(req: Request): Promise<Response> {
// Setup CORS Headers
const headers = new Headers();
headers.set("Access-Control-Allow-Origin", "*");
headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
headers.set("Access-Control-Allow-Headers", "Content-Type");
// Handle different HTTP methods
if (req.method === "OPTIONS") {
return new Response(null, { headers });
// If it's a POST request, read the request body
handlebarsExample
@tmcw
An interactive, runnable TypeScript val by tmcw
Script
export let handlebarsExample = (async () => {
const { default: Handlebars } = await import("npm:handlebars");
let source =
"<p>Hello, my name is {{name}}. I am from {{hometown}}. I have " +
"{{kids.length}} kids:</p>" +
"<ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>";
let template = Handlebars.compile(source);
let data = {
"name": "Alan",
"hometown": "Somewhere, TX",
tanHedgehog
@greatcode
An interactive, runnable TypeScript val by greatcode
HTTP
const app = new Hono();
type X = "asdf" | "qwer";
app.get("/api/page", (c) => {
const y: X = "zxcv";
return c.json({ message: "You are authorized" });
app.post('/gmail', async (c) => {
try {
const body = await c.req.json();
console.log(body)
} catch (e) {
val_U4m66UKKNC
@dhvanil
An interactive, runnable TypeScript val by dhvanil
Script
export default async function handler(req) {
try {
const result = await (async () => {
return 100;
return Response.json({ success: true, result });
} catch (error) {
return Response.json({
success: false,
error: error.message
}, { status: 500 });
val_gFodtl1Mdm
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_gFodtl1Mdm(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
// Attempt to exploit the rational number correction mechanism
const exploitRationalPrecision = () => {
// Create a function that forces rational interpretation
const forceRational = (num, denominator = 1000000) => {
// Convert any number to a rational approximation
const rational = Math.round(num * denominator) / denominator;
blob_admin
@pomdtr
Blob Admin This is a lightweight Blob Admin interface to view and debug your Blob data. Use this button to install the val: It uses basic authentication with your Val Town API Token as the password (leave the username field blank). TODO [x] /new - render a page to write a new blob key and value [x] /edit/:blob - render a page to edit a blob (prefilled with the existing content) [x] /delete/:blob - delete a blob and render success [x] add upload/download buttons [ ] Use modals for create/upload/edit/view/delete page (htmx ?) [ ] handle non-textual blobs properly [ ] use codemirror instead of a textarea for editing text blobs
Script
# Blob Admin
This is a lightweight Blob Admin interface to view and debug your Blob data.
![b7321ca2cd80899250589b9aa08bc3cae9c7cea276282561194e7fc537259b46.png](https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/311a81bb-18d8-4583-b7e3-64bac326f700/public)
Use this button to install the val:
[![](https://stevekrouse-button.express.val.run/Install)](https://www.val.town/v/stevekrouse/blob_admin_app/fork)
It uses [basic authentication](https://www.val.town/v/pomdtr/basicAuth) with your [Val Town API Token](https://www.val.town/settings/api) as the password (leave the username field blank).
/** @jsxImportSource https://esm.sh/hono@4.0.8/jsx **/
const app = new Hono();
app.use(
jsxRenderer(({ children }) => {
val_KMj03ciXmu
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_KMj03ciXmu(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
const generateRandomNumbers = (count) => {
const numbers = [];
for (let i = 0; i < count; i++) {
numbers.push(Math.random());
return numbers;
const analyzeDistribution = (numbers) => {
valle_tmp_53076151180486396547071678302139
@janpaul123
// This val will respond with a fun and styled HTML page saying "Hello, world!"
HTTP
// This val will respond with a fun and styled HTML page saying "Hello, world!"
export default async function main(): Promise<Response> {
const htmlContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
<style>
body {
codeshowcase
@ejfox
open "https://ejfox-codeshowcase.web.val.run/?code=$(pbpaste | jq -sRr @uri)" to get a screenshottable code snippet
HTTP
`open "https://ejfox-codeshowcase.web.val.run/?code=$(pbpaste | jq -sRr @uri)"` to get a screenshottable code snippet
* This val creates a simple code snippet display service.
* It accepts code via GET request, displays it in a
* beautifully-formatted syntax-highlighted snippet,
* uses an LLM to generate a title for the snippet,
* and allows shuffling through random, animated gradients.
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);
const code = url.searchParams.get("code") || "console.log(\"Hello, World!\");";
const language = url.searchParams.get("language") || "javascript";
cookiesDemo
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export let cookiesDemo = (req) => new Response(
`<h1>Cookie Playground</h1>
<pre>${req.headers.get('cookie')}</pre>
headers: {
"Content-Type": "text/html",
"Set-Cookie": `hi there friendlkajsfdljkasdfas=dfasf=asdfalskdfjalsfjasldkfj`,
scribe
@yawnxyz
// Inlined content from ./middleware.ts
HTTP
// Inlined content from ./middleware.ts
const groq = new Groq();
const hf = new HfInference(Deno.env.get("HUGGINGFACE_API_KEY"));
const MAX_CHUNK_SIZE_BYTES = 25 * 1024 * 1024; // 25 MB in bytes
const DEFAULT_WHISPER_MODEL = 'whisper-large-v3-turbo';
const MAX_TRANSCRIPT_CONTEXT = 3000; // Characters to keep from transcript history
type WhisperModel = 'whisper-large-v3-turbo' | 'distil-whisper-large-v3-en' | 'whisper-large-v3';
type WhisperResponseFormat = 'json' | 'verbose_json' | 'text';
interface TranscriptionParams {
model?: WhisperModel;
connect4_site
@saolsen
Play connect4. Write agents that play connect4. Battle your agents against other agents. It's fun.
HTTP
# Play connect4.
* Write agents that play connect4.
* Battle your agents against other agents.
* It's fun.
/* @jsxImportSource https://esm.sh/hono/jsx */
init("connect4_site");
const tracer = get_tracer("connect4_site");
// TODO:
// * htmx loading spinners
const _nanoid = customAlphabet("123456789abcdefghijklmnopqrstuvwxyz", 10);
renderFormAndSaveData
@adamwiggins
Render form and save data This val provides a web-based interface for collecting email addresses. It features a dual-functionality approach: when accessed via a web browser using a GET request, it serves an HTML form where users can submit their email address. If the script receives a POST request, it implies that the form has been submitted, and it proceeds to handle the incoming data. Fork this val to customize it and use it on your account.
HTTP
# Render form and save data
This val provides a web-based interface for collecting email addresses. It features a dual-functionality approach: when accessed via a web browser using a GET request, it serves an HTML form where users can submit their email address. If the script receives a POST request, it implies that the form has been submitted, and it proceeds to handle the incoming data.
Fork this val to customize it and use it on your account.
export const renderFormAndSaveData = async (
const weights = (await blob.getJSON("weights")) ?? [];
req: Request,
): Promise<Response> => {
// A visit from a web browser? Serve a HTML page with a form
if (req.method === "GET") {
return new Response(
api2
@endingwithali
An interactive, runnable TypeScript val by endingwithali
Script
export function api2(req, res) {
res.send("<script>alert('hellow')</script>");
rumsey_roulette
@sammeltassen
An interactive, runnable TypeScript val by sammeltassen
HTTP
const SCHEMA_VERSION = 5;
const KEY = new URL(import.meta.url).pathname.split("/").at(-1);
const TABLE_NAME = `${KEY}_objects_${SCHEMA_VERSION}`;
const MAX_REQUEST_SIZE = 105 * 1024 * 1024; // 105MB limit (allowing some overhead)
const CHUNK_SIZE = 500; // Number of objects to insert in a single SQL query
async function initializeDatabase() {
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
id INTEGER PRIMARY KEY AUTOINCREMENT,
data JSON NOT NULL