Search

Results include substring matches and semantically similar vals. Learn more
andreterron avatar
genval
@andreterron
Generate a Val Uses the OpenAI API to generate code for a val based on the description given by the user. TODO: [ ] Improve code detection on GPT response [ ] Give more context on val town exclusive features like console.email or @references [ ] Enable the AI to search val town to find other vals to use
HTTP
# [Generate a Val](https://andreterron-genval.express.val.run)
Uses the OpenAI API to generate code for a val based on the description given by the user.
TODO:
- [ ] Improve code detection on GPT response
- [ ] Give more context on val town exclusive features like console.email or @references
- [ ] Enable the AI to search val town to find other vals to use
export let genval = async (req: Request): Promise<Response> => {
const { default: htm } = await import("npm:htm");
const { default: vhtml } = await import("npm:vhtml");
const cookies = await import("https://deno.land/std@0.193.0/http/cookie.ts");
stevekrouse avatar
openaiStreamingDemo
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
HTTP
const openai = new OpenAI();
export default async (req) => {
const stream = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: "Tell me a story" }],
stream: true,
let { readable, writable } = new TransformStream();
let writer = writable.getWriter();
const textEncoder = new TextEncoder();
new Promise(async () => {
zackoverflow avatar
minizodFunctionGenerateTypescript
@zackoverflow
An interactive, runnable TypeScript val by zackoverflow
Script
export const minizodFunctionGenerateTypescript = (
username: string,
name: string,
authToken: string,
minizodType: any,
): string => {
const mzt = minizodCast(minizodType);
if (mzt.type !== "function")
throw new Error("Not a function");
const argsType = mzt.__args.toTs();
tmcw avatar
brownPelican
@tmcw
An interactive, runnable TypeScript val by tmcw
HTTP
export default async function (req: Request): Promise<Response> {
return Response.json({ ok: true })
janpaul123 avatar
valle_tmp_90775096713594030038814365860220246
@janpaul123
// Define interface for Story object
HTTP
// Define interface for Story object
interface Story {
id: number;
title: string;
url: string;
points: number;
const app = new Hono();
const BLOB_KEY = "hacker_news_stories";
// Add 30 fake sample stories
async function initializeStories() {
dbee avatar
fcReadyPublic
@dbee
// Initialize the Farcaster SDK and set the frame context
Script
import fcsdk from "https://esm.sh/@farcaster/frame-sdk@0.0.26";
// Initialize the Farcaster SDK and set the frame context
(async () => {
try {
await fcsdk.actions.ready();
} catch (error) {
console.error("Error initializing SDK:", error);
Davidkim avatar
EmailNotifIfDidntCode
@Davidkim
An interactive, runnable TypeScript val by Davidkim
Cron
export async function EmailNotifIfDidntCode() {
type Data = DataItem[];
interface DataItem {
id: string;
type: string;
actor: any;
repo: any;
payload: any;
"public": boolean;
created_at: string;
dglazkov avatar
bbaas
@dglazkov
Breadboard As a Service A simple board runner that allows hosting board as a service. The service can be public (accessible to everyone) or private (locked behind a service key). See chatbot example for a public service and generatevoice for private. Make sure to add all the necessary secrets to your environment variables. The resulting HTTP endpoint can be then used as a Service URL for Core Kit's service node.
Script
# Breadboard As a Service
A simple board runner that allows hosting board as a service.
The service can be public (accessible to everyone) or private (locked behind a service key).
See [chatbot](https://www.val.town/v/dglazkov/chatbot) example for a public service and [generatevoice](https://www.val.town/
Make sure to add all the necessary secrets to your environment variables.
The resulting HTTP endpoint can be then used as a Service URL for Core Kit's `service` node.
type HarnessRunResult,
run,
} from "npm:@google-labs/breadboard/harness";
asRuntimeKit,
thedro avatar
myApi
@thedro
An interactive, runnable TypeScript val by thedro
Script
export const myApi = ((input) => {
var inner = (name) => {
return "hello " + name;
console.log(inner("What"));
console.log(inner);
return { inner, value: "one", output: inner("sup") };
// return async () => {
// inner(input);
pomdtr avatar
codeOnValTown
@pomdtr
Code on Val Town Adds a "Code on Val Town" ribbon to your page. This lets your website visitors navigate to the code behind it. This uses github-fork-ribbon-css under the hood. Usage Here are 2 different ways to add the "Code on Val Town" ribbon: 1. Wrap your fetch handler (recommended) import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=45"; import { html } from "https://esm.town/v/stevekrouse/html?v=5"; export default modifyFetchHandler(async (req: Request): Promise<Response> => { return html(`<h2>Hello world!</h2>`); }); Example: @andreterron/openable_handler 2. Wrap your HTML string import { modifyHtmlString } from "https://esm.town/v/andreterron/codeOnValTown?v=45"; import { html } from "https://esm.town/v/stevekrouse/html?v=5"; export default async (req: Request): Promise<Response> => { return html(modifyHtmlString(`<h2>Hello world!</h2>`)); }; Example: @andreterron/openable_html Other ways We made sure this was very modular, so you can also add the ribbon using these methods: Get the element string directly: @andreterron/codeOnVT_ribbonElement Modify an HTTP Response: @andreterron/codeOnVT_modifyResponse Use .pipeThrough to append to a stream: @andreterron/InjectCodeOnValTownStream Customization Linking to the val These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the val argument: modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }}) modifyHtmlString("<html>...", {val: { handle: "andre", name: "foo" }}) Styling You can set the style parameter to a css string to customize the ribbon. Check out github-fork-ribbon-css to learn more about how to style the element. modifyFetchHandler(handler, {style: ".github-fork-ribbon:before { background-color: #333; }"}) modifyHtmlString("<html>...", {style: ".github-fork-ribbon:before { background-color: #333; }"}) Here's how you can hide the ribbon on small screens: modifyFetchHandler(handler, {style: `@media (max-width: 768px) { .github-fork-ribbon { display: none !important; } }`}) To-dos [ ] Let users customize the ribbon. Some ideas are the text, color or placement.
Script
# Code on Val Town
![Screenshot 2024-02-27 at 1.25.46 PM.png](https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/6b67bb0a-d80f-4f3d-5b17-57b5378b3
Adds a "Code on Val Town" ribbon to your page. This lets your website visitors navigate to the code behind it.
This uses [github-fork-ribbon-css](https://github.com/simonwhitaker/github-fork-ribbon-css) under the hood.
## Usage
Here are 2 different ways to add the "Code on Val Town" ribbon:
* @param bodyText HTML string that will be used to inject the element.
* @param val Define which val should open. Defaults to the root reference.
export function modifyHtmlString(
bodyText: string,
dhvanil avatar
val_FHkXzjGb1t
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export default async function handler(req) {
try {
const result = await (async () => {
function findLowestThreeDigitFibonacci() {
let a = 0, b = 1;
let lowestThreeDigitFibonacci = 0;
while (b < 1000) {
let temp = b;
b = a + b;
a = temp;
laidlaw avatar
books
@laidlaw
@jsxImportSource npm:hono@3/jsx
HTTP
/** @jsxImportSource npm:hono@3/jsx */
const openai = new OpenAI();
function esmTown(url) {
return fetch(url, {
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.142.86 Safari/537
}).then(r => r.text());
const app = new Hono();
export default app.fetch;
janpaul123 avatar
valle_tmp_418674886600415720477086592392646
@janpaul123
// This val will respond to HTTP requests with a simple "Hello, world!" message.
HTTP
// This val will respond to HTTP requests with a simple "Hello, world!" message.
export default async function main(req: Request): Promise<Response> {
return new Response("Hello, world!");
stevekrouse avatar
cron2
@stevekrouse
@jsxImportSource npm:hono@3/jsx
HTTP
/** @jsxImportSource npm:hono@3/jsx */
const app = new Hono();
export default app.fetch;
app.get("/", async (c) => {
const description = c.req.query("description") || "On weekdays at noon";
const timezone = c.req.query("timezone") || "America/New_York";
const cron = c.req.query("description") ? await compile(description, timezone) : "0 16 * * 1-5";
let translated;
try {
translated = cronstrue.toString(cron, { tzOffset: getOffset(timezone), use24HourTimeFormat: false });
pomdtr avatar
renderGithubReadme
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
export async function renderGithubReadme(req: express.Request, res: express.Response) {
try {
const { repo } = req.query as {
repo: string;
const markdown = await fetch(`https://api.github.com/repos/${repo}/readme`)
.then((res) => res.json()).then(({ content }) => atob(content));
const html = await fetch("https://api.github.com/markdown", {
method: "POST",
headers: {
"Accept": "Accept: application/vnd.github+json",