Elixir Livebook is a secret weapon for documentation
fly.io
fly.io
In the same "standing on giant's shoulders" stance, you can use Explorer (see example LiveBook at https://github.com/elixir-explorer/explorer/blob/main/notebo...), which leverages Polars (https://www.pola.rs), a very fast DataFrame library and now a company (https://www.pola.rs/posts/company-announcement/) with 4M$ seed.
They are useful for unit testing code like libraries, providing usage examples for end-users (as well as the text format markdown usually supports) and testing it at the same time. Definitely a great idea for documentation, and one which I should use more of.
Wow!
I built this tool to let people generate evergreen markdown documentation from annotated type-safe YAML integration tests:
To anyone curious, I highly recommend:
- https://hitchdev.com/hitchstory/approach/
- https://hitchdev.com/hitchstory/why-not/
From the overall RDD/BDD type home page:
- https://hitchdev.com/hitchstory/
The entire product site is a thing of richly informative beauty.
---
My only question was whether the generated 'docs' snippets would add value over just reading the story in your DASL. Any markdown site generator (such as the chosen Material for MKDocs) can just embed the ```yaml anyway. But then I realized what was generating e.g. …
- https://hitchdev.com/hitchstory/using/engine/rewrite-story/
… and how superior that is to typical docs, especially typical docstring or swagger factories.
I've been working on something like this for Kotlin using a compiler plugin that allows code to access the source text of lambdas, functions and classes being executed. You write code that spits out markdown and captures its own source into code blocks.
You can write inline examples in your docstrings and they’re automatically turned into unit tests. So again you get that documentation as an executable test suite not subject to rot, but at a per-function level. Same kind of idea but different levels of the documentation stack.
- Elixir's scripting makes it super easy to write a one-liner that tests a function, that'd be a lot more verbose in many other languages
- You need the docs tool and unit tests tools to 'speak the same language' to make it work, and for whatever reason Elixir devs don't seem as intent on reinventing tools like those as some other languages
However, do I understand it correctly that this allows me to output verified, working code in my test suite, but its not a tool that I can embed in my docs to create runnable code samples? (which is what the OP is showing).
super valuable either way, just trying to validate understanding.
I'm not aware of anything exactly like Livebook in the Kotlin ecosystem but you might be interested in kotlinx-knit which takers a more incremental approach to executable documentation:
https://github.com/Kotlin/kotlinx-knit
Neither of these approaches will result in interactive documentation.
It's one of my favorite tools.
Installing it directly is a bit complicated if you are not familiar with it. I wish linux also had Desktop app like mac.
You might have to Google how to read a file in Elixir, but you don't actually need to know Elixir.
In the future, you won't even need to know that to use it.
Mind blown.gif
:)
Here's an example. Note in the first paragraph a link to the post as a livemd file: https://genericjam.com/blog/image-processing
If you go through the steps, you'll notice that the livemd isn't stylized as a blog post. This is where the next opportunity lies: creating beautiful blog posts as livebooks, and without the need to install and run a livebook server locally.
Mix.install(
[
{:my_app, path: Path.join(__DIR__, ".."), env: :dev}
],
config_path: :my_app,
lockfile: :my_app
)
(The above snippet assumes a notebook located within a `notebooks/` directory, as per the article.)Alternatively, you can connect to a running instance, e.g. a Phoenix project:
$ elixir --sname my-app --cookie cookie -S mix phx.server
$ LIVEBOOK_DEFAULT_RUNTIME=attached:my-app:cookie livebook server- it’s collaborative (think Google docs for code) when several people are working on the same instance of a livebook;
- it’s easy to extend with so-called smart cells (which are essentially pieces of gui you can inject in your document https://news.livebook.dev/v0.6-automate-and-learn-with-smart... ). Smart cells are available for various tasks (db connection/ interaction, data frame exploration, ML tasks, maps), and building your own is relatively easy;
- you can turn a notebook into a web app ( https://news.livebook.dev/deploy-notebooks-as-apps-quality-o... )
- you can run your code an a remote elixir node by attaching to it (although this requires some knowledge of distributed elixir/erlang )
[1] https://github.com/jonatanklosko/notebooks/blob/main/article... [2] https://github.com/livebook-dev/livebook/blob/main/lib/liveb...
It requires you to run a far less common tech stack and limits your hiring to a vanishingly small subset of developers.
Paradoxically, that may be a good thing.
Jupyter outputs JSON.
For Markdown Docs, Markdown Blogs, and JSX-static pages
- https://docusaurus.io/docs/next/api/themes/@docusaurus/theme...
I'm not sure to understand what you mean by "Docusaurus is static". Docusaurus builds static pages and allows you to plug JS/React code anywhere in your docs, so it's quite interactive and can run anything that can run in a browser, including REPLs.
I read the Fly article but still don't really understand what Livebook is about. They say they use Livebook themselves, but the examples linked to only display a regular non-interactive doc to me.
Do you have any production url showing me an experience that is possible in Livebook, and impossible in Docusaurus?
Imagine the following.
<here's a code block containing project metadata>
we click a play button to start an elixir runtime based on that metadata code block
<here's a "component" that securely connects to an elixir system running in a kubernetes pod in production, exposing an elixir REPL to interact with it>
with this component, we then issue commands to inspect state, manage elixir "processes" in the runtime, etc
Can you show a concrete example? IE a real production url running this?
What is "metadata"?
In Docusaurus you can have a live playground evaluating on your browser, or you can embed any embeddable playground if it requires a server integration.
> with this component, we then issue commands to inspect state, manage elixir "processes" in the runtime, etc
Another example would be useful.
So this is just an embedded widget to interact with something remote? Why can't this be built as a React component that you can add to any Docusaurus page?
---
It looks to me that you don't need maintainer knowledge to build that, and React knowledge is enough.
The code blocks need to be run in sequence, from top-down, as one builds on the next. The "metadata" at the very top often describes the project and its dependencies.
Can someone show me a real production url of what is possible to achieve in Livebook and impossible/difficult to achieve with other tools?
I'm the Docusaurus maintainer, and making your docs interactive, and giving the ability to run the documented project inside its doc does not feel like something new.
Connecting to some proper SQL database is a breeze, but if I cannot access some silo'ed data that is absilute critical, its not that useful after all :-/
But on the topic: I think its a simple problem ultimately, the SF Api (https://developer.salesforce.com/docs/atlas.en-us.api_rest.m...) needs OAuth, which needs a redirect at some point, where I have no idea how to capture it from a livebook instance (easy in a phx app).
This is a reference lib in JS ( https://jsforce.github.io/ ) and there seems to be no maintained alternative on hex.pm unfortunately. So, from scratch it seems, somehow.
Additional insight: many big companies do use salesforce, and its internal tooling to produce reports/insights is rather limited, but there is a SQL-like language to do complicated stuff, but there is no way to execute a handwritten query in SF itself, except via API calls from outside. This... would be a perfect fit fro livebook! query SF + other databases to generate a report ad-hoc thats not easily possible right now without adding some heavyweight data warehouse connection!
If this is something you would like to work on, please reach out, I think it could open up interesting possibilities!
See: https://gist.github.com/Anonyfox/3f36c26fb00a9bc4067d6dc9c9a...
I sound totally dumb now to bitch about it, but glad I could solve it in like 1 hour in a sufficient way
Don't get me wrong, I love org babel but there are some advantages of the browser based approach.
There are still some rough edges -- it would be nice if livebook could cache prerendered content. for example, kino graphs only chuck a big fat JSON into a html comment, it would be nice if it also popped out an svg or encoded png with data uri.