Avatar

maas

3 public vals
Joined March 2, 2023

Imports Gists to Val Town

Import your TypeScript and JavaScript to Val Town

import-gists.png

Authentication

This function requires two keys: one from Github to get your gists, and one from Val Town to make the vals in your account:

  1. Github token: https://github.com/settings/tokens
  2. Val Town key: https://www.val.town/settings/api

Usage

You can use this function by calling it and passing your keys like so:

@maas.importGists({
  githubToken: @me.secrets.githubGists,
  valTownKey: @me.secrets.valtown,
});

Example usage: https://www.val.town/v/maas.untitled_harlequinCrawdad

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { createVal } from "https://esm.town/v/stevekrouse/createVal?v=2";
export const importGists = (async ({ githubToken, valTownKey }: {
githubToken: string;
valTownKey: string;
}) => {
const supportedLanguages = ["JavaScript", "TypeScript"];
let imported = [];
const headers = { "X-GitHub-Api-Version": "2022-11-28" };
const { Octokit } = await import("npm:@octokit/core");
const octokit = new Octokit({ auth: githubToken });
let { data } = await octokit.request("GET /gists", { headers });
for (let i in data) {
let files = Object.values(data[i].files);
let { filename, language } = files[0];
if (!supportedLanguages.includes(language)) {
continue;
}
let gist = await octokit.request("GET /gists/{gist_id}", {
gist_id: data[i].id,
});
let { content } = Object.values(gist.data.files)[0];
createVal({ code: content, valTownKey: valTownKey });
imported.push(filename);
}
return `Imported ${imported.length} vals (${
imported.join(", ")
}) from GitHub Gists.`;
});

Unlimited Anonymous Emails

All code can be triggered via email (docs), i.e. maas.forwarder@valtown.email. You can generate as many emails as you want to avoid giving away your personal email address and reduce spam.

Getting started

  1. Log in to Val Town
  2. Fork this Val
  3. Publish the Val via 🔒 > Unlisted
  4. Copy the email endpoint via ⋮ > Endpoints > Copy email address
  5. Sign up for newsletters or services using this email (maas.forwarder@valtown.email).

To remove their ability to email you, simply delete the val (or send it to /dev/null).

1
2
3
4
5
6
7
8
9
export function forwarder(e: {
from: string;
to: string[];
subject: string;
text: string;
html: string;
}) {
console.email({ html: e.html, subject: e.subject });
}
1
export let beep = "boop";
Next