Newest
Fancy animated SVGs in readmes, along with centering and image sizing.
<div align="center"><img width=200 src="https://gpanders.com/img/DEC_VT100_terminal.jpg"></div>
<p align="center">
<img src="https://maxm-animatedreadmesvg.web.val.run/comet.svg" />
</p>
<p align="center">
<img src="https://maxm-animatedreadmesvg.web.val.run/custom text!" />
</p>
Static Chess
Check it out here: https://chess.maxmcd.com
Plain, brutalist, no bloat chess. Every page is only html and css. Every chess move is made by clicking a link. Send a link to your friend and they'll send you one back to make your move. No silly animations or slick interactivity to trip up your gameplay. When Google indexes this site will we successfully compute all possible chess moves?
Functionality is quite limited, and things might be broken. Please let me know if you find bugs!
Inspired by this HN discussion about sites that have all possible game states of tic-tac-toe.
I plan on extending this to support real gameplay. I think it could be a nice simple interface for long form games with friends. Might also be fun to add a static AI to play against. Feel free to PR any changes if you'd like to see something added.
Decorator Router
Fair simple decorator based router, with GET/POST and middleware support.
demo
live demo: https://yieldray-decorator_router_demo.web.val.run/
Create valimport { get, post, all, use, registered, handler, type Context } from "https://esm.town/v/yieldray/decorator_router";
import { parseBearerAuth, transformResponse } from "https://esm.sh/serve-router@1.1.0/utils";
interface User {
id: number;
name: string;
}
const users: User[] = [
{ id: 0, name: "Alice" },
{ id: 1, name: "Ray" },
];
class _Server {
/**
* Decorator @get: Parses URLSearchParams into an object as the first parameter.
*/
@get("/users")
getAllUsers() {
return users; // Automatically wrapped in a Response.json
}
@get("/getUserByName") // GET /getUserByName?name=Alice
getUserByName({ name }: Record<string, string>) {
const user = users.find((u) => u.name === name);
if (user) {
return user; // Automatically wrapped as Response.json(user)
}
// Optionally, manually return a Response object
return Response.json({ error: "not found" }, { status: 404 });
}
@get("/user/:id") // GET /user/123
user(_: unknown, { params: { id } }: Context) {
return users.find((u) => u.id === Number(id));
}
/**
* Decorator @post: Parses the request body into an object as the first parameter.
*/
@post("/user") // POST /user
async createUser(user: User) {
if (users.find((u) => u.id === user.id)) {
return { error: "already exists!" };
}
await users.push(user); // Assume insertion into a database
return { ok: true, users };
}
@post("/user/:id") // POST /user/123
async updateUser(user: User, { params: { id }, request }: Context) {
const token = parseBearerAuth(request.headers.get("Authorization")!);
// Additional logic here...
}
@all("/")
home({ request }: { request: Request }) {
return {
registered,
method: request.method,
url: request.url,
headers: Object.fromEntries(request.headers.entries()),
};
}
@use("/*")
async corsMiddleware({ next, request }: Context) {
const resp = await next();
return transformResponse(resp, {
headers: {
"Access-Control-Allow-Origin": request.headers.get("origin") || "*",
},
});
}
}
// For Deno:
Deno.serve(handler);
// For val.town:
export default handler;
OpenAI ChatGPT helper function
This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.
Create valimport { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat("Hello, GPT!");
console.log(content);
Create valimport { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat(
[
{ role: "system", content: "You are Alan Kay" },
{ role: "user", content: "What is the real computer revolution?"}
],
{ max_tokens: 50, model: "gpt-4" }
);
console.log(content);
markdown.download
Handy microservice/library to convert various data sources into markdown. Intended to make it easier to consume the web in ereaders
Introductory blog post: https://taras.glek.net/post/markdown.download/
Package: https://jsr.io/@tarasglek/markdown-download
Features
- Apply readability
- Further convert article into markdown to simplify it
- Allow webpages to be viewable as markdown via curl
- Serve markdown converted to html to browsers
- Extract youtube subtitles
Source
https://github.com/tarasglek/markdown-download
https://www.val.town/v/taras/markdown_download
License: MIT
Usage: https://markdown.download/ + URL
Dev: https://val.markdown.download/ + URL