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.
singpolyma avatar
singpolyma
sendxmpplib
Script
Simple helper for sending a message over XMPP. For an API that doesn't require your own bot setup see https://www.val.town/v/singpolyma/sendxmpp import sendxmpp from "https://esm.town/v/singpolyma/sendxmpplib"; await sendxmpp("someone@example.com", "Hello!"); Also supports optional keepalive to send multiple messages with one connection: import sendxmpp from "https://esm.town/v/singpolyma/sendxmpplib"; await sendxmpp("someone@example.com", "1", true); await sendxmpp("someone@example.com", "2", true); await sendxmpp("someone@example.com", "3); Or even manual disconnect: import sendxmpp from "https://esm.town/v/singpolyma/sendxmpplib"; await sendxmpp("someone@example.com", "1", true); await sendxmpp("someone@example.com", "2", true); const stop = sendxmpp("someone@example.com", "3", true); stop(); Environment variables needed for your bot: XMPP_URI=wss://example.com XMPP_DOMAIN=example.com XMPP_USERNAME=bot XMPP_PASSWORD=password Only websockets or direct tls (xmpps://) connections are supported until https://github.com/denoland/deno/issues/26685 is fixed
0
rozek avatar
rozek
resettableQuotaTracker
Script
Public vals often use resources which have some usage limits ("quota"). Publishing such vals carries the risk that these quotas may be exceeded. For this reason, it makes sense to keep track of resource consumption and trigger a relevant response when a preset limit is reached (for example, one could provide the user with a meaningful error message). The "resettableQuotaTracker" is designed to help monitor resources that are replenished at a specific time (e.g., at a certain time each day or at the beginning of a month). Simply add an invocation of the "resettableQuotaTracker" into your val just before the tracked resource is going to be used and, from then on, that resource will be tracked and protected against excessive consumption. Usage Example Using a resettableQuotaTracker (within the val that requires the resource) is quite simple: import { resettableQuotaTracker } from 'https://esm.town/v/rozek/resettableQuotaTracker' const ResourceTable = 'xxx' // enter name of sqlite table that can be used const ResourceLimit = 10 // max. number of allowed requests before reset ;(async () => { const Tracker = await resettableQuotaTracker.new(ResourceTable,ResourceLimit) let exceeded = await Tracker.LimitExceeded() // true if quota exceeded // can be used to chech the current status await Tracker.incrementIfAllowed() // increments resource usage if allowed // or throws a "LimitExceeded" exception otherwise ... now use your resource as usual })() Simply enter the name of an sqlite table in ResourceTable where the resource consumption should be logged, and specify in ResourceLimit how many calls are allowed before the resource needs to be replenished. The "resettableQuotaTracker" is designed to be accessed simultaneously from multiple vals without interfering with each other. Resetting the consumption must be handled, for example, by a separate CRON job. import { resettableQuotaTracker } from 'https://esm.town/v/rozek/resettableQuotaTracker' const ResourceTable = '' // enter name of sqlite table that can be used ;(async () => { const Tracker = await resettableQuotaTracker.new(ResourceTable) await Tracker.reset() })() API Reference static async new (TableName:string, Limit:number=10):resettableQuotaTracker creates a new resettableQuotaTracker instance for the table TableName (which must match the RegEx pattern /^[a-z_][0-9a-z_]+$/i ). If this table does not exist yet, it will be created automatically, with Limit set as the quota ( Limit is optional and is only needed when the table is created). async isReady ():Promise<boolean> returns a Promise that resolves to true as soon as the resettableQuotaTracker is available (this is unfortunately necessary because the constructor contains asynchronous code). async reset ():Promise<void> can be used to reset the resource consumption back to 0. async Usage ():Promise<number> returns the number of counted calls so far. async Limit ():Promise<number> returns the currently configured limit. async setLimit (newLimit:number):Promise<void> can be used to configure a new limit. async LimitExceeded ():Promise<boolean> returns true if the configured limit has been reached or exceeded, or false if further calls are still allowed. async increment ():Promise<void> increases the consumption counter by 1 (even if the configured limit has already been reached). async incrementIfAllowed ():Promise<void> increases the consumption counter by 1 only if the configured limit has not yet been reached. Important: the check and the incrementing of the counter occur in the same transaction , allowing multiple resettableQuotaTracker instances to access the same table simultaneously. Tests Some tests can be found in val resettableQuotaTracker_Test
1
pomdtr avatar
pomdtr
search_user_vals
Script
This val is supposed to be used with the val.town extension. See the extension readme for installation instructions.
0
midnightlightning avatar
midnightlightning
uniswapV3Position
HTTP
An endpoint to calculate additional metadata for a Uniswap v3 liquidity position. In order to keep on-chain fees low, the Uniswap cryptocurrency exchange balances how much data it writes to the blockchain when users take out a liquidity position. Properties are saved in a few different contracts and so knowing exactly what a liquidity position entails takes a bit of additional calculation. This endpoint takes in a token identifier that represents a liquidity position, and follows the math to make the values more human-friendly. This script uses the bignumber.js library to do higher-precision floating-point math than JavaScript can do on its own with number variables. Usage Find the token ID of the Uniswap position you wish to get details about. If you own the liquidity position, you can head to https://app.uniswap.org/pool and click on the v3 position. The ID of that position will be in the URL of the details page. Append the token ID to the end of this val's URL to fetch data about it (e.g. to get information about token ID 12345 , fetch the url https://midnightlightning-uniswapv3position.web.val.run/12345 ) Reference This val fetches blockchain data from the following smart contracts: NonfungiblePositionManager( 0xc36442b4a4522e871399cd717abdd847ab11fe88 ) Manages the liquidity position tokens as an ERC721 contract. The positions function is used to determine what tokens and tick ranges the individual liquidity position has. UniswapV3Factory ( 0x1F98431c8aD98523631AE4a59f267346ea31F984 ) Contract that manages liquidity pools, and acts as a registry to record where each pairing is deployed to. The getPool function is used to find where the smart contract for a specific pairing of ERC20 tokens is deployed to. ERC20 tokens Each position has two tokens it's balancing between, and each token has its own instance of an ERC20 contract deployed to the blockchain. The name and symbol functions are used to determine how to describe each token, and the decimals function to determine how to scale the price value for the ratio between them. UniswapV3Pool Contract that handles swaps between specific pairs of tokens. The slot0 function is used to fetch the current price the two tokens are swapping at.
0
zarutian avatar
zarutian
gardland
HTTP
// til minnis: þarf að uppfæra þetta til að nota Hano
1
rozek avatar
rozek
GDI_MarkDown_Examples
Script
MarkDown Rendering Examples Which MarkDown primitives are supported and how do they look like? (edit this ReadMe in order to find out how it was written) Important: no, Val Town does not support "GitHub-flavoured" Markdown (GfM)! Level 1 Heading (followed by some plain text) Level 2 Heading (followed by some plain text) Level 3 Heading (followed by some plain text) Level 4 Heading (followed by some plain text) Level 5 Heading (followed by some plain text) Level 6 Heading (followed by some plain text) Nota bene: while heading levels 5 and 6 look useless, they still have an implied anchor which may be used in links to explicitly navigate there Paragraphs Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Text Styling (and Links) This text is italicised , and this one set in bold , in bold italics or ~~striked-through~~, but you may also superset or subset text. Links Your text may also contain links , even relative ones which navigate to other locations within the same text. Unordered Lists list item 1 list item 2 inner list item 2.1 inner list item 2.2 inner list item 2.3 list item 3 inner list item 3.1 inner list item 3.2 inner list item 3.3 list item 4 Ordered Lists list item 1 list item 2 inner list item 2.1 inner list item 2.2 inner list item 2.3 list item 3 inner list item 3.1 inner list item 3.2 inner list item 3.3 list item 4 Nota bene: in order to nest lists, inner list items have to be indentend by at least 4 spaces! ToDo Lists [x] already done [ ] still pending [x] but partially done Text Indentation Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Nota bene: text indentation does not seem to work - it looks a bit like a code paragraph Quotations Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Code You may render code inline within your text or as a separate paragraph: console.log('Hello, World!') Important: Keep in mind that you can tag code paragraphs with a (programming) language - not only for syntax highlighting, but also in order to avoid the nasty look shown in the "Text Indentation" section. Images Horizontal Lines (some text above...) (...and some text below the horizontal line) Footnotes and their Contents Your text may contain footnotes[^1]. And, while you may define the contents of your footnote anywhere in the text, it is rendered at the end only - thus, make sure, that you add a "dangling" heading! [^1]: this is just an example for a foot note Raw HTML Markup Important: You may even insert a subset of HTML into your Markdown code Unfortunately, however, e.g., iframes are not supported. References
0
augustohp avatar
augustohp
ghOrgRepos
Script
An interactive, runnable TypeScript val by augustohp
0
freecrayon avatar
freecrayon
getLatestGitCoreVersion
HTTP
An interactive, runnable TypeScript val by freecrayon
1
rwev avatar
rwev
gitlabWeeklySummary
Script
An interactive, runnable TypeScript val by rwev
0
nsafouane avatar
nsafouane
effortlessAquamarineHookworm
HTTP
@jsxImportSource https://esm.sh/react
0
janpaul123 avatar
janpaul123
valle_tmp_42249988258651369468890296933772
HTTP
// Initialize sample stories and store them in blob storage
0
pomdtr avatar
pomdtr
val_town_by_example_css
Script
An interactive, runnable TypeScript val by pomdtr
0
janpaul123 avatar
janpaul123
valle_tmp_4674518929569141580380318140624
HTTP
// Initialize sample stories and store them in blob storage
0
yawnxyz avatar
yawnxyz
valWall
HTTP
Forked from iamseeley/valcontributionchart
1
trob avatar
trob
prompt_to_code_auto_refresh_codebed
HTTP
@jsxImportSource https://esm.sh/react
1
noartem avatar
noartem
fetchGHRepoInfo
Script
An interactive, runnable TypeScript val by noartem
0