Interactive code executing in TiddlyGit (like IPython notebook)

This is something like IPython notebook. It uses google/zx to execute scripts locally, so this plugin has to be used in TiddlyGit , which provides a worker thread that runs zx in nodejs.

I will try to refactor it to be a standalone nodejs tw plugin, so people have tw server can use it too.

屏幕录制2021-09-18 01.37.42

Each code block in tid or md file can be executed, you can click “ZX” button on the right of the code block to run them and see results showing below the code block.

You can also click on “conch” icon on the view tools bar, which executes the whole tiddler. If execution output is in tid format, it will be rendered as it is a real tiddler.

Currently, no output will be saved as a real tiddler, except you use fetch API to create a new tiddler, via nodejs HTTP API.

6 Likes

@linonetwo - this is amazing!
is there any restriction on type of codes one can run?

It is limited by zx, it only accept javascript, markdown (I make it accept tiddler too), and shell script.

If I port it to be a standalone plugin (so it can run without tiddlygit), then these 3 language will be what it can run. (But I think I will bring Python with tiddlygit in the future, so it may execute python in the future too.

1 Like

Wow, this is awesome! I’ve been thinking idly about something like this for a while, but thought it was way too complicated to be practical. Apparently not.

1 Like

Due to interest in Developer demo of alternate wiki store implementation by Jermolene · Pull Request #7329 · Jermolene/TiddlyWiki5 · GitHub,

v0.8.0-prerelease11 of TidGi has a better-sqlite3 instance at $tw.utils.Sqlite. Which is accessable for server side plugin. (TidGi is a launcher for nodejs wiki)

And there is a predefined table TidGi-Desktop/index.ts at 5651ea70c6301bbabacf45126b84a60b630b3a4b · tiddly-gittly/TidGi-Desktop · GitHub

CREATE TABLE IF NOT EXISTS tiddlers (
          title TEXT PRIMARY KEY,
          text TEXT,
          type TEXT,
          created INTEGER,
          modified INTEGER,
          tags TEXT,
          fields TEXT,
          creator TEXT,
          modifier TEXT
          );

You can try this from wiki frontent using zx

Github: tiddly-gittly/zx-script
Doc: github pages

Usage is like

// pure nodejs context
console.log(`## Hi!`);
let aaa = 3;

/** tw */

// now in worker_thread with $tw wiki access

let filterExample = $tw.wiki.filterOperators.sum((callback) => {callback({}, String(aaa));callback({}, String(aaa))})
console.log(filterExample)

// use Sqlite
const db = $tw.utils.Sqlite
const stmt = db.prepare('SELECT title, text FROM tiddlers');
const result = stmt.pluck().all()
console.log(result)

click this icon to execute zx script

See $:/plugins/linonetwo/zx-script in plugin list for more usage. For example it says only code after /** tw */ can access $tw

Download a TidGi, and upgrade this plugin in CPL to try out.

1 Like

I just stumble upon this project:

But I guess it’s more cool is we use other languages with WASM, like this project is doing:

or maybe insert the jupyterlite as a new plugin is an option?

Python support is tracked in Provide python environment · Issue #344 · tiddly-gittly/TidGi-Desktop · GitHub

Maybe implemented in 3-5 years!