Search

Results include substring matches and semantically similar vals. Learn more
stevekrouse avatar
dude
@stevekrouse
Run squint in val.town!
Script
Run squint in val.town!
import * as squint from "npm:squint-cljs";
globalThis.squint_core = squint;
const program = `(js/console.log (+ 1 2 3))`;
let theString = squint.compileString(program, { repl: true, "elide-imports": true });
console.log(theString);
theString = theString.replace(`'squint-cljs/core.js'`, `'npm:squint-cljs/core.js'`);
const AsyncFunction = Object.getPrototypeOf(async function() {}).constructor;
await new AsyncFunction(theString)();
stevekrouse avatar
asyncExample1
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export let asyncExample1 = {p: Promise.resolve(10)}
chatgpt avatar
chat
@chatgpt
// Forked from @webup.chat
Script
export const chat = async (
prompt: string | object = "Hello world",
options = {},
// Initialize OpenAI API stub
const { Configuration, OpenAIApi } = await import("https://esm.sh/openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI,
const openai = new OpenAIApi(configuration);
// Request chat completion
const messages = typeof prompt === "string"
rafter avatar
cityLookup
@rafter
// Cities named Brooklyn
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
// Cities named Brooklyn
export let cityLookup = fetchJSON(
"https://nominatim.openstreetmap.org/search.php?city=brooklyn&format=jsonv2"
rustyb avatar
getTelAvivMobilitySpots
@rustyb
An interactive, runnable TypeScript val by rustyb
Script
interface APIResponse {
type: string;
crs: unknown;
features: unknown[];
export async function getTelAvivMobilitySpots() {
// const url =
// "https://gisn.tel-aviv.gov.il/arcgis/rest/services/IView2/MapServer/860/query?where=1=1&outFields=*&f=geojson";
const url = "https://app.digital4grids.com/api";
const json_data = await fetchJSON(url);
return { "json_data": [] };
pomdtr avatar
raw
@pomdtr
Fetch the source of a val This val was created before the introduction of https://esm.town Usage curl https://pomdtr-raw.web.val.run/v/<author>/<name>.<extension>[?v=<version>] To see the code of this val, use https://pomdtr-raw.web.val.run/v/pomdtr/raw.ts Examples Fetching the val code $ curl https://pomdtr-raw.web.val.run/v/pomdtr/add.tsx You can also use js , jsx and ts extension (only the content-type change, there is no transpilation). Fetching private val Pass an api token as an username $ curl "https://<token>@pomdtr-raw.web.val.run/v/pomdtr/privateVal.ts" Fetching the val README $ curl https://pomdtr-raw.web.val.run/v/pomdtr/add.md Getting an image $ curl https://pomdtr-raw.web.val.run/v/pomdtr/add.png Fetching a specific version of a val $ curl https://pomdtr-raw.web.val.run/v/pomdtr/raw.ts?v=66 You need to be authenticated to use this method. Fetching the val metadata $ curl https://pomdtr-raw.web.val.run/v/pomdtr/add.json Running vals locally using Deno Create a new val.ts file referencing the @pomdtr.add import { add } from "https://pomdtr-raw.web.val.run/v/pomdtr/add.ts"; console.log(add(1, 2)); then use deno run $ deno run ./val.ts 3 If you val accept a request and return a response, you can pass it to Deno.Serve to run it locally! import {raw} from "https://pomdtr-raw.web.val.run/v/pomdtr/raw.ts"; Deno.serve(raw); If your val is private, you can set the DENO_AUTH_TOKENS env. DENO_AUTH_TOKENS=<val-town-token>@pomdtr-raw.web.val.run deno run val.ts
HTTP (deprecated)
# Fetch the source of a val
> This val was created before the introduction of https://esm.town
## Usage
```console
curl https://pomdtr-raw.web.val.run/v/<author>/<name>.<extension>[?v=<version>]
To see the code of this val, use <https://pomdtr-raw.web.val.run/v/pomdtr/raw.ts>
async function createScreenshot(code: string) {
const apiUrl = "https://sourcecodeshots.com/api/image";
const resp = await fetch(apiUrl, {
method: "POST",
adrianlee avatar
aqi
@adrianlee
AQI Alerts Get email alerts when AQI is unhealthy near you. Set up Click Fork Change location (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via nominatim's geocoder API . Click Run Background This val uses nominatim's geocoder to get your lat, lon, and air quality data from OpenAQ. It uses EPA's NowCast AQI Index calculation and severity levels. Learn more: https://www.val.town/v/stevekrouse.easyAQI
Cron
# AQI Alerts
Get email alerts when AQI is unhealthy near you.
![](https://i.imgur.com/hB56X7o.png)
## Set up
1. Click `Fork`
2. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into
export async function aqi(interval: Interval) {
const location = "japanese prespretarian church, seattle, wa, 98144"; // <-- change to place, city, or zip code
const data = await easyAQI({ location });
if (!interval.lastRunAt) {
russbiggs avatar
foo
@russbiggs
An interactive, runnable TypeScript val by russbiggs
Script
export let foo = async (bar) => {
console.email(`This is ${bar}`);
steveb1313 avatar
OfficeJSTest
@steveb1313
An interactive, runnable TypeScript val by steveb1313
Script
export async function OfficeJSTest(
req: express.Request,
res: express.Response,
res.json({ message: "hello" });
hunty avatar
FetchBasic
@hunty
Framer Fetch: Basic A basic example of an API endpoint to use with Framer Fetch.
HTTP (deprecated)
# Framer Fetch: Basic
A basic example of an API endpoint to use with Framer Fetch.
export default async function(req: Request): Promise<Response> {
// Setup CORS Headers
const headers = new Headers();
headers.set("Access-Control-Allow-Origin", "*");
headers.set("Access-Control-Allow-Methods", "GET, PUT, DELETE, OPTIONS");
headers.set("Access-Control-Allow-Headers", "Content-Type");
// Pick a random greeting
const greetings = ["Hello!", "Welcome!", "Hi!", "Heya!", "Hoi!"];
tmcw avatar
sendFiveHundred
@tmcw
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Script
/** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqu
export let sendFiveHundred = (req, res) => {
res.send("Five hundred", 500);
tmcw avatar
nhttpExample
@tmcw
nhttp example This uses the tiny nhttp framework with the Val Town Web API . New frameworks like nhttp works really well with our system because they rely on the standard Request & Response objects! Server examples Hono Peko Itty Router Nhttp
HTTP (deprecated)
# nhttp example
This uses the tiny [nhttp framework](https://github.com/nhttp/nhttp) with the Val Town [Web API](https://docs.val.town/api/we
### Server examples
- [Hono](https://www.val.town/v/tmcw.honoExample)
- [Peko](https://www.val.town/v/tmcw.pekoExample)
- [Itty Router](https://www.val.town/v/tmcw.ittyRouterExample)
export const nhttpExample = async (request) => {
const { nhttp } = await import("npm:nhttp-land@1");
const app = nhttp();
app.get("/", () => {
yawnxyz avatar
wahoo
@yawnxyz
An interactive, runnable TypeScript val by yawnxyz
HTTP (deprecated)
export default async function (req: Request): Promise<Response> {
return Response.json( {message: 'hello!!'})
richardkaplan avatar
getWeather
@richardkaplan
Get Weather Simple function to get weather data from the free wttr.in service. import { getWeather } from "https://esm.town/v/stevekrouse/getWeather"; let weather = await getWeather("Brooklyn, NY"); console.log(weather.current_condition[0].FeelsLikeF)
Script
## Get Weather
Simple function to get weather data from the free [wttr.in](https://wttr.in/:help) service.
```ts
let weather = await getWeather("Brooklyn, NY");
console.log(weather.current_condition[0].FeelsLikeF)
export async function getWeather(location: string): Promise<WeatherResponse> {
return fetchJSON(`https://wttr.in/${location}?format=j1`);
export interface WeatherResponse {
current_condition: CurrentCondition[];
nearest_area: NearestArea[];
stu43005 avatar
hololiveAnniversaryIcs
@stu43005
An interactive, runnable TypeScript val by stu43005
HTTP (deprecated)
export async function hololiveAnniversaryIcs(req: Request) {
// if (
// req.url
// && new URL(req.url).searchParams.get("token")
// !== process.env.apiSecretToken
// return new Response(null, {
// status: 401,
const data = hololiveAnniversaryData;
const { error, value } = createEvents(data.map((item): EventAttributes => {
const [mm, dd] = item.日付.split("/").map((v) => parseInt(v, 10));