Github API examples & templates
Use these vals as a playground to view and fork Github API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
pomdtr
sql
Script
SQL Template Tag Port of blakeembrey/sql-template-tag for usage in val.town. Usage import { sqlite } from "https://esm.town/v/std/sqlite"
import { sql, zip } from "https://esm.town/v/pomdtr/sql"
const query = sql`SELECT * FROM books WHERE author = ${author}`;
console.log(query.sql) // => "SELECT * FROM books WHERE author = ?"
console.log(query.args) // => [author]
const res = await sqlite.execute(query)
console.table(zip(res)) For advanced usage (ex: nesting queries), refer to the project readme .
6
tmcw
punycodeExample
Script
punycode punycode is so cool. It's esoteric, but like, it's amazing what ingenuity can do. It's an encoding of UTF-8 - the kind of text with easy representations for unicode sequences like ñ - in ASCII - the one that just supports English. It does this in a way that's reversible, and lets us use UTF8 text in ASCII places, because you can also detect when something is written in punycode. Do you need this, probably not – but someday you will, and you will remember.
0
sammeltassen
iiif44tu
HTTP
IIIF Presentation API for 4TU.ResearchData . URL scheme: https://sammeltassen-iiif44tu.web.val.run/[datasetUUID] Examples: https://sammeltassen-iiif44tu.web.val.run/e3f72cb2-9432-4ae9-a353-67f22dbab590 https://sammeltassen-iiif44tu.web.val.run/9a2b38e4-e87f-4600-8fe1-1989f4155b1d If the dataset is private you need to create a token and include it as a query param: https://sammeltassen-iiif44tu.web.val.run/[datasetUUID]?token=[token] If no uuid is provided the val currently defaults to one of my private datasets used for testing... Todo: Add more metadata from the Djehuty API response. Limitations: This is a temporary workaround until the Presentation API is implemented as part of Djehuty Only images are currently supported (not video/audio) The val needs to do some API requests before producing the manifest and doesn't cache responses Credits: Image API implementation by Roel Janssen of 4TU.ResearchData. The source code can be found here IIIF Builder by Stephen Fraser
0
postpostscript
interruptibleChain
Script
interruptibleChain: simple interface for pausing and resuming execution chains ⚠️ Moved to GitHub ⚠️ import { $chain } from "https://esm.town/v/postpostscript/interruptibleChain";
const multiply = $chain()
.then(() => 1)
.then((x) => x + 3)
.then(async (x) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
return x * 2;
});
const handle = multiply.init();
console.log(await handle.untilDone());
// { done: true, value: 8, handle: InterruptibleChainHandle { ... } }
const handle2 = multiply.init({
index: 2,
value: 4,
});
await handle2.advance();
console.log(handle2.done, handle2.state);
// true { index: 3, value: 8 }
/**** Interrupts ****/
const handle3 = $chain().then(() => {
throw new Error("failed");
}).init();
await handle3.advance();
console.log(handle3.done, handle3.interrupt);
// false Interrupt { reason: Error: failed, chain: InterruptibleChain { index: 0 } }
console.log(await handle3.untilDone());
// { done: false, interrupt: Interrupt { ... }, handle: InterruptibleChainHandle { ... } }
const handle4 = $chain().then((_, interrupt) => {
return interrupt("call me later");
}).init();
await handle4.advance()
console.log(handle4.done, handle4.interrupt);
// false Interrupt { reason: "call me later", chain: InterruptibleChain { index: 0 } }
0
std
turso
Script
Deprecated in favor of std/sqlite (also powered by Turso) std/turso was the initial version of our integration with Turso. It was so popular, we rebuilt it to be faster and easier to use: std/sqlite . Turso is a serverless SQLite platform designed for the edge. It runs libSQL , their open contribution fork of SQLite. Every Val Town user automatically gets their own Turso SQLite database! It's great for >100kb data (ie bigger than a val) or when you need SQL: relations, ACID transactions, etc. Storage used in Turso will count against your Val Town total storage (10mb for free users; 1gb for Pro users). Contact us if you'd need more – it should be no problem! Getting started This val uses our public key auth scheme . Generate your keypair On your publicKey click the lock icon🔒 to change the permissions to Unlisted . Fork this helper function replacing stevekrouse with your own username Try out some queries! Usage This val returns a Turso SDK's Client , which supports execute , batch , and transaction . await @me.turso().execute(`create table blobs(
key text unique,
value text
)`) More example usage Architecture This @std.turso function is the client or SDK to @std.tursoAPI, which acts as a "proxy" to Turso. It handles authentication, creates databases, and forwards on your SQL queries. You can get lower latency (~200ms vs ~800ms), more storage, databases, CLI & API access by having your own Turso account.
7