52
53// The script we run within the worker. Don't reference anything
54// outside of this function as it won't be available within the worker. We could even host this in a separate val and pass
55const workerScript = () => {
56 type Log = {
64 get(target, key) {
65 const real = target[key];
66 if (typeof real === "function" && typeof key === "string") {
67 const fn = function(...args: any[]) {
68 logs.push({
69 level: key,
79 },
80 });
81 async function evaluate(url) {
82 try {
83 const _ = await import(url);
170
171// // evaluate("let ten = 10");
172// // evaluate("function cube(x) { return x ** 3 }");
173// // evaluate("ten + cube(3)");
174// evaluate(`
2import { google } from "npm:googleapis";
3
4export async function getAccessToken(accountId: string, bearer = Deno.env.get("pipedream")) {
5 const response = await fetchJSON(
6 `https://api.pipedream.com/v1/accounts/${accountId}?include_credentials=1`,
10}
11
12export function googleService(service: string, accessToken: string) {
13 return google[service]({
14 version: "v3",
19}
20
21export async function pipeDreamGoogle(service: string, accountId: string, bearer = Deno.env.get("pipedream")) {
22 const accessToken = await getAccessToken(accountId, bearer);
23 return googleService(service, accessToken);
12}
13
14export default function ProfilePage({ username, name, bio, links, title }: ProfilePageProps) {
15
16 return (
10}
11
12export default function MapboxComponent({ city }: MapboxProps) {
13 const mapContainer = <div id="map" style={{ width: '100%', height: '400px' }}></div>;
14
3Pipedream offers an Accounts API to handle OAuth for you, automatically, and for free. [How to do it is covered in this guide](https://docs.val.town/integrations/google-sheets/#use-pipedreams-accounts-api).
4
5The helper functions below can make it easier to work with various Google API. For example, I used them like so to get all my free/busy times for this week from all my google calendars:
6
7```ts
11const calendar = await pipeDreamGoogle("calendar", accountId);
12
13// Function to get free/busy information
14async function getFreeBusyTimes(calendarId: string) {
15 const now = new Date();
16 const startOfWeek = new Date(now);
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI";
3
4export async function aqi(interval: Interval) {
5 const location = "46025, Benicalap, Valencia, Spain"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });
3import { zodToJsonSchema } from "npm:zod-to-json-schema";
4
5export function getSchemaDesc(schema: z.Schema) {
6 return zodToJsonSchema(schema, {
7 name: "schema",
24}
25
26export function getPathsDesc(endpoints: EndpointDefinition[]) {
27 const paths: any = {};
28 for (const endpoint of endpoints) {
61}
62
63export function getOpenApiSpec(
64 url: string,
65 title: string,
1import { postToMastodon } from "https://esm.town/v/sebdd/postToMastodon";
2
3export function testPostToMastodon() {
4 let response = postToMastodon(
5 "https://floss.social/api/v1",
6Plain, 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?
7
8Functionality is quite limited, and things might be broken. Please let me know if you find bugs!
9
10Inspired by [this HN discussion](https://news.ycombinator.com/item?id=39456467) about sites that have all possible game states of tic-tac-toe.
18}
19
20export function get(path: string) {
21 return (
22 target: (query: Record<string, string>, ctx: Context) => unknown,
37}
38
39export function post(path: string) {
40 return (target: (body: any, ctx: Context) => unknown, _context: ClassMethodDecoratorContext) => {
41 _registered.push({ method: "POST", path });
49}
50
51export function all(path: string) {
52 return (target: (ctx: Context) => unknown, _context: ClassMethodDecoratorContext) => {
53 _registered.push({ method: "*", path });
61}
62
63export function use(path: string) {
64 return (target: (ctx: Context) => unknown, _context: ClassMethodDecoratorContext) => {
65 app.use(path, async (request: Request, { params, next }) => {