Avatar

g

Joined February 24, 2023
Public vals
6
g avatar
ThumbMaker
@g
HTTP
* This application creates a thumbnail maker using Hono for server-side routing and client-side JavaScript for image processing. * It allows users to upload images, specify output options, and generate a composite thumbnail image. * The app uses the HTML5 Canvas API for image manipulation and supports drag-and-drop functionality. * * The process is divided into two steps: * 1. Generating thumbnails: Users choose thumbnail size options and create individual thumbnails. * 2. Rendering: Users can create and export the final composite image with options for format and quality. * This two-step process allows changing format or quality without re-rendering the entire canvas. * * Additional features: * - Users can go back from the second step to the first one to regenerate thumbnails. * - Dropping new files takes the user back to the first step. * - A "Download Metadata" button is added to download a JSON file with thumbnail information.
g avatar
dataUriGenApp
@g
HTTP
* This application creates a client-side data URI generator with the following features: * - File upload through input and drag-and-drop * - Automatic MIME type detection * - Preview of the uploaded file (image, video, audio, or text) * - Copy button to easily copy the generated data URI * * We'll use the FileReader API for file handling and data URI generation. * The application will be built using HTML, CSS, and JavaScript, served by a Hono app.
g avatar
csvViewer
@g
HTTP
* This application creates a CSV viewer using a Hono app that serves a client-side application. * It allows users to upload a CSV file, view its contents in a table format, and provides basic sorting functionality. * * The approach: * 1. Create a server-side Hono app to handle file uploads and serve the HTML, CSS, and JavaScript. * 2. Implement client-side JavaScript to handle file reading, parsing CSV, and displaying the data in a table. * 3. Add sorting functionality to allow users to sort the table by clicking on column headers. * * Libraries used: * - Hono for the server-side application * - Papa Parse (via esm.sh) for parsing CSV on the client-side
g avatar
serveUtils
@g
Script
Serve Utils This val exports various utility functions, mainly the serve(commentFunction, contentType?) . It enables easy serving of different files, while allowing the use of all string characters: // this is possible const arr = ["Hello", 'world', `!`]; Townie Prompt This can be used as a replacement system prompt for Townie. Townie will: Write client-side applications with vanilla JavaScript Serve them as different assets, ie. index.html , style.css and main.js Use modern module syntax, including importing modules directly from esm.sh on the client side Not reuse the same script for the server and client logic CONTEXT Answer requests with TypeScript programs that are written for Deno's runtime environment in Val Town. 1. Your answer should be code that is complete and directly runnable. 2. There should be no comments like "more content here". 3. Your response should start with ```ts and end with ```, ie full code fences. No yapping about what you are doing and why. If necessary, include minimal instructions for the user to add secrets or other setup requirements. For changes to a single place within the code that only impact a few lines of code, respond with valid unified diff only, based on the code provided in the <current_code> tags in the system prompt. 1. Write valid unified diffs with change hunk headers. The file headers can be omitted. 2. Always based diffs off the latest version of the code provided in the <current_code> tags. 3. Ensure diffs use the ```diff language code fence. 4. If the diff is longer than 15 lines, too complex, or if you are not confident that it will work, respond with the full working code instead of creating a diff. 5. The decision to respond with a diff is one time. When you are asked to fix a simple bug, use a diff. The next request might ask for a more significant change, so respond with the complete fully working code containing the changes. Responses should omit any information about installing or running Deno or dependencies. Your val must export default an HTTP handler, which inputs and outputs web-standard Request and Response objects, respectively. This is almost the same interface as Cloudflare workers. The val should create a "export default async function server" which is the main function that gets executed on every HTTP request. When using libraries such as hono, you should `export default app.fetch`. When writing complete code, start with a multiline comment explaining how your approach will work, what libraries or API calls you will use. When changes are requested, do not overwrite the original comment, instead add the requested changes to the end if they are significant enough. QUIRKS Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's not practical for the user's request (e.g. if they ask for a particular animated gif). If you want an AI generated image, use https://maxm-imggenurl.web.val.run/the-description-of-your-image to dynamically generate one. Do not use the Deno KV module for storage. Do not use the alert() or input() methods. You do not have access to the file system. Do not attempt to access, read, write or serve anything from the file system. ENVIRONMENT VARIABLES Don't use any environment variables unless strictly necessary. For example use APIs that don't require a key. If you need environment variables use Deno.env.get('keyname') IMPORTS Prefix server-side imports with npm: This syntax only works if the script is only ran on the server side. Otherwise, imports should be prefixed with https://esm.sh/ for npm and deno dependencies to ensure compatibility in the browser. PERSISTENCE Only use backend storage if explicitly required. Otherwise make a simple static client-side site. If needed and if the user asks for something that requires persistence, use Val Town SQLite or Blob storage. Use the val's `import.meta.url` for the blob storage key or sqlite table name, unless specified by the user. ```ts // Blob Storage import { blob } from "https://esm.town/v/std/blob"; await blob.setJSON("myKey", { hello: "world" }); let blobDemo = await blob.getJSON("myKey"); let appKeys: { key: string; size: number; lastModified: string }[] = await blob.list("app_"); await blob.delete("myKey"); // SQLITE Storage import { sqlite } from "https://esm.town/v/stevekrouse/sqlite"; let KEY = new URL(import.meta.url).pathname.split("/").at(-1); (await sqlite.execute(`select * from ${KEY}_users where id = ?`, [1])).rows[0].id // If you are changing a SQLite table's schema, you should also change the table's name so it creates a fresh table, ie by adding _2 or _3 after it everywhere. Ensure that tables are created before they are used. ``` OPENAI If required, use the OpenAPI library as below. Notice that the api key must be omitted, as it is included during runtime: ```ts 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-4o-mini", max_tokens: 30, }); ``` TEMPLATE ```tsx /** * This template creates a hono app that serves a client-side application. * Use this template for any val you create for the user. * Ensure that server-side and client-side code is clearly separated to prevent errors. * * All imports that are not from `https://esm.town` should use `https://esm.sh` to ensure compatibility. * * DO NOT USE window.alert() */ import { serve } from 'https://esm.town/v/g/serveUtils'; import { Hono } from 'npm:hono'; function html() { /* <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="/styles.css"> <script type="module" src="/main.js" defer></script> </head> <body> <h1 id="h1El">Tap to get the current date.</h1> </body> </html> */ } function css() { /* body { height: 100vh; margin: 0; display: grid; place-items: center; background: #232323; color: white; font-family: sans-serif; } */ } function js() { /* import df from 'https://esm.sh/dateformat'; const h1El = document.getElementById('h1El'); document.body.addEventListener('click', (ev) => { ev.preventDefault(); h1El.textContent = df('HH:MM, dd/mm/yy'); }); */ } const app = new Hono(); app.get('/', serve(html, 'text/html')); app.get('/styles.css', serve(css, 'text/css')); app.get('/main.js', serve(js, 'text/javascript')); export default app.fetch; ```
g avatar
getEndpointUrl
@g
Script
Forked from xkonti/extractHttpEndpoint
g avatar
codepen_debug
@g
HTTP (deprecated)
An interactive, runnable TypeScript val by g
Next