Search

Results include substring matches and semantically similar vals. Learn more
jdan avatar
handCraftedFlagWales
@jdan
An interactive, runnable TypeScript val by jdan
Script
import { wavingBlackFlag } from "https://esm.town/v/jdan/wavingBlackFlag";
export const handCraftedFlagWales = String.fromCodePoint(
wavingBlackFlag,
"g".charCodeAt(0) + 0xE0000,
"b".charCodeAt(0) + 0xE0000,
"w".charCodeAt(0) + 0xE0000,
"l".charCodeAt(0) + 0xE0000,
"s".charCodeAt(0) + 0xE0000,
cancelTag,
matthamlin avatar
api400
@matthamlin
An interactive, runnable TypeScript val by matthamlin
Script
export function api400(req: express.Request, res: express.Response) {
res.status(400);
res.json({
failed: true,
janpaul123 avatar
valle_tmp_63664219849257147630054266136499
@janpaul123
// This val responds with an HTML form to input the user's name and greets them upon form submission
HTTP (deprecated)
// This val responds with an HTML form to input the user's name and greets them upon form submission
export default async function(req: Request): Promise<Response> {
if (req.method === "POST") {
const formData = new URLSearchParams(await req.text());
const name = formData.get("name") || "stranger";
const htmlResponse = `<h1>Hello, ${name}!</h1>`;
return new Response(htmlResponse, {
headers: { "Content-Type": "text/html" },
} else {
const htmlForm = `
easrng avatar
sql
@easrng
An interactive, runnable TypeScript val by easrng
Script
let batch: { statement: InStatement; promise: ReturnType<typeof Promise.withResolvers<ResultSet>> }[] | null = null;
async function flush() {
const currentBatch = batch;
batch = null;
try {
const results = await sqlite.batch(currentBatch.map(e => e.statement));
for (let i = 0; i < currentBatch.length; i++) {
currentBatch[i].promise.resolve(results[i]);
} catch (e) {
for (const query of currentBatch) {
andreterron avatar
reachingFreeTierLimit
@andreterron
An interactive, runnable TypeScript val by andreterron
Script
export const reachingFreeTierLimit = async (interval: Interval) => {
const threshold = 90;
// If the interval never ran, there's no time range to check for updates
if (!interval.lastRunAt) {
return;
const opts = {
headers: {
Authorization: `Bearer ${process.env.vt_token}`,
const me = await fetchJSON(
"https://api.val.town/v1/me",
janpaul123 avatar
valle_tmp_239473183576900634635727013442197
@janpaul123
// This val responds with an HTML form for users to input their name and get a greeting
HTTP (deprecated)
// This val responds with an HTML form for users to input their name and get a greeting
export default async function (req: Request): Promise<Response> {
// Reading form data if present
const formData = new URLSearchParams(await req.text());
const name = formData.get("name") || "Stranger"; // Get the user's name or default to "Stranger"
// Displaying the form and the personalized greeting
return new Response(`
<html>
<head>
<title>Greeting Form</title>
mbforbes avatar
githubUser
@mbforbes
An interactive, runnable TypeScript val by mbforbes
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
// Github profile
export let githubUser = fetchJSON(
"https://api.github.com/users/mbforbes"
case avatar
market_kelly_bet
@case
// Copied from https://github.com/Will-Howard/manifolio/blob/master/manifolio-ui/lib/calculate.ts
HTTP (deprecated)
const paramsSchema = z.object({
slug: z.coerce.string(),
estimatedProb: z.coerce.number().min(0).max(1),
bankroll: z.coerce.number().min(0),
deferenceFactor: z.coerce.number().min(0).max(1).optional().default(0.5),
// Copied from https://github.com/Will-Howard/manifolio/blob/master/manifolio-ui/lib/calculate.ts
function calculateNaiveKellyBet({
marketProb,
estimatedProb,
deferenceFactor,
wongbria avatar
emailRandomJoke
@wongbria
// Fetches a random joke.
Cron
// Fetches a random joke.
async function fetchRandomJoke() {
const response = await fetch(
"https://official-joke-api.appspot.com/random_joke",
return response.json();
const randomJoke = await fetchRandomJoke();
const setup = randomJoke.setup;
const punchline = randomJoke.punchline;
// Sends an email with the joke.
export const emailRandomJoke = email({
websandbox avatar
create
@websandbox
An interactive, runnable TypeScript val by websandbox
Script
export async function create({ code, token }: { code: string; token: string }) {
const { error, details, url } = await (await fetch("https://websandbox-createAPI.web.val.run", {
body: JSON.stringify({ code, token }),
method: "POST",
})).json();
if (error) {
const e = new Error(error);
if (details) {
(e as any).details = details;
return url;
stevekrouse avatar
dateme_sqlite
@stevekrouse
This script is buggy... import { setupDatabase } from "https://esm.town/v/stevekrouse/dateme_sqlite" await setupDatabase()
HTTP (deprecated)
This script is buggy...
```ts
await setupDatabase()
export function createTable() {
return sqlite.execute(`
CREATE TABLE IF NOT EXISTS DateMeDocs (
Name TEXT,
Profile TEXT,
Gender TEXT,
InterestedIn TEXT,
kognise avatar
transitCacheExpiry
@kognise
An interactive, runnable TypeScript val by kognise
Script
export const transitCacheExpiry = 60000;
nbbaier avatar
paginatedResponse
@nbbaier
Return a paginated response A helper function to take an array and return a paginated response. This is useful when defining one's own folders for pomdtr's vscode extension . Usage: const data = [...] export default async function(req: Request): Promise<Response> { return paginatedResponse(req, data); } For demo usage in the context of the vscode extension see this val .
Script
# Return a paginated response
A helper function to take an array and return a paginated response. This is useful when defining one's own folders for [pomdt
Usage:
```ts
const data = [...]
export default async function(req: Request): Promise<Response> {
export async function paginatedResponse(req: Request, data: any[], defaultLimit: number = 20): Promise<Response> {
const url = new URL(req.url);
const searchParams = Object.fromEntries(url.searchParams.entries());
const limit = parseInt(searchParams.limit) || defaultLimit;
fshine99 avatar
resyBot
@fshine99
Resy bot This bot books restaurant reservations via Resy. Use it to snipe reservations at your favorite restaurant! How to use it Set up a scheduled val to call it like this: const resyBotCron = async () => { const bookingInfo = await api(@vtdocs.resyBot, { slug: 'amaro-bar', city: 'ldn', day: '2023-07-05', start: '19:00', end: '21:00', partySize: 2, // Use https://www.val.town/settings/secrets for these! email: @me.secrets.resyEmail, password: @me.secrets.resyPassword, }); // If the val doesn't error, it successfully made a booking! // Send yourself an email like this: await @std.email({ text: bookingInfo, subject: 'resy bot made a booking for you!' }); } How it works This val makes the same requests that your browser would make when you reserve a slot on Resy (that's why it needs your login info – to request an auth token). When there isn't a matching slot, this val errors and nothing else happens. When a booking is available, this val books it and returns a description of the booking so you can email it to yourself (Resy will also email you). This val will then stop attempting bookings for you until you change one of the arguments you're passing (it concats the non-sensitive arguments and uses this as a key). Credit to @rlesser and @alp for their existing Resy vals (search for resy on here).
Script
# Resy bot
This bot books restaurant reservations via Resy. Use it to snipe reservations at your favorite restaurant!
## How to use it
Set up a [scheduled val](https://docs.val.town/scheduled-vals) to call it like this:
```ts
const resyBotCron = async () => {
let { resyBotData } = await import("https://esm.town/v/vtdocs/resyBotData");
export const resyBot = async (opts: {
slug: string; // amaro-bar
city: string; // ldn
vez avatar
editVal
@vez
An interactive, runnable TypeScript val by vez
Script
export const editVal = (body: {
code: string;
name?: string;
isInterval?: boolean;
fetchJSON(`api.val.town/run/`, {
headers: {
accept: "*/*",
authentication: process.env.valtown,
"content-type": "application/json",
body: JSON.stringify(body),