Search

Results include substring matches and semantically similar vals. Learn more
vladimyr avatar
fetchTweet
@vladimyr
// @see: https://github.com/vercel/react-tweet/blob/a292ca7/packages/react-tweet/src/api/fetch-tweet.ts#L27-L31
Script
import { fetch } from "https://esm.town/v/std/fetch";
export async function fetchTweet(url) {
const tweetId = url.match(/(\d{19})/)[1];
const token = getToken(tweetId);
return tweetData;
// @see: https://github.com/vercel/react-tweet/blob/a292ca7/packages/react-tweet/src/api/fetch-tweet.ts#L27-L31
function getToken(id: string) {
return ((Number(id) / 1e15) * Math.PI)
.toString(6 ** 2)
Pushpam avatar
responsiveMagentaBear
@Pushpam
@jsxImportSource https://esm.sh/react@18.2.0
Script
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
function RunningGame() {
const [targetDistance, setTargetDistance] = useState(Math.floor(Math.random() * 5) + 1); // 1-5 km
</div>
function client() {
createRoot(document.getElementById("root")).render(<RunningGame />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
return new Response(`
lolocoo avatar
getText
@lolocoo
An interactive, runnable TypeScript val by lolocoo
Script
export async function getText(data) {
console.log("hello");
return data;
movienerd avatar
AIMovie
@movienerd
* This program creates a movie recommendation system based on moods. * It uses OpenAI to generate movie recommendations based on the user's selected mood and feedback. * The program uses React for the frontend and handles state management for user interactions. * It uses the Val Town OpenAI proxy for backend API calls. * Movies are saved in SQLite to prevent recommending the same movie twice. * The SQLite schema version has been updated to fix the 404 error. * A dancing popcorn emoji has been added to the loading message. * The color scheme has been updated to a monochrome look with a modern style and a nice font. * The "More moods" button text has been changed to "Ask the AI for different moods". * The mood generation now keeps track of previously generated moods to avoid repetition. * A list of movies that have been liked, disliked, or not seen is displayed at the bottom of the page. * The JSON parsing has been made more robust to handle non-standard responses.
HTTP
* It uses OpenAI to generate movie recommendations based on the user's selected mood and feedback.
* It uses the Val Town OpenAI proxy for backend API calls.
function App() {
function getMoodEmoji(mood: Mood): string {
function client() {
async function server(request: Request): Promise<Response> {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
const { OpenAI } = await import("https://esm.town/v/std/openai");
webup avatar
memorySampleVector
@webup
An interactive, runnable TypeScript val by webup
Script
const builder = await getMemoryBuilder({
type: "vector",
provider: "openai",
const memory = await builder();
await memory.saveContext({ input: "My favorite sport is soccer" }, {
dhvanil avatar
val_jjllaXPKSh
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export default async function handler(req) {
try {
const result = await (async () => {
janpaul123 avatar
valle_tmp_242381480528420354693635284265856
@janpaul123
// This HTTP val responds with "Hello, world!" in JSON format.
HTTP
// It leverages the Web API which provides Request and Response objects.
// No external libraries or other dependencies are necessary.
export default async function(req: Request): Promise<Response> {
// Return a simple JSON response
return Response.json({ message: "Hello, world!" });
stevekrouse avatar
braintrust_tool_test
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
HTTP
case "divide":
return a / b;
export default async function server(req: Request) {
const rawInput = await req.json();
const parsedInput = zInput.parse(rawInput);
nerdymomocat avatar
add_to_notion_from_todoist
@nerdymomocat
Use todoist for quick notes to add to notion. Uses project to decide which project to fetch to add stuff to notion. Can add to page or database based on config below. Demarkation using sections in the todoist project. Extracts date for page blocks that are added as callouts.
Cron
"notion-id": "DB_ID_HERE",
function getNotionId(section_id) {
if (!section_id) {
return [todoist_dict_mapping["dump"]["notion-map-type"], todoist_dict_mapping["dump"]["notion-id"]];
function convertDateObject(due) {
function convertToISOWithOffset(datetimeStr, timezoneStr) {
const date = new Date(datetimeStr);
: (due && due.datetime && due.timezone ? due.timezone : "America/Los_Angeles"),
async function addCalloutToNotionPage(page_id, content, date) {
console.log(JSON.stringify(date));
console.log(JSON.stringify(response));
async function addPageToNotionDatabse(database_id, content) {
const response = await notion.pages.create({
"content": content,
export default async function(interval: Interval) {
var tasks = await todoistapi.getTasks({
richardkaplan avatar
webscrapeWikipediaIntro
@richardkaplan
An interactive, runnable TypeScript val by richardkaplan
Script
const cheerio = await import("npm:cheerio");
const html = await fetchText(
"https://en.wikipedia.org/wiki/OpenAI",
const $ = cheerio.load(html);
// Cheerio accepts a CSS selector, here we pick the second <p>
janpaul123 avatar
valle_tmp_4630203169811349044369672658961
@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 main(req: Request): Promise<Response> {
return new Response("Hello, World!", { headers: { "Content-Type": "text/plain" } });
rozek avatar
UserSpecificResource_Test
@rozek
This val contains a few tests for the UserSpecificResource val
HTTP
allowedString, expectString, ValueIsNonEmptyString
} from "https://rozek.github.io/javascript-interface-library/dist/javascript-interface-library.esm.js"
export default async function testUserSpecificVal (request:Request):Promise<Response> {
const ValURL = 'https://rozek-userspecificresource.web.val.run'
const validToken = allowedString('valid token',Deno.env.get('UserSpecificResource'))
mattx avatar
verify_discord_signature
@mattx
verify_discord_signature Verify HTTP signatures coming from Discord. public_key should be the Ed25519 public key from Discord, as a hex string body should be the request body as a string. If you have a JSON object as the request body, use JSON.stringify. signature should be the X-Signature-Ed25519 header timestamp should be the X-Signature-Timestamp header You must return a 401 error and return early if this function returns false, otherwise you will pretty quickly get a big scary warning from Discord that your endpoint has been removed. Note that you'll only be able to add one once you've integrated this correctly. As this function only deals with strings, it doesn't matter whether you use an Express or web endpoint.
Script
- timestamp should be the X-Signature-Timestamp header
You **must** return a 401 error and return early if this function returns false, otherwise you will pretty quickly get a big
As this function only deals with strings, it doesn't matter whether you use an Express or web endpoint.
postpostscript avatar
fetchWorker
@postpostscript
fetchWorker: communicate with a worker over a fetch -like interface! Example: import { fetchWorker } from "https://esm.town/v/postpostscript/fetchWorker"; using worker = await fetchWorker({ url: "https://esm.town/v/postpostscript/fetchWorkerExample", handler: "handler", }); const res = await worker.fetch("/", { method: "POST", body: JSON.stringify({ test: 1, }), headers: { "Content-Type": "application/json", }, }); console.log(await res.json()); // { // method: "POST", // url: "https://7ae81ab0-04cf-485a-ae09-054c4d3be6b3.val.town/", // text: { test: 1 }, // headers: { "content-type": "application/json" } // } Full Example Options: url ( string , required): URL that the worker will fetch the handler from handler ( string , defaults to default ): name of export that will execute the request
Script
export const workerURL = new URL(import.meta.url);
workerURL.searchParams.set("worker", "1");
export async function fetchWorker(opts: {
url: string;
handler?: string;
terminate: () => worker.terminate(),
[Symbol.dispose]: () => worker.terminate(),
export function setupWorker() {
let handler: (req: Request) => Promise<Response>;
self.onmessage = async (e) => {
daisuke avatar
renderHTMLWithHono
@daisuke
An interactive, runnable TypeScript val by daisuke
HTTP
</body>
</html>
export default async function(req: Request): Promise<Response> {
return app.fetch(req);