Search
gistFetcher
@tgrecojs
An interactive, runnable TypeScript val by tgrecojs
Script
const getFileData = (fileName = "fileName.json") => ({ files }) => files[fileName];
const getContent = ({ content }) => content;
const getData = ({ data }) => data;
const mapper = fn => array => array.map(fn);
const getPubkeyAndAddresses = ({ pubkey = { key: "" }, address = "" }) => ({
address,
pubkey: {
key: pubkey.key,
const compose = (...fns) => (initialValue) => fns.reduceRight((acc, val) => val(acc), initialValue);
const getFileContents = (fileName = "") =>
tinygoHttp
@maxm
Class representing a BufferResult.
Script
/** Class representing a BufferResult. */
class BufferResult {
* @member {Uint8Array}
buffer: Uint8Array;
* @member {boolean}
isError = false;
* Create a Buffer Result.
* @param {Uint8Array} buffer - the payload.
* @param {boolean} isError - is the result an error
constructor(buffer: Uint8Array, isError: boolean) {
valle_tmp_7814561962855233872642258373586
@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");
valle_tmp_66391058371017956900111721083726
@janpaul123
// This val responds with "Hello, world!"
HTTP
// This val responds with "Hello, world!"
export default async function main(req: Request): Promise<Response> {
return new Response("Hello, world!");
valle_tmp_115772121902645334646172151872623
@janpaul123
* This val creates a simple hacker news clone with 30 fake sample stories.
* It uses blob storage to store story data, including the ability to submit
* new stories and upvote existing stories.
HTTP
* This val creates a simple hacker news clone with 30 fake sample stories.
* It uses blob storage to store story data, including the ability to submit
* new stories and upvote existing stories.
interface Story {
id: number;
title: string;
url: string;
points: number;
createdAt: string;
const DEFAULT_STORIES: Story[] = Array.from({ length: 30 }).map((_, idx) => ({
valTownBadgeMiddleware
@jxnblk
An interactive, runnable TypeScript val by jxnblk
Script
export default function badgeMiddleware(handler, url: string) {
return async function(req: Request): Promise<Response> {
if (req.method !== "GET") return await handler(req);
let res = await handler(req);
if (res.headers.get("Content-Type")?.includes("text/html")) {
let body = await res.text();
const badge = valTownBadge(url);
body += `<div style="position:fixed;right:0;bottom:0;margin:8px">${badge}</div>`;
res = new Response(body, res);
return res;
password_auth
@stevekrouse
Password Auth Middleware Protect your vals behind a password. Use session cookies to persist authentication. Demo See @pomdtr/password_auth_test Usage If you want to use an api token to authenticate: import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth";
export default passwordAuth(() => {
return new Response("OK");
}); Or if you prefer to use a string: import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth";
export default passwordAuth(() => {
return new Response("OK");
}, { password: Deno.env.get("MY_PASSWORD") }); Or if you want to share your val with someone without sharing your main password, you can set multiple ones import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth";
export default passwordAuth(() => {
return new Response("OK");
}, { password: [Deno.env.get("MY_PASSWORD"), Deno.env.get("STEVE_PASSWORD")] }); Note that authenticating using your api token is always an option. TODO [x] allow to authenticate using a val town token [ ] add a way to send an email to ask a password from the val owner [ ] automatically extend the session [ ] automatically remove expired sessions FAQ How to sign out ? Navigate to <your-site>/signout .
Script
# Password Auth Middleware
Protect your vals behind a password. Use session cookies to persist authentication.
![6ed0648ae8813e958dbe79468572cb52f578239c0fae55857a13660beebdc5fd.png](https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/36c1dc4f-4e19-457b-ad89-0bf139754e00/public)
## Demo
See @pomdtr/password_auth_test
## Usage
type Session = {
id: string;
expiresAt: number;
async function createSessionTable(tableName: string) {
agenta_webhook_eval
@mmabrouk
Example webhook evaluator (see docs in http://docs.agenta.ai/evaluation/evaluators/webhook-evaluator)
HTTP
Example webhook evaluator (see docs in http://docs.agenta.ai/evaluation/evaluators/webhook-evaluator)
export default async function server(request: Request): Promise<Response> {
// Parse the request body
let body: { inputs: Record<string, string>, output: string, correct_answer: string };
body = await request.json();
const score = body.output.toLowerCase() === body.correct_answer.toLowerCase() ? 1.0 : 0.0;
const responseBody = { score };
return new Response(JSON.stringify(responseBody), {
status: 200,
headers: { 'Content-Type': 'application/json' }
t
@tmcw
An interactive, runnable TypeScript val by tmcw
Script
export function t(tag: string, args: any = {}, children: any[] = []) {
const func = (...argsOrChildren: any) => {
if (Array.isArray(argsOrChildren[0]))
return func(...argsOrChildren[0], ...argsOrChildren.slice(1));
const args2 = { ...args },
ch2 = [...children];
for (const c of argsOrChildren) {
if (typeof c === "string") ch2.push(c);
else if (typeof c.html === "string") ch2.push(c.html);
else for (const k in c) args2[k] = c[k];
antonia_tim_burton
@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(" ");
const settings = {
bandcampWrappedScript
@donmccurdy
An interactive, runnable TypeScript val by donmccurdy
Script
const replacements = [
[/\*/g, "\\*"],
[/#/g, "\\#"],
[/\//g, "\\/"],
[/\(/g, "\\("],
[/\)/g, "\\)"],
[/\[/g, "\\["],
[/\]/g, "\\]"],
[/</g, "<"],
[/>/g, ">"],
compileCljsToES6
@liamdanielduffy
An interactive, runnable TypeScript val by liamdanielduffy
Script
import * as squint_core from "npm:squint-cljs/core.js";
globalThis.squint_core = squint_core;
export function compileCljsToES6(cljs: string) {
return compileString(cljs, { repl: true, "elide-exports": true }).replace(
"squint-cljs",
"npm:squint-cljs",
masterfulBronzeFlea
@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({
aqi
@cfab
An interactive, runnable TypeScript val by cfab
Cron
export let aqi = async () => {
let pm25 = (
await fetchJSON(
"https://api.openaq.org/v2/latest?" +
new URLSearchParams({
limit: "10",
page: "1",
location: "Geneva",
offset: "0",
sort: "desc",
living
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
HTTP
export async function living(req: Request) {
let name = decodeURI(new URL(req.url).pathname.replace("/", ""));
let alive, error;
try {
alive = await alive2(name);
catch (e) {
error = e;
return html(
`<body style="color: white; font-family: sans-serif; background: linear-gradient(to right, #fbc21d 0%, #f79622 30%, #ff6a00 60%, #ff2b04 100%)">
<div style="font-size:2em; padding:0.5em">