Search
valCoinApi
@aggy
I have no idea how crypto really works, this is just a guess
HTTP
I have no idea how crypto really works, this is just a guess
const app = new Hono();
app.use("/*", cors());
const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
const { v4: uuidv4 } = await import("https://esm.sh/uuid");
const SCHEMA_VERSION = 1;
const KEY = new URL(import.meta.url).pathname.split("/").at(-1);
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS ${KEY}_valcoin_${SCHEMA_VERSION} (
hash TEXT PRIMARY KEY,
silverSwallow
@tempguy
An interactive, runnable TypeScript val by tempguy
Cron
import { blob } from "https://esm.town/v/std/blob?v=12";
export default async function(interval: Interval) {
await fetch("https://tempguy-scarletsole.web.val.run/refresh");
const date = new Date();
await blob.setJSON("turnstileCron", { ptime: date.getTime(), ntime: interval.delay + interval.lastRunAt.getTime() });
renderFormAndSaveData
@pauliusef
An interactive, runnable TypeScript val by pauliusef
HTTP
interface Data {
email: string;
product: {
id: string;
url?: string;
handle?: string;
title?: string;
export const renderFormAndSaveData = async (req: Request) => {
// A visit from a web browser? Serve a HTML page with a form
if (req.method === "GET") {
valle_tmp_059037444149131925961380987213611
@janpaul123
// This val will respond with "Hello, World!" to all incoming HTTP requests.
HTTP
// This val will respond with "Hello, World!" to all incoming HTTP requests.
export default async function main(req: Request): Promise<Response> {
return new Response("Hello, World!", { headers: { "Content-Type": "text/plain" } });
celinewaitlist
@mbo
* This Val creates a simple API endpoint that saves an email address for notifications
* using Val Town's JSON storage. It handles POST requests to save the submitted email
* and returns a simple confirmation message.
HTTP
* This Val creates a simple API endpoint that saves an email address for notifications
* using Val Town's JSON storage. It handles POST requests to save the submitted email
* and returns a simple confirmation message.
async function server(request: Request): Promise<Response> {
const { blob } = await import("https://esm.town/v/std/blob");
const KEY = new URL(import.meta.url).pathname.split("/").at(-1);
console.log(await blob.getJSON(`${KEY}_subscribers`));
if (request.method === "POST") {
const formData = await request.formData();
const email = formData.get("email");
syntheticLoot
@jamiedubs
dark greetings cryptoadventurers. This val will print the contents of a given Ethereum wallet's Synthetic Loot , which is procedurally generated from your wallet address. To look at your sLoot in a browser with some fun pixel art, check out timshel's Synthetic Loot Viewer to use this endpoint, pass ?address=0x... e.g. https://jamiedubs-syntheticloot.web.val.run/?account=0xf296178d553c8ec21a2fbd2c5dda8ca9ac905a00 the default response type is JSON. You can also get a simple list of the loot bag contents using ?format=text . e.g. https://jamiedubs-syntheticloot.web.val.run/?account=0xf296178d553c8ec21a2fbd2c5dda8ca9ac905a00&format=text
HTTP
dark greetings cryptoadventurers. This val will print the contents of a given Ethereum wallet's [Synthetic Loot](https://www.lootproject.com/synthloot), which is procedurally generated from your wallet address. To look at your sLoot in a browser with some fun pixel art, check out timshel's [Synthetic Loot Viewer](https://timshelxyz.github.io/synthetic-loot-viewer/#/account/0xf296178d553c8ec21a2fbd2c5dda8ca9ac905a00)
to use this endpoint, pass `?address=0x...` e.g. https://jamiedubs-syntheticloot.web.val.run/?account=0xf296178d553c8ec21a2fbd2c5dda8ca9ac905a00
the default response type is JSON. You can also get a simple list of the loot bag contents using `?format=text`. e.g. https://jamiedubs-syntheticloot.web.val.run/?account=0xf296178d553c8ec21a2fbd2c5dda8ca9ac905a00&format=text
// I <3 ether.actor, very convenient for fetching on-chain data
// it's a little slow - Alchemy or another RPC/API provider would be faster
const url = `https://ether.actor/0x869ad3dfb0f9acb9094ba85228008981be6dbdde/tokenURI`;
// example data:
// const account = "0xf296178d553c8ec21a2fbd2c5dda8ca9ac905a00";
// const svg = `<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 350 350"><style>.base { fill: white; font-family: serif; font-size: 14px; }</style><rect width="100%" height="100%" fill="black" /><text x="10" y="20" class="base">Grave Wand</text><text x="10" y="40" class="base">Ornate Chestplate</text><text x="10" y="60" class="base">Dragon's Crown of Protection</text><text x="10" y="80" class="base">War Belt</text><text x="10" y="100" class="base">"Fate Sun" Divine Slippers of Power</text><text x="10" y="120" class="base">Silk Gloves</text><text x="10" y="140" class="base">Necklace</text><text x="10" y="160" class="base">Bronze Ring</text></svg>`;
async function fetchAndParseSvgFromJson(account: string) {
codeOnValTown
@vladimyr
Code on Val Town Adds a "Code on Val Town" ribbon to your page. This lets your website visitors navigate to the code behind it. This uses github-fork-ribbon-css under the hood. Usage Here are 2 different ways to add the "Code on Val Town" ribbon: 1. Wrap your fetch handler (recommended) import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=45";
import { html } from "https://esm.town/v/stevekrouse/html?v=5";
export default modifyFetchHandler(async (req: Request): Promise<Response> => {
return html(`<h2>Hello world!</h2>`);
}); Example: @andreterron/openable_handler 2. Wrap your HTML string import { modifyHtmlString } from "https://esm.town/v/andreterron/codeOnValTown?v=45";
import { html } from "https://esm.town/v/stevekrouse/html?v=5";
export default async (req: Request): Promise<Response> => {
return html(modifyHtmlString(`<h2>Hello world!</h2>`));
}; Example: @andreterron/openable_html Other ways We made sure this was very modular, so you can also add the ribbon using these methods: Get the element string directly: @andreterron/codeOnVT_ribbonElement Modify an HTTP Response: @andreterron/codeOnVT_modifyResponse Use .pipeThrough to append to a stream: @andreterron/InjectCodeOnValTownStream Customization Linking to the val These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the val argument: modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }}) modifyHtmlString("<html>...", {val: { handle: "andre", name: "foo" }}) Styling You can set the style parameter to a css string to customize the ribbon. Check out github-fork-ribbon-css to learn more about how to style the element. modifyFetchHandler(handler, {style: ".github-fork-ribbon:before { background-color: #333; }"}) modifyHtmlString("<html>...", {style: ".github-fork-ribbon:before { background-color: #333; }"}) Here's how you can hide the ribbon on small screens: modifyFetchHandler(handler, {style: `@media (max-width: 768px) {
.github-fork-ribbon {
display: none !important;
}
}`}) To-dos [ ] Let users customize the ribbon. Some ideas are the text, color or placement.
Script
# Code on Val Town
![Screenshot 2024-02-27 at 1.25.46 PM.png](https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/6b67bb0a-d80f-4f3d-5b17-57b5378b3e00/public)
Adds a "Code on Val Town" ribbon to your page. This lets your website visitors navigate to the code behind it.
This uses [github-fork-ribbon-css](https://github.com/simonwhitaker/github-fork-ribbon-css) under the hood.
## Usage
Here are 2 different ways to add the "Code on Val Town" ribbon:
* @param bodyText HTML string that will be used to inject the element.
* @param val Define which val should open. Defaults to the root reference.
export function modifyHtmlString(
bodyText: string,
remarkHtmlTest
@stevekrouse
// Forked from @nbbaier.remarkHtmlTest
Script
export const remarkHtmlTest = (async () => {
const { unified } = await import(
"https://cdn.jsdelivr.net/npm/unified@10/+esm"
const { default: remarkParse } = await import("npm:remark-parse");
const { default: remarkHTML } = await import("npm:remark-html");
const output = await unified()
.use(remarkParse)
.use(remarkHTML)
.process("# Hello World")
.then((file) => console.log(String(file)));
hackerNewsRAG
@paulhoule
Find comments on HN (powered by Algolia ), extract content and return a streaming markdown summary (powered by Substrate ). The RAG portion of this is 34 lines of Substrate code. Twitter thread walkthrough: https://x.com/vprtwn/status/1812844236401762513 🪩 To fork, sign up for Substrate to get your own API key and $50 free credits.
HTTP
Find comments on HN (powered by [Algolia](https://hn.algolia.com/api)), extract content and return a streaming markdown summary (powered by [Substrate](https://substrate.run)).
The RAG portion of this is 34 lines of Substrate code. Twitter thread walkthrough: https://x.com/vprtwn/status/1812844236401762513
🪩 To fork, [sign up for Substrate](https://substrate.run/signin) to get your own API key and $50 free credits.
const substrate = new Substrate({ apiKey: Deno.env.get("SUBSTRATE_API_KEY") });
// search for HN comments using https://hn.algolia.com/api
const query = "rust";
const searchResults = await hnSearch({
query: query,
numericFilters: `created_at_i>${Math.floor(Date.now() / 1000) - 60 * 60 * 24 * 7 * 4}`,
tags: "comment",
dispatch
@beneskildsen
An interactive, runnable TypeScript val by beneskildsen
Script
import { getItem } from "https://esm.town/v/beneskildsen/getItem";
export const dispatch = async (action, reducer, stateNamespace) => {
const state = getItem(stateNamespace);
const nextState = reducer(state, action);
await setItem(stateNamespace, nextState);
return nextState;
CVE
@curtcox
An interactive, runnable TypeScript val by curtcox
HTTP
import { chatio } from "https://esm.town/v/curtcox/_cve";
export const Chatio = (req: Request) => {
return chatio(req);
feeds
@elan
Bluesky feed generator
HTTP
Bluesky feed generator
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
const path = url.pathname;
if (path === "/") {
return new Response(
`<!DOCTYPE html><html><head><style>:root {color-scheme: light dark;}body {font-family: Arial, sans-serif;}</style><meta name="viewport" content="width=device-width, initial-scale=1" /></head>
<body><h1>Bluesky Feed: Posts Without 'E'</h1>
<p>This feed includes all Bluesky posts that do not contain the letter 'E'.</p>
<ul>
moccasinMoose
@yusukebe
An interactive, runnable TypeScript val by yusukebe
HTTP
import { Hono } from "npm:hono@4";
const app = new Hono();
app.get("/", (c) => c.text("Hello Val!"));
export default app.fetch;
consoleEmailEx
@suncin
An interactive, runnable TypeScript val by suncin
Script
export let consoleEmailEx = (() => {
console.email({ html: "<b>hi!</b>", subject: "Subject accepted here too" });
examplebot_endpoint
@stevekrouse
// Forked from @malloc.examplebot_endpoint
Script
export let examplebot_endpoint = (
req: express.Request,
res: express.Response,
console.log(res);
if (!req.get("X-Signature-Timestamp") || !req.get("X-Signature-Ed25519")) {
res.status(400);
res.end("Signature headers missing");
verify_discord_signature(
process.env.discord_pubkey,
JSON.stringify(req.body),