Search

Results include substring matches and semantically similar vals. Learn more
tmcw avatar
cachedResponseExample
@tmcw
An interactive, runnable TypeScript val by tmcw
Script
export const cachedResponseExample = () => {
return new Response(Date.now(), {
headers: {
"Cache-Control": "public, immutable, max-age=64800",
stevekrouse avatar
similarSites
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
const exaSecret = Deno.env.get("EXA_API_KEY");
const exa = new Exa(exaSecret);
const similarSites = async function(url: string) {
const results = await exa.findSimilar(url);
if (results.results) {
let elements = results.results.map((el) => {
return {
"score": el.score,
"url": el.url,
elements.sort((a, b) => b.score - a.score);
byjp avatar
addShortlink
@byjp
Shortlinks for the decentralised web This is a script to allow API-based updating of the shortlinks/redirects in an IPFS-based shortlink repo (using val.town). I've written up how all this works on my blog at https://byjp.me/posts/link-shortener
Express (deprecated)
# Shortlinks for the decentralised web
This is a script to allow API-based updating of the shortlinks/redirects in an IPFS-based shortlink repo (using val.town). I'
export const addShortlink = async (
req: express.Request,
res: express.Response,
const { to } = req.query;
const shortlink = req.path;
if (!/^Bearer github_pat_/.test(req.get("Authorization"))) {
res.status(401).send("Github PAT authentication required");
return;
coofdy avatar
streamThesaphistRSS
@coofdy
An interactive, runnable TypeScript val by coofdy
Script
import { internalStreamThesephistComRSS } from "https://esm.town/v/coofdy/internalStreamThesephistComRSS";
export let streamThesaphistRSS = async (req, res) => {
res.set("Content-type", "application/rss+xml");
res.set("Cache-Control", "max-age=14400");
res.send(await internalStreamThesephistComRSS);
andreterron avatar
tidbytCheck
@andreterron
An interactive, runnable TypeScript val by andreterron
Script
export async function tidbytCheck({ size = 7, bg = 0x047857ff, check = 0xffffffff }: {
size?: number;
bg?: number;
check?: number;
const img = await tidbytCircle({
size,
fill: 0x14532dc0,
border: 0x047857ff,
const center = Math.floor(size / 2);
img.setPixelColor(check, center - 1, center);
janpaul123 avatar
valle_tmp_0112503842756113147839156482696499
@janpaul123
// This val retrieves the weather in Brooklyn, NY using the MetaWeather API
HTTP
// This val retrieves the weather in Brooklyn, NY using the MetaWeather API
export default async function main(req: Request): Promise<Response> {
const response = await fetch("https://www.metaweather.com/api/location/2459115/");
const weatherData = await response.json();
return new Response(JSON.stringify(weatherData), {
headers: { "Content-Type": "application/json" },
neverstew avatar
slackReplyToMessage
@neverstew
An interactive, runnable TypeScript val by neverstew
Script
export const slackReplyToMessage = async (req: Request) => {
const body = await req.json();
// Verify the request is genuine
if (body.token !== process.env.slackVerificationToken) {
return new Response(undefined, { status: 401 });
// Respond to the initial challenge (when events are enabled)
if (body.challenge) {
return Response.json({ challenge: body.challenge });
// Reply to app_mention events
if (body.event.type === "app_mention") {
all avatar
excalidrawPass
@all
Excalidraw Document with Authentication User Signup or just password. original excalidraw code import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo?v=29"; import { blob } from "https://esm.town/v/std/blob?v=12"; import { createExcalidraw } from "https://jsr.io/@smallweb/excalidraw/0.3.0/mod.ts"; import { join } from "jsr:@std/path@0.225.2"; const { name } = extractValInfo(import.meta.url); export default createExcalidraw({ store: { get: async (key) => { try { const res = await blob.get(join(name, key)); return new Uint8Array(await res.arrayBuffer()); } catch (e) { return null; } }, set: (key, value) => { return blob.set(join(name, key), value); }, }, });
HTTP
# Excalidraw Document with Authentication
User Signup or just password.
original excalidraw code
const { name } = extractValInfo(import.meta.url);
export default createExcalidraw({
store: {
// This approach adds Lucia authentication with signup to the existing Excalidraw implementation.
// We'll use the luciaMiddleware to handle authentication and redirect unauthenticated users.
// The Excalidraw functionality will only be accessible to authenticated users.
const { name } = extractValInfo(import.meta.url);
xiyouMc avatar
getValTownResp
@xiyouMc
An interactive, runnable TypeScript val by xiyouMc
Script
import { getValTown } from "https://esm.town/v/xiyouMc/getValTown";
export let getValTownResp = (async () => {
const s = getValTown;
console.log("aaa", s);
yuval_dikerman avatar
gpt3
@yuval_dikerman
An interactive, runnable TypeScript val by yuval_dikerman
HTTP
export let gpt3 = async (prompt: string, openAiApiKey: string): Promise<string> => {
if (!prompt || !openAiApiKey) {
let cat = await fetch("https://catfact.ninja/fact");
let { fact } = await cat.json();
return Promise.reject(
`Prompt text or api key was not provided. \n \n here's a cat fact: \n ${fact}`,
const content = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
body: JSON.stringify({
model: "gpt-3.5-turbo",
easrng avatar
moduleFetch
@easrng
An interactive, runnable TypeScript val by easrng
Script
let cache: [string, AuthTokens] | undefined;
export function moduleFetch(input: RequestInfo | URL, init?: RequestInit | undefined): Promise<Response> {
const req = new Request(input, init);
let authTokens = Deno.env.get("DENO_AUTH_TOKENS");
let valTownToken = Deno.env.get("valtown");
if (typeof authTokens === "undefined" && typeof valTownToken === "string") {
authTokens = `${valTownToken}@esm.town`;
if (typeof authTokens !== "undefined") {
const parsedAuthTokens = (cache && (cache[0] === authTokens))
? cache[1]
vladimyr avatar
gfm
@vladimyr
Markdown to html (with github styling)
Script
# Markdown to html (with github styling)
export async function html(markdown: string) {
const [
{ micromark },
{ frontmatter, frontmatterHtml },
{ gfm: gfmMarkdown, gfmHtml },
] = await Promise.all([
import("npm:micromark"),
import("npm:micromark-extension-frontmatter"),
import("npm:micromark-extension-gfm"),
byzantine_emperor avatar
harryPotterData
@byzantine_emperor
// when a request comes in fetch hpotter data
Script
import { fetch } from "https://esm.town/v/std/fetch";
// when a request comes in fetch hpotter data
export async function harryPotterData(req: express.Request, res) {
try {
const responseData = await fetch(
"https://hp-api.onrender.com/api/characters",
const data = await responseData.json();
res.json(data);
catch (e) {
res.status(500).send("Internal Server Error");
camajudson avatar
handleDiscordInteraction
@camajudson
Bot for Cama discord server. To initialize new slash commands, you have to run a separate bit of code. This is for modifying their functionality
HTTP
Bot for Cama discord server. To initialize new slash commands, you have to run a separate bit of code. This is for modifying
export const handleDiscordInteraction = async (req: Request) => {
// Bump version
let bank = await blob.getJSON("bank");
let bets = await blob.getJSON("bets");
const starting_amount = 5;
if (!bank) {
bank = {};
await blob.setJSON("bank", bank);
if (!bets) {
z233 avatar
bebopBotWebhook
@z233
An interactive, runnable TypeScript val by z233
Script
export async function bebopBotWebhook(
req: express.Request,
res: express.Response
const requestSecretToken =
req?.options?.headers?.["x-telegram-bot-api-secret-token"];
if (requestSecretToken !== bebopBotSecretToken) {
res.status(403).send("Access denied");
return;
const { channel_post: channelPost } = req.body;
if (!channelPost) {