Avatar

dan

Joined July 18, 2022
Likes
5
karfau avatar
testRunner
@karfau
Script
Test runner to be able to run a number of tests (e.g. on a different val). check the references for seeing how it is used. It is extracted into a val to avoid having all that clutter in the same val as your tests. Each test is a named function (which can be async), the name is used as the name for the test. the input passed as the first argument is passed to each test, great for importing assertion methods, stubs, fixed values, ... everything that you do not mutate during a test if a function is async (it returns a promise) there is a timeout of 2 seconds before the test is marked as failed. all tests are called in the declared order, but async tests run in parallel afterwards, so don't assume any order if a test starts with skip it is not executed if a test fails it throws the output, so it appears in the read box below the val and the evaluation/run is marked red if all tests pass it returns the output, so it appears in the grey box and the evaluation/run is marked green. Note: If you are using the test runner to store the result in that val, as described above, it is considered a "JSON val" and has a run button, but it also means that another of your vals could update the val with just any other (JSON) state. Alternatively you can define a function val that calls the test runner and have a separete val to keep the curretn test results, but it means after updating the tests you need to fest save that val and then reevaluate to val storing the test state.
zackoverflow avatar
lisp
@zackoverflow
Script
Lispaas (lisp as a service) A mini lisp interpreter How to use: To execute code: const result = @zackoverflow.lisp(" (+ 1 2)") To just parse and return the AST: const ast = @zackoverflow.lisp("(+ 1 2)", true) The value returned is the last expression of the program, for example: const lispResult = @zackoverflow.lisp("(+ 1 2) (+ 400 20)") console.log('Val', lispResult.val === 420) Example: Compute Fibonacci sequence let result = @zackoverflow.lisp(` (defun fib (x) (if (<= x 1) x (defun impl (i n-1 n-2) (if (= x i) (+ n-1 n-2) (impl (+ i 1) (+ n-1 n-2) n-1))) (impl 2 1 0))) (assert-eq 0 (fib 0)) (assert-eq 1 (fib 1)) (assert-eq 1 (fib 2)) (assert-eq 2 (fib 3)) (assert-eq 3 (fib 4)) (assert-eq 5 (fib 5)) (assert-eq 8 (fib 6)) (assert-eq 13 (fib 7)) `); Documentation Functions You can define a function like so: (defun hello (x) (print x)) Rest/variadic arguments are also supported (defun variable-amount-of-args (...args) (print args)) (variable-amount-of-args "Hello" "World!") Lists Define a list like so: (let ((my-list (list 1 2 3 4))) (print my-list) (print (list-get my-list 1))) Internally, a list is just a Javascript array. So indexing is O(1), but that does mean cdr requires copying (vs the linked list implementation). Plists Property lists, or records. Internally these are Javascript objects. Create a plist like so: (set null :key "Value") TODO
hootz avatar
telegramDalleBot
@hootz
Script
Telegram DALLE Bot A personal telegram bot you can message to create images with OpenAI's DALLE ✨ Set up yours fork this val speak to telegram’s https://t.me/botfather to create a bot and obtain a bot token set the bot token as a val town secret called telegramDalleBotToken add a random string as a val town secret called telegramDalleBotWebhookSecret set up your webhook with telegram like this: // paste and run this in your workspace on here @vtdocs.telegramSetWebhook(@me.secrets.telegramDalleBotToken, { url: /* your fork's express endpoint (click the three dots on a val) */, allowed_updates: ["message"], secret_token: @me.secrets.telegramDalleBotWebhookSecret, }); message your bot some prompts! (if you get stuck, you can refer to the telegram echo bot guide from docs.val.town)
rodrigotello avatar
welcomeEmail
@rodrigotello
Script
An interactive, runnable TypeScript val by rodrigotello
stevekrouse avatar
langchainEx
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
Next