Likes
72
maxm
wide
HTTP
WIDE Store any unstructured JSON data. Retrieve it with an expressive and efficient query system. WIDE is a library and service hosted on Val Town. Authenticate and use it with your Val Town credentials, or fork it and connect it to your own Clickhouse Instance. import { ValSession } from 'https://esm.town/v/maxm/valSession';
import { Wide } from 'https://esm.town/v/maxm/wide';
// Use your Val Town API Token to create a session
const wide = new Wide(await ValSession.new(Deno.env.get("valtown")))
// Write any data.
await wide.write([
{ user: {id: 1, name: 'Alice', email: 'alice@example.com' }},
{ user: {id: 2, name: 'Bob', email: 'bob@example.com' }},
{ user: {id: 3, name: 'Charlie', email: 'charlie@example.com' }},
]);
await wide.fields("user.")
// => [
// { fieldName: "user.email", fieldType: "string", count: 3 },
// { fieldName: "user.id", fieldType: "number", count: 3 },
// { fieldName: "user.name", fieldType: "string", count: 3 }
// ]
await wide.values("user.email")
// [
// { value: "bob@example.com", count: 1 },
// { value: "charlie@example.com", count: 1 },
// { value: "alice@example.com", count: 1 }
// ]
await wide.search({
start: new Date(Date.now() - 1000 * 60 * 10),
end: new Date(),
filters: [{ fieldName: "user.name", operator: "equals", value: "Alice" }],
})
// [{ user: { name: "Alice", email: "alice@example.com", id: 1 } }];
4
maxm
valSession
HTTP
Val Session import { ValSession } from "https://esm.town/v/maxm/valSession";
// Generate a token from your valtown api key.
const token = await ValSession.newSession(Deno.env.get("valtown"));
// Other services can use it to authenticate
const user = await ValSession.validate(token); Fork it, provide your own VT_SESSION_PRIVATE_KEY, and update the hardcoded public key. You can generate your own keys like so: import { crypto } from "https://deno.land/std@0.198.0/crypto/mod.ts";
// Generate a key pair for JWT signing and verification
const { privateKey, publicKey } = await crypto.subtle.generateKey(
{
name: "RSASSA-PKCS1-v1_5",
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256",
}, true, ["sign", "verify"],
);
function formatPEM(b64: string, type: "PRIVATE KEY" | "PUBLIC KEY"): string {
const lines = b64.match(/.{1,64}/g) || [];
return `-----BEGIN ${type}-----\n${lines.join("\n")}\n-----END ${type}-----`;
}
const privateKeyPem = formatPEM(
btoa(String.fromCharCode(...new Uint8Array(exportPrivateKey))),
"PRIVATE KEY",
);
const publicKeyPem = formatPEM(
btoa(String.fromCharCode(...new Uint8Array(exportPublicKey))),
"PUBLIC KEY",
);
console.log(privateKeyPem, publicKeyPem);
3
tmcw
devstats
HTTP
Developer Statistics This val lets you post statistics from your GitHub Actions runs to build charts of change over time. We do this by having a step at the end of our actions run like this: - name: devstats
run: |
curl -X "POST" "https://tmcw-devstats.web.val.run/" \
-H 'Authorization: Bearer ${{ secrets.DEVSTATS_TOKEN }}' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $"{ \"name\": \"node_modules_kb\", \"value\": $(du -sk node_modules | awk '{print $1}') }" And setting a DEVSTATS_TOKEN value, which could be any short random value, both in Val Town environment variables
and as a secret in your GitHub Actions configuration. Currently the name you attach to a statistic can be anything, and the value is expected to be a number.
4
g
countGithubLOCUI
HTTP
GitHub Line Counter π GitHub Line Counter , live on val.town ; Ever wondered how many lines of code are in a GitHub repo without the hassle of cloning it? Say hello to GitHub Line Counter β your friendly, web-based LOC inspector! π What It Does This simple tool fetches the GitHub repository as a ZIP file,
decompresses it on the fly (thanks to fflate π¨),
and counts the lines of code β on val.town
with an incredible bandwith and speed. Built with Vanilla JS on the frontend and
powered by val.town on the backend,
itβs lightweight, fast, and ready to use! How to Use Just paste the repo URL, hit "Count Lines," and watch the magic happen! β¨
2
michaelwschultz
generateframeImage
HTTP
Gathers information and returns an image of this val Why I'm using this val for my 3-color e-ink display run by a Raspberry Pi Zero W. The Pi runs a cron job that tell's it
to fetch this url twice a day and render it to the display. Works like a charm. Right now I'm not displaying much but I'm going to keep iterating on what type of information I want to display. How I'll post more info on my set up here later if you want to try something similar. But I assume this workflow could
be used for lot's of different projects that don't have a ton of compute or where you don't want to learn how to
actually draw things to a screen like all the e-ink display libraries.
1
maxm
eval
Script
Eval web demo Security Caveats This code runs in a Worker with { permissions: { write: false, read: false, net: false } } . This is likely very safe, but if you enable network access keep in mind that users might generate junk network traffic or attempt to make infinite loops. If sandboxed code knows the name of one of your private vals it will be able to import the code with import "https://esm.town/v/maxm/private" . If you enabled write: true in the Worker, the unix socket that Deno uses to communicate with the host can be deleted and intercepted. This might mean that evaluated code can steal the socket and read the next request. You should not use this to evaluate code that should not be read by a previous evaluation. All code is running on the same process and you are not protected from exotic attacks like speculative execution. Overview You can use this library to evaluate code: import { evalCode } from "https://esm.town/maxm/eval"
console.log(await evalCode("export const foo = 1")) // => 1 You can use this library with https://www.val.town/v/maxm/transformEvalCode to return the last value without needing to export it. This is how the /eval api endpoint used to work and makes the library preform similarly to a repl. import { evalCode } from "https://esm.town/maxm/eval"
import { transform } from "https://esm.town/maxm/transformEvalCode"
console.log(await evalCode(transform("1+1"))) // => 2 Here's an example UI application that demonstrates how you can string this all together: https://maxm-evalui.web.val.run/ (source: https://www.val.town/v/maxm/evalUI) Security Model Code is evaluated using a dynamic import within a Worker. await import(`data:text/tsx,${encodeURIComponent(e.data)}`); Running the code withing a Worker prevents access to GlobalThis and window from leaking between evals. Similarly, access to Deno.env is prevented and evaluations will see errors when trying to access any environment variables. TODO: what else?
4
begoon
thisval
Script
This val default exports a function returning ValInfo. The val information comes from the Deno stack trace induced by throw new Error() . type ValInfo = {
stack: string[]; // mostly for debugging
endpoint: string; // val endpoint URL, empty if it is not an HTTP val
user: string; // val.town user name
name: string; // val name
}; Here is an example program: import thisval from "https://esm.town/v/begoon/thisval";
const val = thisval();
export default async function(req: Request): Promise<Response> {
return Response.json(val);
} when invoked, it returns: {
"stack": [
"Error",
" at info (https://esm.town/v/begoon/thisval?v=12:10:11)",
" at https://esm.town/v/begoon/thisvaltest?v=2:3:13"
],
"endpoint": "begoon-thisvaltest.web.val.run",
"user": "begoon",
"name": "thisvaltest"
}
2
jdan
dialog
HTTP
dialog Renders windows 98 dialog boxes as SVGs. Using satori and styles from 98.css Usage https://jdan-dialog.web.val.run/? w =200& h =110& title =Hello& caption =World w (default: 200): the width of the dialog h (default: 110): the height of the dialog title (default: "{title}"): the text in the title bar caption (default: "{caption}"): the caption text
3
neverstew
superchargedQueryParams
Script
β‘ Supercharge your query params Tired of the old x=y query param limitations?
Ever wished you could say x>y or x!=y as well? Now you can! Parse query params with superchargedQueryParams and you get an array of operations for each parameter instead: import { superchargeQueryParams } from "https://esm.town/v/neverstew/superchargeQueryParams";
console.log(superchargeQueryParams(new URL("https://example.com?a=b&c>d&e!=f&e>=g")))
// {"a":[{"eq":"b"}],"c":[{"gt":"d"}],"e":[{"ne":"f"},{"gte":"g"}]}
1