Search

Results include substring matches and semantically similar vals. Learn more
stevekrouse avatar
firmIvorySawfish
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
["dthyresson", "playRandomSong"],
["cephalization", "smsjournalertextrelay"],
["isidentical", "fluxImageGenerator"],
["stevekrouse", "lucia_middleware"],
["vawogbemi", "short"],
nerdymomocat avatar
add_to_notion_w_ai
@nerdymomocat
Uses instructor and open ai (with gpt-4-turbo) to process any content into a notion database entry. Use addToNotion with any database id and content. await addToNotion( "DB_ID_GOES_HERE", "CONTENT_GOES HERE"//"for example: $43.28 ordered malai kofta and kadhi (doordash) [me and mom] jan 3 2024" ); Prompts are created based on your database name, database description, property name, property type, property description, and if applicable, property options (and their descriptions). Supports: checkbox, date, multi_select, number, rich_text, select, status, title, url, email Uses NOTION_API_KEY , OPENAI_API_KEY stored in env variables and uses Valtown blob storage to store information about the database. Use get_notion_db_info to use the stored blob if exists or create one, use get_and_save_notion_db_info to create a new blob (and replace an existing one if exists).
Script
import Instructor from "npm:@instructor-ai/instructor";
import { Client } from "npm:@notionhq/client";
import OpenAI from "npm:openai";
const NOTION_API_KEY = process.env.NOTION_API_KEY;
const notion = new Client({
auth: NOTION_API_KEY,
apiKey: process.env.OPENAI_API_KEY ?? undefined,
const client = Instructor({
client: oai,
mode: "TOOLS",
const db_info = await get_notion_db_info(dbid);
const processed_message = await client.chat.completions.create({
messages: [{ role: "system", content: db_info["system_message"] }, { role: "user", content: text }],
liamdanielduffy avatar
REACT_DOM_MINIFIED_PT1
@liamdanielduffy
// set by liamdanielduffy.buildReactDomMinified at 2023-06-01T12:04:43.562Z
Script
// set by liamdanielduffy.buildReactDomMinified at 2023-06-01T12:04:43.562Z
export let REACT_DOM_MINIFIED_PT1 = "/**\n * @license React\n * react-dom.production.min.js\n *\n * Copyright (c) Facebook, I
yawnxyz avatar
valVersions
@yawnxyz
* Retrieves a user by their username. * @param {string} username - The username of the user to retrieve. * @returns {Promise<Object>} The user object.
Script
import { Sema } from 'npm:async-sema'; // Import async-sema
const client = new ValTown();
* Retrieves a user by their username.
export async function getUser(username) {
const user = await client.alias.username.retrieve(username);
return user;
// Automatically fetches more pages as needed.
for await (const basicVal of client.users.vals.list(user.id, {
limit: 100,
// Automatically fetches more pages as needed.
for await (const versionListResponse of client.vals.versions.list(valId, {
limit: 20, // Default limit
const valPromises = [];
for await (const basicVal of client.users.vals.list(user.id, {
limit: 100,
nicosuave avatar
databaseRunner
@nicosuave
An interactive, runnable TypeScript val by nicosuave
HTTP (deprecated)
console.log("Connecting to PostgreSQL");
const client = new pg.Client({
connectionString: url,
try {
await client.connect();
console.log("Connected to PostgreSQL successfully");
console.log("Executing PostgreSQL query");
const res = await client.query(query);
console.log(`PostgreSQL query executed. Row count: ${res.rows.length}`);
await Promise.race([
client.end(),
new Promise((_, reject) => setTimeout(() => reject(new Error("Connection close timed out")), 1000)),
zzz avatar
YoutubeTranscript
@zzz
An interactive, runnable TypeScript val by zzz
Script
static generateRequest(page: string, config?: TranscriptConfig) {
const clientScreenNonce = this.generateNonce();
const params = this.extractValue(page, YouTubeKey.serializedShareEntity);
context: {
client: {
hl: config?.lang || "en",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Saf
clientName: "WEB",
clientVersion: "2.20200925.01.00",
osName: "Macintosh",
user: {},
clientScreenNonce,
clickTracking: {
throw new YoutubeTranscriptError("Malformed YouTube video url or ID.");
* Generate nonce for clientScreenNonce as part of YouTube API
static generateNonce() {
MattieTK avatar
octopusAgilePricing
@MattieTK
Backend val for https://www.val.town/v/MattieTK.laMetricOctopus Feel free to use it in your own apps.
Script
"East Midlands": "B",
"Eastern England": "A",
"Merseyside & Northern Wales": "D",
"North Eastern England": "F",
"North Western England": "G",
iamseeley avatar
savePDF
@iamseeley
šŸ—ƒļø save your html as a pdf using html2pdf // Adjust the options html2pdf(element, { margin: 0.2, filename: 'resume.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2 }, jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' } }) usage <!-- Add the button to your html --> <body> <button id="saveAsPDFButton">Save as PDF</button> <!-- Import the module --> <script type="module" src="https://esm.town/v/iamseeley/savePDF"></script> </body>
Script
page-break-before: auto !important;
page-break-inside: auto !important;
margin-bottom: 20px !important; /* Add space between sections */
section > ul {
page-break-inside: auto !important;
margin-bottom: 15px !important;
section > ul > li {
page-break-inside: avoid !important;
margin-bottom: 15px !important;
#certificates > ul > li {
page-break-inside: auto !important;
margin-bottom: 20px !important;
.title-period {
page-break-inside: avoid !important;
margin-bottom: 5px !important;
.highlights {
page-break-inside: auto !important;
.highlight-item {
page-break-inside: avoid !important;
margin-bottom: 8px !important;
saolsen avatar
git_sync
@saolsen
Sync vals to a git repo This will not run on val town! You need to run it locally with deno. Install Deno: https://docs.deno.com/runtime/manual/getting_started/installation Set your val.town api key as an environment variable. https://www.val.town/settings/api export valtown="abcdefgh-ijkl-mnop-qrst-uvwxyz123456" Create a git repo to sync to. mkdir ./valtown && pushd ./valtown && git init && popd Copy down this script and run it, passing the path to your git directory. deno run -A ./git_sync.ts ./valtown There is currently no incremental syncing or recovering. You can only use this script against a fresh git repo. If you want to sync to an existing repo, you should create a new repo, run the script and then force push to your existing repo. This will sync all your vals, including private ones so be careful where you push your git repo if you want those to remain private.
Script
throw e;
// check if the directory is a git repo
const [code, _output] = await git(["rev-parse", "--is-inside-work-tree"]);
if (code != 0) {
console.log(`${git_repo} is not a git repo.`);
tambre avatar
getRedditAccessToken
@tambre
// The account's 2FA needs to be disabled.
Script
const authorization = "Basic "
+ Buffer.from(
`${process.env.reddit_client_id}:${process.env.reddit_client_secret}`,
).toString("base64");
const response = await fetch("https://www.reddit.com/api/v1/access_token", {
petermillspaugh avatar
june2024
@petermillspaugh
@jsxImportSource https://esm.sh/preact
Script
/** @jsxImportSource https://esm.sh/preact */
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
</p>
<h2>Working outside a tech hub</h2>
<p>
<p>
So Iā€™m starting to accrue perspective on working in software while living outside a tech hub. There arenā€™t
weekly meetups like you have in NYC and SF, but there are engineers around if you look closely! And you can
arthrod avatar
OpenAI
@arthrod
OpenAI - Docs ā†— Use OpenAI's chat completion API with std/openai . This integration enables access to OpenAI's language models without needing to acquire API keys. For free Val Town users, all calls are sent to gpt-4o-mini . Usage import { OpenAI } from "https://esm.town/v/std/openai"; const openai = new OpenAI(); const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" }, ], model: "gpt-4", max_tokens: 30, }); console.log(completion.choices[0].message.content); Limits While our wrapper simplifies the integration of OpenAI, there are a few limitations to keep in mind: Usage Quota : We limit each user to 10 requests per minute. Features : Chat completions is the only endpoint available. If these limits are too low, let us know! You can also get around the limitation by using your own keys: Create your own API key on OpenAI's website Create an environment variable named OPENAI_API_KEY Use the OpenAI client from npm:openai : import { OpenAI } from "npm:openai"; const openai = new OpenAI(); šŸ“ Edit docs
Script
3. Use the `OpenAI` client from `npm:openai`:
import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
private rawOpenAIClient: RawOpenAI;
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
[opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing ou
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as i
constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
this.rawOpenAIClient = new RawOpenAI({
return this.rawOpenAIClient.chat;
stevekrouse avatar
awesome
@stevekrouse
Awesome Val Town An curated list of useful community vals. Feel free to create your own awesome list! Apps @pomdtr/blob_editor @nbbaier/sqliteExplorerApp View and interact with your Val Town SQLite data. @pomdtr/http_client Attach a postman-like http client to your vals VS Code Extension vt Chrome Extension Tooling Authentication @pomdtr/basicAuth @pomdtr/email_auth @pomdtr/password_auth Sqlite @sqlite/db @pomdtr/sql @pomdtr/kv @postpostscript/sqliteUniverse Blob @stevekrouse/blobAdmin @pomdtr/lowdb Middleware @andreterron/codeOnValTown Testing @pomdtr/test_explorer Api @pomdtr/api @pomdtr/trpc Other @vladimyr/valshot @pomdtr/mdx @pomdtr/serve_readme OpenAI @pomdtr/ask_ai Web Components Val Town Playground CodeMirror
HTTP (deprecated)
- @nbbaier/sqliteExplorerApp View and interact with your Val Town SQLite data.
- @pomdtr/http_client Attach a postman-like http client to your vals
- [VS Code Extension](https://github.com/pomdtr/val-town-vscode)
tr3ntg avatar
md5
@tr3ntg
An interactive, runnable TypeScript val by tr3ntg
Script
* See http://pajhome.org.uk/crypt/md5 for more info.
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
tmcw avatar
reasonPhrase
@tmcw
The story behind HTTP 200 "OK" What's in an HTTP response? I've been writing software for the web since the early 2000s and have incrementally learned things about HTTP. There are status codes, like "200" and "404". There are headers, for Content-Type and headers to control cache settings. There are different versions of HTTP itself, like 1.1, 2, and 3. HTTP requests and responses can contain data, in the message body. But there's one thing I didn't notice until yesterday. A quirk that was included in the HTTP 1.1 specification with an authors note that it's mostly there for historical reasons: the reason-phrase . None of this information is useful. The reason-phrase is barely supported on the web and was always an oddity, but keep reading if you like oddities! If you're used to JavaScriptā€™s fetch() method to make HTTP requests, you've seen the reason-phrase under a different name: statusText : (await fetch('https://example.com/')).statusText What is statusText ? I had assumed that it was something that JavaScript itself provides, by looking up the status code 200 and matching it with the text "OK". I was wrong! When I look at a raw HTTP response, I see the first few lines are like this: HTTP/1.1 200 OK Date: Thu, 17 Aug 2023 15:16:42 GMT Content-Type: text/plain;charset=UTF-8 The reason phrase So what is that text? I dug around in the HTTP 1.0 specification and found the section Status Code and Reason Phrase . The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request. The Reason-Phrase is intended to give a short textual description of the Status-Code. The Status-Code is intended for use by automata and the Reason-Phrase is intended for the human user. The client is not required to examine or display the Reason-Phrase. That also lists recommended reason phrases, like OK for 200 and Not Found for 404. And notes that you can choose different phrases without affecting the protocol. The HTTP 1.1 specification adds a little color about the reason-phrase : So, with a HTTP server, you can customize your reason phrase! Here's an example with a val on Val Town: let customReason = (req) => new Response("", { statusText: 'Hello world!', }); Unfortunately, this doesn't work! The response that Val Town produces is reorganized and optimized by Cloudflare, which upgrades requests and responses from HTTP 1.1 to HTTP 2. And sadly, HTTP 2 dropped support for the custom reason-phrase . RIP the reason-phrase . It was present even in a 1992 draft of the HTTP specification , and was a weird and under-appreciated way to pilfer extra information in a response. Now, thanks to HTTP/2 and the commonplace use of proxies and CDNs like Cloudflare, it's no longer usable. It was fun while it lasted.
Script
So what _is_ that text? I dug around in the HTTP 1.0 specification and found the section [Status Code and Reason Phrase](http
or use by automata and the Reason-Phrase is intended for the human user. The client is not required to examine or display the
That also lists recommended reason phrases, like OK for 200 and Not Found for 404. And notes that you can choose different ph