Search

Results include substring matches and semantically similar vals. Learn more
thinkle_iacs avatar
multiply
@thinkle_iacs
An interactive, runnable TypeScript val by thinkle_iacs
Script
export function multiply(number) {
let n = Number(number);
return { value: `${n}×2=${n * 2}` };
maxm avatar
pgliteNpm
@maxm
An interactive, runnable TypeScript val by maxm
HTTP
INSERT INTO test (id, test, counter)
VALUES (1, 'valtown', 0);
export default async function(req: Request): Promise<Response> {
await db.query(`
UPDATE test
andre_h avatar
hnMuteStory
@andre_h
An interactive, runnable TypeScript val by andre_h
Script
let { hnBlockList } = await import("https://esm.town/v/andre_h/hnBlockList");
export function hnMuteStory(id) {
console.log(`Muting story ${id}`);
hnBlockList = [...(hnBlockList ?? []), id];
stevekrouse avatar
cloudmailin
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export function cloudmailin(req, res) {}
karfau avatar
test_dlock
@karfau
An interactive, runnable TypeScript val by karfau
Script
} as const,
async function should_reject_after_last_attempt(
dlock,
args: [`https://dlock.univalent.net/lock/${id}/aquire?ttl=${ttl}`],
async function should_reject_ttl_of_0(
{ dlock, id, ttl, fetchStub, assertMatch, assertRejects },
assertMatch(err.message, /ttl/);
async function should_return_lock_on_successful_request(
{ dlock, deadline, fetchStub, assertFalse, assertEquals },
// runs into endless loop!
async function skip_should_reject_when_id_is_locked(
{ dlock, id, ttl, deadline, fetchStub, assertRejects, assertEquals },
stevekrouse avatar
perf
@stevekrouse
Perf - a website performance tester I had Anthropic build this for me to show off the launch of HTTP (Preview) vals: https://blog.val.town/blog/http-preview/
HTTP
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
// Utility functions
const performSingleRequest = async (url) => {
highest: Math.max(...times),
// Helper function to safely format numbers
const safeToFixed = (number, decimalPlaces) => {
hydrateRoot(document, <App />);
export default async function(req: Request): Promise<Response> {
const stream = await renderToReadableStream(<App />, { bootstrapModules: [import.meta.url] });
baj avatar
zaobao
@baj
An interactive, runnable TypeScript val by baj
HTTP
import process from "node:process";
export async function zaobao() {
const res = await fetch(
`https://chrome.browserless.io/content?token=${process.env.browserlessKey}`,
geraldo avatar
aqi
@geraldo
AQI Alerts Get email alerts when AQI is unhealthy near you. 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
import { email } from "https://esm.town/v/std/email?v=9";
import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI";
export async function aqi(interval: Interval) {
const location = "barcelona"; // <-- change to place, city, or zip code
const data = await easyAQI({ location });
edyi8 avatar
energeticLimeStoat
@edyi8
// Fetches a random joke.
Email
// ... imports ...
// Fetches a random joke.
async function fetchRandomJoke() {
const response = await fetch(
"https://official-joke-api.appspot.com/random_joke",
g avatar
codepen_debug
@g
Codepen Debug Direct URLs to your Codepen projects. Not in an iframe!
HTTP
import { parseCodepen } from "https://esm.town/v/g/parseCodepen";
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
const id = url.pathname.slice(1);
gitneukev avatar
SAMPLE_JOKE
@gitneukev
// Fetches a random joke.
HTTP
import { email } from "https://esm.town/v/std/email?v=9";
// Fetches a random joke.
function fetchRandomJoke() {
const SAMPLE_JOKE = {
"setup": "What do you call a group of disorganized cats?",
roseznu avatar
expertCoralDinosaur
@roseznu
// Fetches a random joke.
Script
import { email } from "https://esm.town/v/std/email?v=9";
// Fetches a random joke.
async function fetchRandomJoke() {
const response = await fetch(
"https://official-joke-api.appspot.com/random_joke",
xkonti avatar
gameIdeaApi
@xkonti
This Val is a part of Creating GPT Actions with ValTown tutorial: Video on YouTube Article on xkonti.tech The GPT using it: Game Idea Exchange GPT
HTTP
const ideasKey = "game-ideas";
async function getIdeas(): Promise<Idea[]> {
let ideas = await blob.getJSON(ideasKey) as Idea[];
return ideas;
async function setIdeas(ideas: Idea[]): Promise<void> {
await blob.setJSON(ideasKey, ideas);
function getRandomElement<T>(array: T[]): T {
const randomIndex = Math.floor(Math.random() * array.length);
syncretizm avatar
formulaEndpoint
@syncretizm
An interactive, runnable TypeScript val by syncretizm
HTTP
export async function formulaEndpoint(req) {
// methods/functions include: add, subtract, multiply, mod, pow, divide, equal, =/=, >, <, >=, <=, and, or, not, xor, nand,
// DICTIONARY OF ALL FUNCTIONS, MAX NUMBER OF PARAMETERS, AND ACCEPTED TYPE
const functions = {
// CHECK IF METHOD EXISTS AGAINST FUNCTIONS DICTIONARY
if (functions[method] === undefined) {
function extractAndParseDate(dateString) {
// CREATE FUNCTIONS
function add(vars) {
function subtract(vars) {
janpaul123 avatar
valle_tmp_880820168898077728093213546584606
@janpaul123
// Initialize sample stories and store them in blob storage
HTTP
// Initialize sample stories and store them in blob storage
const SAMPLE_STORIES_KEY = "hn_sample_stories";
async function initializeSampleStories() {
const existingStories = await blob.getJSON(SAMPLE_STORIES_KEY);
if (!existingStories) {