Search

Results include substring matches and semantically similar vals. Learn more
stevekrouse avatar
cron2
@stevekrouse
@jsxImportSource npm:hono@3/jsx
HTTP (deprecated)
/** @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
honoJSX
@pomdtr
@jsxImportSource https://esm.sh/hono/jsx
HTTP (deprecated)
/** @jsxImportSource https://esm.sh/hono/jsx **/
const Layout = (props) => {
return (
<html>
<body>{props.children}</body>
</html>
const Top = (props: { messages: string[] }) => {
return (
<Layout>
<h1>Hello Hono!</h1>
janpaul123 avatar
valle_tmp_65773463412544294175217031213487
@janpaul123
// Initialize SQLite database and comments table if it doesn't exist
HTTP (deprecated)
// Initialize SQLite database and comments table if it doesn't exist
const initDB = async () => {
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS comments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
text TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
await initDB();
const app = new Hono();
// Serves the comment page
peterqliu avatar
vt_app_v3
@peterqliu
@jsxImportSource https://esm.sh/hono@4.0.8/jsx
HTTP
/** @jsxImportSource https://esm.sh/hono@4.0.8/jsx **/
const app = new Hono();
app.use(
jsxRenderer((c) => {
const { children } = c;
return (
<html>
<head>
<link
rel="stylesheet"
dthyresson avatar
honoWithUnkeyRateLimiting
@dthyresson
Example of using Unkey Ratelimiting See: https://www.unkey.com/docs/libraries/ts/ratelimit
HTTP (deprecated)
# Example of using Unkey Ratelimiting
See: https://www.unkey.com/docs/libraries/ts/ratelimit
/** @jsxImportSource npm:hono@3/jsx */
export function unkeyRatelimitMiddleware(config: RatelimitConfig): MiddlewareHandler {
const ratelimiter = new Ratelimit(config);
return async (c, next) => {
const ratelimitResponse = await ratelimiter.limit("home");
console.log(">> ratelimitResponse", ratelimitResponse);
if (!ratelimitResponse.success) {
return c.html(
janpaul123 avatar
valle_tmp_888865450629273105329300182726127
@janpaul123
// Initialize SQLite database and comments table if it doesn't exist
HTTP (deprecated)
// Initialize SQLite database and comments table if it doesn't exist
const initDB = async () => {
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS comments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
text TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
await initDB();
const app = new Hono();
// Serves the comment page
stevekrouse avatar
reactExample
@stevekrouse
@jsxImportSource https://esm.sh/react
HTTP (deprecated)
/** @jsxImportSource https://esm.sh/react */
import { renderToString } from "npm:react-dom/server";
export const reactExample = () =>
new Response(renderToString(<div>Test {1 + 1}</div>), {
headers: {
"Content-Type": "text/html",
thecurryman avatar
ismyplaneaboeing
@thecurryman
@jsxImportSource https://esm.sh/preact
HTTP (deprecated)
/** @jsxImportSource https://esm.sh/preact */
export let isBoeing = async (airline, number) => {
const response = await fetch("https://www.flightstats.com/v2/flight-tracker/" + airline + "/" + number);
const body = await response.text();
const $ = cheerio.load(body);
const boeingElements = $("h5").filter(function() {
return $(this).text().includes("Boeing");
let aircraft = [];
boeingElements.each(function() {
aircraft.push($(this).text());
jxnblk avatar
JxnblkCSS
@jxnblk
CSS for https://val.town/v/jxnblk/dotcom – https://jxnblk.com
Script
CSS for <https://val.town/v/jxnblk/dotcom><https://jxnblk.com>
// tuna-based generative css lib
export const colors = [
"light",
"foliage",
"paper",
"amber",
"tomato",
"brown reverse",
"dark reverse",
neverstew avatar
preactTest
@neverstew
An interactive, runnable TypeScript val by neverstew
HTTP (deprecated)
export const preactTest = async () => {
const { useState, h, htm, renderToString } = await import(
"https://npm.reversehttp.com/preact,htm,preact/hooks,preact-render-to-string"
const html = htm.bind(h);
function Component() {
const [count, setCount] = useState(0);
const inc = () => setCount(count => count + 1);
return html`<div class="foo" onClick=${inc}>${count}</div>`;
return new Response(renderToString(h(Component)));
vladimyr avatar
feps
@vladimyr
An interactive, runnable TypeScript val by vladimyr
HTTP (deprecated)
import { Hono } from "npm:hono@3.12.7";
const app = new Hono();
app.get("/:fepId{[A-za-z0-9]{4}}", (c) => {
const fepId = c.req.param("fepId").toLowerCase();
return c.redirect(`https://codeberg.org/fediverse/fep/src/branch/main/fep/${fepId}/fep-${fepId}.md`);
export default app.fetch;
shellphon avatar
getEmojis
@shellphon
An interactive, runnable TypeScript val by shellphon
Script
export async function getEmojis(num, isRandom = false) {
const { default: emojis } = await import("npm:emojis-list");
if (isRandom) {
return emojis.sort(() => Math.random() - 0.5).slice(0, num);
return emojis.slice(0, num);
stevekrouse avatar
lucia_middleware
@stevekrouse
Lucia Middleware Import users. Backed by Val Town SQLite. Demo: @stevekrouse/lucia_middleware_demo If you want a version that is safe to import (but not call) on the frontend: import { luciaMiddleware } from "https://esm.town/v/stevekrouse/lucia_middleware_safe"; Usage Wrap your HTTP handler in it, ie export default luciaMiddleware(handler) In your handler, redirect to /auth/signup , /auth/login , /auth/logout to trigger those flows. Remember Response.redirect is broken in Val Town right now, so either use links or return new Response(null, { 302, headers: { Location: "/place/to/redirect" }}) In your HTTP handler, read the X-Lucia-Username header, ie const username = req.headers.get("X-Lucia-Username") If the user is logged in, you now have a username you can work with. If not, it will be empty Custom Sign Up and Log In pages By default, the middleware has very basic sign in and sign up pages. The only way to customize those right now is to fork this middleware and customize them to your liking. Todos [ ] Allow users to specify the users & sessions table [ ] Remove Hono from this middleware (attempted in this fork: @stevekrouse/lucia_middleware_vanilla) [ ] Allow users to customize the auth pages without forking the middleware Initially built by @pomdtr
Script
# Lucia Middleware
Import users. Backed by Val Town SQLite.
Demo: @stevekrouse/lucia_middleware_demo
If you want a version that is safe to import (but not call) on the frontend:
```ts
## Usage
/** @jsxImportSource npm:hono/jsx **/
// TODO - make these configurable
const userTable = "lucia_users_1";
const sessionTable = "lucia_sessions_1";
pomdtr avatar
python
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
import pyodideModule from "npm:pyodide/pyodide.js";
(globalThis as any).window = {};
(globalThis as any).document = { location: { href: "" }, currentScript: { src: "" } };
(globalThis as any).navigator = {};
export async function loadPython(params?: { packages: string[] }) {
const pyodide = await pyodideModule.loadPyodide();
for (const pkg of params?.packages || []) {
await pyodide.loadPackage(pkg);
return (strings: TemplateStringsArray) => pyodide.runPythonAsync(strings[0]);
stevekrouse avatar
poembuilder3
@stevekrouse
@jsxImportSource npm:hono@3/jsx
HTTP (deprecated)
/** @jsxImportSource npm:hono@3/jsx */
sqlite.execute(`
CREATE TABLE IF NOT EXISTS poemlines3 (
id INTEGER PRIMARY KEY autoincrement,
line TEXT,
safe TEXT
const app = new Hono();
app.get("/", async (c) => {
const poem = await sqlite.execute(`SELECT id, line FROM poemlines3 WHERE safe='SAFE'`);
return c.html(