Search
serverlessMatrixEchoBot2
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export async function serverlessMatrixEchoBot2(req, res) {
console.log(req.path);
res.send("<h1>working!</h1>");
valle_tmp_543915460990811923753769386621215
@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_realistic_sample_stories";
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),
trpcRouter
@andreterron2
An interactive, runnable TypeScript val by andreterron2
Script
export const trpcRouter = await import("npm:@trpc/server");
is_ipaddr_in_Iceland
@zarutian
IS: Athugar hvort gefin iptala rátast inn til Íslands eður ei.
Notar CIDR listana frá Reykjavík Internet eXchange. EN: Checks if a given ip address routes to Iceland or not.
Uses the CIDR lists from Reykjavík Internet eXchange.
Script
IS: Athugar hvort gefin iptala rátast inn til Íslands eður ei.
Notar CIDR listana frá Reykjavík Internet eXchange.
EN: Checks if a given ip address routes to Iceland or not.
Uses the CIDR lists from Reykjavík Internet eXchange.
// original val name: vicariousLavenderDeer
const ipv4_nets_url = "https://rix.is/is-net.txt";
const ipv6_nets_url = "https://rix.is/is-net6.txt";
export const is_ipaddr_in_Iceland = async (iptala) => {
if ((typeof iptala) == "string") {
if (!ipaddr.isValid(iptala)) {
browserlessPuppeteerExample
@vtdocs
An interactive, runnable TypeScript val by vtdocs
Script
export const browserlessPuppeteerExample = (async () => {
const { PuppeteerDeno } = await import(
"https://deno.land/x/puppeteer@16.2.0/src/deno/Puppeteer.ts"
const puppeteer = new PuppeteerDeno({
productName: "chrome",
const browser = await puppeteer.connect({
browserWSEndpoint:
`wss://chrome.browserless.io?token=${process.env.browserlessKey}`,
const page = await browser.newPage();
await page.goto("https://en.wikipedia.org/wiki/OpenAI");
val_aBl2zIzBr7
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_aBl2zIzBr7(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
const findPrimes = (max) => {
const primes = [];
for (let num = 2; num < max; num++) {
let isPrime = true;
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
fetsServerExample
@maxm
An interactive, runnable TypeScript val by maxm
HTTP
export const router = createRouter().route({
method: "GET",
path: "/",
schemas: {
responses: {
200: {
type: "object",
properties: {
message: {
type: "string",
sseDemoCountdown
@maxm
Server-Sent Events Demo
HTTP
# Server-Sent Events Demo
export default async function(req: Request): Promise<Response> {
let count = 10;
const body = new ReadableStream({
start(controller) {
const intervalId = setInterval(() => {
if (count > 0) {
const msg = new TextEncoder().encode(`data: ${count}\r\n\r\n`);
controller.enqueue(msg);
count--;
webhookHandler
@metart43
An interactive, runnable TypeScript val by metart43
Script
export async function webhookHandler(req: express.Request, res: express.Response) {
let page;
const ftRSSFeedRes = await fetchRSS(
"https://www.ft.com/news-feed?format=rss",
const rssFeedItems = ftRSSFeedRes?.channel?.item;
const channel = ftRSSFeedRes?.channel;
if (rssFeedItems) {
page = generateHTMLFromRSS({
rssFeedItems,
categoryLink: channel.link,
oakExample
@vladimyr
An interactive, runnable TypeScript val by vladimyr
HTTP
const router = new Router();
router
.get("/", (ctx) => {
ctx.response.body = "Hello world!";
.get("/cat", (ctx) => {
ctx.response.body = { name: "cat" };
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
export default denoServer(app.fetch);
writeMessage
@jdan
An interactive, runnable TypeScript val by jdan
Express (deprecated)
export const writeMessage = async (req: express.Request, res: express.Response) => {
const name = req.body.name.slice(0, 100);
const message = req.body.message.slice(0, 500);
messages.push({
name,
message,
approved: false,
await set("messages", messages);
await email({
text:
valWall
@iamseeley
Inspired by https://www.val.town/v/ejfox/valcontributionchart
HTTP
Inspired by https://www.val.town/v/ejfox/valcontributionchart
/** @jsxImportSource npm:hono@3/jsx */
const app = new Hono();
app.get("/", (c) => c.html(
<div>
<h1>Val Town Contribution Graph</h1>
<form action="/graph" method="get">
<label for="username">Enter a username: </label>
<input type="text" id="username" name="username" required />
<button type="submit">Generate Graph</button>
val_irc8Igm1CR
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_irc8Igm1CR(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
const findPrimes = (max) => {
const primes = [];
for (let num = 2; num < max; num++) {
let isPrime = true;
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
compress_image_demo
@stevekrouse
@jsxImportSource npm:hono@3/jsx
HTTP
/** @jsxImportSource npm:hono@3/jsx */
const app = new Hono();
app.get("/", (c) =>
c.html(
<form action="/" method="post" enctype="multipart/form-data">
<input type="file" accept="image/*" name="file">Upload photo</input>
<button type="submit">Submit</button>
</form>,
app.post("/", async (c) => {
const formData = await c.req.formData();
fastCoffeeLizard
@mvmattgray
An interactive, runnable TypeScript val by mvmattgray
HTTP
export default async (request) => {
const secret = "cfbd87a697526bf25127f998fe6388684b80524be46062a1a79d6dd26b5a6b90";
async function verifySignature(bodyText, receivedSignature) {
const encoder = new TextEncoder();
const keyData = encoder.encode(secret);
const data = encoder.encode(bodyText);
const cryptoKey = await crypto.subtle.importKey(
"raw",
keyData,
{ name: "HMAC", hash: "SHA-256" },