Back to APIs list

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.
maxm avatar
imageMagickWasmExample
@maxm
Script
Val Town implementation of the magick-wasm demo: https://github.com/dlemstra/magick-wasm/blob/main/demo/demo.ts Outputs: ImageMagick 7.1.1-30 Q8 x86_64 dd459b01f:20240407 https://imagemagick.org Delegates: freetype heic jng jp2 jpeg jxl lcms lqr openexr png raw tiff webp xml zlib Features: Cipher Quantum: 8 GIF 100x75 8-bit sRGB 2679
pomdtr avatar
sql
@pomdtr
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 .
maxm avatar
tinygoWasmHelloWorld
@maxm
HTTP (deprecated)
Tinygo Wasm Example Go Source: package main import ( "fmt" "net/http" gotown "github.com/maxmcd/go-town" ) func main() { gotown.ListenAndServe(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World") })) } Built with: deno run --allow-net --allow-run --allow-read \ "https://esm.town/v/maxm/compileAndUploadTinygoWasm?v=58"
austinm911 avatar
scheduledNotifier
@austinm911
Cron
Forked from pranjaldotdev/poller
Olive avatar
dailyDadJoke
@Olive
Cron
Forked from stevekrouse/dailyDadJoke
pomdtr avatar
example_article
@pomdtr
HTTP (deprecated)
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/
nbbaier avatar
fetchPaginatedData
@nbbaier
Script
Forked from stevekrouse/fetchJSON
natashatherobot avatar
blob
@natashatherobot
Script
Forked from std/blob
pomdtr avatar
add_jsdoc_action
@pomdtr
Script
Add JSDoc comment to any val This val is supposed to be used with the val.town chrome extension . Add this field to your config to use it: export default [ { title: "Add JSDoc comments", val: "pomdtr/add_jsdoc_action", patterns: ["https://www.val.town/v/:author/:name"], }, // ... ]
stevekrouse avatar
autoGPTPrompt
@stevekrouse
Script
// fork from https://github.com/Torantulino/Auto-GPT/blob/master/scripts/data/prompt.txt
yawnxyz avatar
shapeshift
@yawnxyz
Script
Forked from substrate/shapeshift
d3vobed avatar
valledrawclient
@d3vobed
Script
Forked from janpaul123/valledrawclient
boson avatar
blackLobster
@boson
Cron
Forked from kingishb/blackLobster
pomdtr avatar
freeformServer
@pomdtr
HTTP (deprecated)
Freeform Brings a taste of Observable to Val Town. This val was adapted from @tmcw obsidian plugin . Instead of using the display function, this port use export default . https://pomdtr-freeformServer.web.val.run/v/<author>/<name> or https://freeform.pomdtr.me/v/<author>/<name> Examples Bar Chart ( View Source )
maxm avatar
pgliteCounter
@maxm
HTTP
Forked from samwillis/pglite_http_preview_runtime
stevekrouse avatar
jsonresumeEx
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse