Avatar

pomdtr

I mainly enjoy building dev tools: - VS Code integration: https://github.com/pomdtr/valtown-vscode - CLI: https://github.com/pomdtr/vt
Joined June 14, 2023
Public vals
317
pomdtr avatar
pomdtr
ask_ai
Script
Ask gpt to update a val on your behalf Usage import { askAI } from "https://esm.town/v/pomdtr/ask_ai"; await askAI(`Add jsdoc comments for each exported function of the val @pomdtr/askAi`);
1
pomdtr avatar
pomdtr
example_article
HTTP
Searching valtown via sql, jq, jo In a recent discussion, a useful command line pipeline was shared for querying a database and processing the results. The original command looked like this: echo "SELECT * FROM vals WHERE lower(name) LIKE '%feed%' and lower(name) like '%email%' LIMIT 100" | jq -R '{args: [.]} ' | xargs -0 -I {} curl -X POST "https://sqlite-execute.web.val.run" -H "Content-Type: application/json" -d {} | yq -P This command effectively queries a database for records matching certain criteria and processes the results. However, there are several ways this pipeline can be improved for efficiency and clarity. Recommendations for Improvement Elimination of xargs for stdin input in curl : Instead of using xargs to pass input from stdin, curl supports -d '@-' where @ means file and - means stdin. This simplifies the command. Use of --json flag in curl : Recent versions of curl support the --json flag, which automatically sets the correct HTTP headers for JSON content. This allows for a more straightforward command. Avoid explicit setting of HTTP method in curl : Explicitly setting the HTTP method (e.g., -X POST ) is considered bad practice when using data, form, and/or json flags. This is because it's unnecessary and can lead to unexpected side effects when more than one request is made behind the scenes. Use of jo for JSON payload creation: While jq can be used to create a JSON payload, it's more common and cleaner to use jo for this purpose. jo is specifically designed for creating JSON objects and arrays. Improved Command Examples Using the recommendations above, the command can be rewritten as follows: $ jo args="$(jo -a "SELECT * FROM vals WHERE lower(name) LIKE '%feed%' and lower(name) like '%email%' LIMIT 100")" \ | curl -s --json '@-' 'https://sqlite-execute.web.val.run' This command uses jo to create the JSON payload and then passes it to curl using the --json flag for processing. For keeping the SQL statement as input to the pipeline, the command can be further refined: $ echo "SELECT * FROM vals WHERE lower(name) LIKE '%feed%' and lower(name) like '%email%' LIMIT 100" \ | jo -a '@-' \ | jo args=':-' \ | curl -s --json '@-' 'https://sqlite-execute.web.val.run' In this version, @- means treat stdin as a string, and :- means treat stdin as JSON, allowing for dynamic input directly into the JSON payload. Additional Resources For those looking to deepen their understanding of curl and its capabilities, especially with JSON, it's highly recommended to read through Everything curl . This online book is full of useful tricks and insights that can significantly enhance one's command line data processing skills. References https://discord.com/channels/1020432421243592714/1221021689627017236 https://chatcraft.org/api/share/tarasglek/7B_nXLYazAyEryn4Z9Yz0 https://github.com/neverstew/valtown-search/
0
pomdtr avatar
pomdtr
test_trpc
Script
An interactive, runnable TypeScript val by pomdtr
0
pomdtr avatar
pomdtr
trpc
Script
trpc Access private Val Town apis. ⚠️ trpc endpoints can change at any time Available Procedures (WIP) Queries search getVal getValMetadata getValLastLogs Mutations deleteVal updateReadme togglePrivacy updateVal toggleLike run updateInterval stopInterval
3
pomdtr avatar
pomdtr
harlequinChinchilla
Script
[ ] Test @bot [ ] Test
0
pomdtr avatar
pomdtr
mdx_import
HTTP
Importing a readme from another readme 🤯 import Readme from "https://pomdtr-mdx_readme.web.val.run/mod.js"
1
pomdtr avatar
pomdtr
mdx_readme
HTTP
⚠️ This readme is only readable from the val http endpoint import msg from "https://esm.town/v/pomdtr/msg" import {capitalize} from "https://esm.sh/lodash-es" export const title = "mdx rendered from a val readme" {capitalize(title)} {msg}
2
pomdtr avatar
pomdtr
mdx
HTTP
title: mdx {frontmatter.title} Usage import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo"; import { mdx } from "https://esm.town/v/pomdtr/mdx"; const { author, name } = extractValInfo(import.meta.url); export default mdx(author, name);
1
pomdtr avatar
pomdtr
aliasValExample
Script
An interactive, runnable TypeScript val by pomdtr
0
pomdtr avatar
pomdtr
aliasExample
Script
An interactive, runnable TypeScript val by pomdtr
0
pomdtr avatar
pomdtr
console
Script
// console.time("time");
0
pomdtr avatar
pomdtr
http_client_component
Script
@jsxImportSource https://esm.sh/preact
0
pomdtr avatar
pomdtr
http_client
HTTP
HTTP Client Attach a postman-like http client to your vals, with bookmarks and history support Usage Wrap your http handler in an the httpClient middleware. import {httpClient} from "https://esm.town/v/pomdtr/http_client" export default httpClient((req) => { return new Response("Hello World!") }) The http client will be shown on the root. Adding bookmarks You might want to bookmark some requests you need often. You can do it by passing a bookmark list as a middleware option: import {httpClient} from "https://esm.town/v/pomdtr/http_client" export default httpClient((req) => { return new Response("Hello World!") }, { bookmarks: [ { "label": "Dummy Request", "request": new Request("https://dummyjson.com/products") } ]}) Customizing the client path import {httpClient} from "https://esm.town/v/pomdtr/http_client" export default httpClient((req) => { return new Response("Hello World!") }, { path: "/http-client" }) TODO [ ] fix syntax highlighting on successive request [ ] allow to prefill the initial request
7
pomdtr avatar
pomdtr
brownBoar
Script
An interactive, runnable TypeScript val by pomdtr
0
pomdtr avatar
pomdtr
guest
HTTP
An interactive, runnable TypeScript val by pomdtr
0
pomdtr avatar
pomdtr
preact_test_component
Script
@jsxImportSource https://esm.sh/preact
0