Search
valle_tmp_6558189023937331447348397779094
@janpaul123
// Serve main page with stories
HTTP
const SAMPLE_STORIES_KEY = "hn_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.lorem.sentence(),
url: faker.internet.url(),
votes: faker.datatype.number({ min: 0, max: 100 }),
await blob.setJSON(SAMPLE_STORIES_KEY, sampleStories);
cloudmailin
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export function cloudmailin(req, res) {}
inventiveAmethystSheep
@temptemp
An interactive, runnable TypeScript val by temptemp
HTTP
export default async function(req: Request): Promise<Response> {
// Define your .ts file URLs
const urls = [
"https://dss.ecapsorea.click/_v7/06c68ba4c20fbb03a8604f05ff6d95cb3ed20ab3e6e1f8be013ab2af4264514fdb2c14d2cac00a00be34927fe274bf5b0bada84ba611ee6d0e90285ecd73107e0d53aecc406a34131d28e6ccaa843170b46299ff512d62ca13ca286bd805ba6c1aca1c0eec76aee761c56fc3aa6b10d36d74c4fb0d887c8e97b8ec405d0340e2/seg-627-f3-v1-a1.html",
"https://dss.ecapsorea.click/_v7/06c68ba4c20fbb03a8604f05ff6d95cb3ed20ab3e6e1f8be013ab2af4264514fdb2c14d2cac00a00be34927fe274bf5b0bada84ba611ee6d0e90285ecd73107e0d53aecc406a34131d28e6ccaa843170b46299ff512d62ca13ca286bd805ba6c1aca1c0eec76aee761c56fc3aa6b10d36d74c4fb0d887c8e97b8ec405d0340e2/seg-628-f3-v1-a1.js",
const concatenateFiles = async () => {
const dataChunks: Uint8Array[] = [];
for (const url of urls) {
const response = await fetch(url);
if (!response.ok) {
dataDemo
@jamiedubs
// hello i am a simple demo of using GET/POST + Content-Type header to handle things differently
HTTP
// hello i am a simple demo of using GET/POST + Content-Type header to handle things differently
// I'm also gonna show VALTOWN BLOBS:
// import { blob } from "https://esm.town/v/std/blob?v=10";
// await blob.setJSON(key, newData);
// const data = await blob.getJSON(key);
export const dataDemo = async (req: Request) => {
if (req.method == "GET") {
return Response.json({ ok: true });
} else if (req.method == "POST") {
const contentType = req.headers.get("Content-Type");
valle_tmp_493882739904999215894176448564479
@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_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: `Sample Story ${idx + 1}`,
url: `https://example.com/story${idx + 1}`,
votes: Math.floor(Math.random() * 100),
cooingAzureRhinoceros
@maxm
An interactive, runnable TypeScript val by maxm
Script
let pg;
self.onmessage = (evt) => {
console.log(evt.data);
pg = await PGlite.create();
console.log(2);
self.postMessage("started");
console.log(3);
await pg.query(`
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
json_viewer
@vladimyr
Inspector to browser json data in HTTP vals Live example: https://stevekrouse-weatherdescription.web.val.run/ Installation import { fetch } from "https://esm.town/v/std/fetch";
import { json_viewer } from "https://esm.town/v/stevekrouse/json_viewer";
export const weatherDescription = async (params: string[]): Promise<unknown> => {
let data = await fetch(`https://wttr.in/${params["city"]}?format=j1`);
let jsonData = await data.json();
return json_viewer(jsonData);
}; https://val.town/v/stevekrouse/weatherDescription Thanks @mmcgrana (https://markmcgranaghan.com/) for the idea!
Script
# Inspector to browser json data in HTTP vals
![Screenshot 2024-02-23 at 9.31.42 AM.png](https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/50a08934-5f7f-41c4-2bfe-46b51612ae00/public)
Live example: https://stevekrouse-weatherdescription.web.val.run/
## Installation
```ts
export const weatherDescription = async (params: string[]): Promise<unknown> => {
export const json_viewer = (req: Request, data) => {
const accept = accepts(req);
if (!accept.type("html")) {
return Response.json(data);
tableSelectScript
@nbbaier
An interactive, runnable TypeScript val by nbbaier
Script
console.log("table selection script loaded!");
if (typeof Deno === "undefined") {
const tables = document.querySelectorAll(".tables-list-item");
const editor = document.getElementById("editordiv");
tables.forEach(table => {
table.addEventListener("click", async () => {
const tableName = table.id;
let statement; // = `SELECT * FROM ${tableName}`;
if (localStorage.getItem(`saved-${tableName}`) !== null) {
statement = localStorage.getItem(`saved-${tableName}`);
valle_tmp_3607258085523705726507190480068266
@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_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: `Sample Story ${idx + 1}`,
url: `https://example.com/story${idx + 1}`,
votes: Math.floor(Math.random() * 100),
watchReaderAndSendToMatrix
@vlad
An interactive, runnable TypeScript val by vlad
Cron
export const watchReaderAndSendToMatrix = async () => {
// plausibly this should be a roam plugin for better results =\
// or I should actually do the thing where message threads become hierarchies of block :p
const lastProcessedReadwiseItemDate = (await blob.getJSON("lastProcessedReadwiseItemDate")).date;
console.log({ lastProcessedReadwiseItemDate });
const itemList = await fetchReadwiseList(
process.env.readwise,
"new",
const lastSavedIdx = itemList.results.findIndex((it) =>
new Date(it.created_at)
saveFormDataExample
@maxm
An interactive, runnable TypeScript val by maxm
HTTP
export const renderFormAndSaveData = async (req: Request) => {
// A visit from a web browser? Serve a HTML page with a form
if (req.method === "GET") {
return new Response(
<!DOCTYPE html>
<html>
<head>
<title>Email Form</title>
</head>
<body>
braintrust_tool_test
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
HTTP
const zInput = z.object({
op: z.enum(["add", "subtract", "multiply", "divide"]),
a: z.number(),
b: z.number(),
type Input = z.TypeOf<typeof zInput>;
const tool = ({ op, a, b }: Input) => {
switch (op) {
case "add":
return a + b;
case "subtract":
vue
@postpostscript
vue: inline Vue SFC components in your HTML Example Val showing how to define reusable components: @postpostscript/vueExample import { htmlResponse } from "https://esm.town/v/postpostscript/html";
import { vueSfcInline } from "https://esm.town/v/postpostscript/vue";
export default function() {
return htmlResponse`
${vueSfcInline`
<script setup type="ts">
import { ref } from "vue";
const name = ref("Vue");
</script>
<template>
Hello World from {{ name }}!
<br>
<input v-model="name" />
</template>
`}
`;
}
Script
# vue: inline Vue SFC components in your HTML
Example Val showing how to define reusable components: @postpostscript/vueExample
```ts
export default function() {
return htmlResponse`
${vueSfcInline`
export { Vue };
export function vueSfc(name: string, template: string) {
window.moduleCache ??= {
vue: Vue,
switchbot
@stevekrouse
Open the Val Town Office Doors with Switchbot We installed two switchbot robots in our office: Ground Floor Office Door This webpage will let Val Town employees or guests to use these bots. The original version of this val was for a party. That fork is preserved here: @stevekrouse/switchbot_party Next steps [ ] Remove party theme [ ] Add one of @pomdtr's login methods [ ] Allow all @val.town emails to login [ ] Have any other email login ping me for approval or make a private val with a list of approved emails [ ] Add the office door to the site [ ] Add instructions (ie turn off wifi completely downstairs; be gentle with the office door one) Switchbot API This val authenticates to the switchbot API with SWITCHBOT_TOKEN and SWITCHBOT_KEY . Learn how to get your own Switchbot API keys here: Switchbot Docs .
HTTP
# Open the Val Town Office Doors with Switchbot
We installed two switchbot robots in our office:
1. Ground Floor
2. Office Door
This webpage will let Val Town employees or guests to use these bots.
The original version of this val was for a party. That fork is preserved here: @stevekrouse/switchbot_party
// This val creates a simple web interface for opening the Val Town office door.
// It uses the Hono framework for routing and HTML rendering, and interacts with
// the SwitchBot API to control the door. The approach includes:
// 1. A frontend route that displays a button to open the door
valle_tmp_265676068342328939565693893814446
@janpaul123
// This val will return a simple HTML page with the text "Hello, world!".
HTTP
// This val will return a simple HTML page with the text "Hello, world!".
export default async function main(req: Request): Promise<Response> {
const htmlContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World</title>
</head>