nbbaier avatar
nbbaier
vtIdeaAggregator
HTTP
Forked from pomdtr/blog
2
pomdtr avatar
pomdtr
blog
HTTP
Val Town Blog A blog written, developed and hosted on val.town. How ? Each article on this blog is contained single val, with a #blog tag. See this example article . // #blog // title: Example Post import { article } from "https://esm.town/v/pomdtr/article"; import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo"; import { html } from "https://esm.town/v/stevekrouse/html?v=5"; export async function examplePost(req: Request) { const { author, name } = extractValInfo(import.meta.url); return html(await article(author, name)); } Each of these post work on it's own . This val is able to: list them with the /v1/search api (with a #blog query) post with different author than the owner of this val will be filtered out only public vals will be listed render the readme of those vals using remark (with github styling) This process run each time a user visit the web endpoint , so the blog is always up to date. You can get your own instance of the blog by just forking this val .
3
pomdtr avatar
pomdtr
page
HTTP
Render a val readme Inspired by github pages. Use https://pomdtr-page.web.val.run/v/<author>/<name> Example You can see this val readme at https://pomdtr-page.web.val.run/v/pomdtr/readme
1
pomdtr avatar
pomdtr
exampleArticle
HTTP
Example Article More detail on the discovery mechanism here . Fork this val to create a new post!
0
nbbaier avatar
nbbaier
vtIdeaList
HTTP
Vals I Want to Build A running list of things I want to build on Val Town, hosted in a Val Town readme . [ ] A bare bones CMS to edit markdown files hosted on a github (or val town readmes eventually) [ ] A set of Vals for interacting with github repos via Octokit (useful for the above CMS idea) [ ] A full json-server like implementation for quickly generating stub APIs based on json/valtown blob data ( begun ) [ ] An implementation of Convert bookmarklet to Chrome extension [ ] A tool for generating an NPM package from a Val or set of Vals (something like [dnt]- [ ] (https://github.com/denoland/dnt/)) [ ] An email handler for forwarding emails to Tana [ ] A component library (this would be a wild swing for me) [ ] A val to get a dependency graph of a val(s) ( started here by rlesser ) [ ] A single val that wraps a FeTS client to the API for saving a couple of lines of boilerplate [ ] A val for generating OpenAPI specs from jsdoc comments within vals (sort of like this npm package ) [ ] Conways game of life pst, if you want to see stuff I would love to see built right into Val Town, here you go
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
nbbaier avatar
nbbaier
vtIdeasTemplate
HTTP
Forked from nbbaier/vtIdeaList
0
nbbaier avatar
nbbaier
metadata
Script
An interactive, runnable TypeScript val by nbbaier
0
1
Next
pomdtr-article.web.val.run
Updated: May 6, 2024