Search
generateGuestbookSnippet
@vtdocs
Generate Guestbook Snippet This val generates the HTML snippet for @vtdocs.guestbook . Using these two vals, you can put an interactive guestbook on any website. valUser and valName are used to build the Express API URL for your forked version of @vtdocs.guestbook .
Script
# Generate Guestbook Snippet
This val generates the HTML snippet for [`@vtdocs.guestbook`](https://www.val.town/v/vtdocs.guestbook).
Using these two vals, you can put an interactive guestbook on any website.
`valUser` and `valName` are used to build the Express API URL for your forked version of [`@vtdocs.guestbook`](https://www.val.town/v/vtdocs.guestbook).
export const generateGuestbookSnippet = (valUser: string, valName: string) => `
<form class="valtown-guestbook">
<div id="valtown-messages"></div>
<div><input id="valtown-name" placeholder="name" /></div>
<div><input id="valtown-message" placeholder="message"/></div>
<button id="valtown-submit" onclick="sendMessage()">Submit</button>
aloneAquaGopher
@parthstown
An interactive, runnable TypeScript val by parthstown
HTTP
console.log("potato", main);
export default async function printWeather(req: Request) {
if (typeof main === "function") {
const newWeather = await main(req);
const data = await newWeather.json();
console.log(newWeather);
return new Response(JSON.stringify(data));
} else {
console.error("main is not a function");
return new Response("Error: main is not a function", { status: 500 });
tonpick
@cyrilos
// handle incoming requests
Script
const DEFAULT_PROFIT = 0;
const DEFAULT_BETAMOUNT = 0.00001000;
const DEFAULT_MULTIPLIER = 1.2;
const DEFAULT_OPTION = "higher";
const DEFAULT_INCREASE = 0;
const DEFAULT_COOKIES =
"adbit_session=hs7vl4dc8scoh960t9kmn11g6s5tb8t6;csrf_cookie_name=4dfe584acca70f16d3c3dd934eebed1d;fp=BqPsqYfDkUINYrso";
const VAL_URL = "https://cyrilos-tonpick.web.val.run";
// handle incoming requests
export default async function(req) {
testSemantics
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export async function testSemantics({
stateName,
api,
stateName: string;
api: string;
const { data: last } = await fetchJSON(
`${api}/eval/${stateName}`
const now = Date.now();
await fetchJSON(`${api}/eval/${stateName} = ${now}`);
const { data: next } = await fetchJSON(
valle_tmp_109048913203484876323222261393799
@janpaul123
// Initialize sample stories and store them in blob storage
HTTP
const SAMPLE_STORIES_KEY = "hn_realistic_sample_stories";
// Initialize sample stories and store them in blob storage
async function initializeSampleStories() {
const existingStories = await blob.getJSON(SAMPLE_STORIES_KEY);
if (!existingStories) {
const sampleStories = Array.from({ length: 30 }).map((_, idx) => ({
id: idx + 1,
title: faker.company.catchPhrase(),
url: faker.internet.url(),
votes: Math.floor(Math.random() * 100),
ChibifyMaker
@jeffreyyoung
An interactive, runnable TypeScript val by jeffreyyoung
HTTP
const basePrompt = [
`Generate an image generation model prompt (description) for the previous image, in nightmare before christmas chibi 3D anime style.`,
`The objective is to try to replicate the image as closely as possible,`,
`but in the new style. To do that, you should be very detailed in including`,
`relevant information necessary to reproduce the image, e.g. colors, poses,`,
`facial expressions, background objects, etc. Ensure that the entire description `,
`is consistent with the nightmare before christmas chibi 3D anime style, especially`,
`the 'nightmare before christmas 3D' part. Output only the prompt and nothing else.`,
].join(" ");
export default serve({
chocolateMeerkat_public
@wannli
An interactive, runnable TypeScript val by wannli
Script
export async function chocolateMeerkat(req) {
const body = await req.json();
let firstLine = body.split("\n")[0]; // Extract the first line from the body
// Define a regular expression pattern to match names and links
const pattern = /- \[\[([^\^]+)\^([^\]]+)\]\]/g;
let match;
const namesToLinks = {};
// Build a map of names to their corresponding links
while ((match = pattern.exec(body)) !== null) {
namesToLinks[match[1].toLowerCase()] = match[2]; // Store lowercased names for case-insensitive matching
predict_cid_test
@stevedylandev
An interactive, runnable TypeScript val by stevedylandev
Script
export const predictCID = async (file: File, version: 0 | 1 = 1) => {
try {
const arrayBuffer = await file.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const blockstore = new MemoryBlockstore();
let rootCid: any;
for await (
const result of importer([{ content: buffer }], blockstore, {
cidVersion: version,
hashAlg: "sha2-256",
htmx_test_endpoint
@suhas
An interactive, runnable TypeScript val by suhas
Script
export const htmx_test_endpoint = async (
req: express.Request,
res: express.Response
console.email(req.body);
res.set("Content-Type", "text/html");
res.send("<h1>hi</h1>");
FunctionToHTMLForm
@rodrigotello
An interactive, runnable TypeScript val by rodrigotello
Script
import { multiplicationFunctionTest } from "https://esm.town/v/rodrigotello/multiplicationFunctionTest";
export async function FunctionToHTMLForm(
req: express.Request,
res: express.Response,
let myFunctionValAsHTML = multiplicationFunctionTest; // Insert your function here and it should generate an HTML form
return res.send(`${valForm(myFunctionValAsHTML)}`);
pingReplit
@dr0
An interactive, runnable TypeScript val by dr0
Cron
import { fetch } from "https://esm.town/v/std/fetch";
export async function pingReplit() {
fetch("https://lookup.icxk.top/imgs/36x36.png");
valle_tmp_5806599353127410960201698264815
@janpaul123
An interactive, runnable TypeScript val by janpaul123
HTTP
The error occurred because the input data sent to your Val was likely empty or not in a valid JSON format. To handle this error, you can add a check to ensure that the request contains valid JSON data before trying to extract the "code" property. Here's an updated version of your code that includes basic error handling to prevent this issue:
ts
export default async function(req: Request): Promise<Response> {
try {
// Ensure the request contains valid JSON data
const requestData = await req.json();
const code = requestData.code || "";
// Format the JavaScript code using Prettier
const formattedCode = format(code, {
parser: "babel",
PGliteOld
@samwillis
PGlite on Val Town - A whole Postgres in your val All you need to do is first import the Deno xmlhttprequest polyfill and then PGlite: import "https://deno.land/x/xhr@0.1.0/mod.ts";
import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist/index.js"; Importing using esm.sh doesn't seem to work, see https://github.com/electric-sql/pglite/issues/110
HTTP
PGlite on Val Town - A whole Postgres in your val
All you need to do is first import the Deno xmlhttprequest polyfill and then PGlite:
```js
Importing using esm.sh doesn't seem to work, see https://github.com/electric-sql/pglite/issues/110
const pg = new PGlite();
let init = (async () => {
await pg.query(`
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
test TEXT
valle_tmp_66885881021009121244024526935712
@janpaul123
// This val responds with "Hello world" on every HTTP request
HTTP
// This val responds with "Hello world" on every HTTP request
export default async function(req: Request): Promise<Response> {
return new Response("Hello world");
maroonBadger
@masd1
// Cheerio accepts a CSS selector, here we pick the second <p>
Script
import { html, load } from "npm:cheerio";
const htmlStr = await fetchText(
"https://archive.is/pPFRB",
const $ = load(htmlStr);
// Cheerio accepts a CSS selector, here we pick the second <p>
const intro = $.html();
console.log(intro);