skip to main content

@tonyfast s notebooks

site navigation
notebook summary
title
pidgy literate computing
description
you've heard of interactive computing, we'll call pidgy hyperactive computing.
cells
16 total
11 code
state
executed out of order
kernel
Python [conda env:root] *
language
python
name
conda-root-py
lines of code
217
outputs
15
table of contents
  • wrap up
  • {"kernelspec": {"display_name": "Python [conda env:root] *", "language": "python", "name": "conda-root-py"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {"0cdd3616ae7148d9b7a9e5cc03606455": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "ButtonStyleModel", "state": {"font_family": null, "font_size": null, "font_style": null, "font_variant": null, "font_weight": null, "text_color": null, "text_decoration": null}}, "1894d3dfb3af4bb2bc0b35fe13c9caa2": {"model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {}}, "1d4764a587e64acca2806b97f7d77b53": {"model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {}}, "2fa3d6bb33334e87a3d887bd54d43a29": {"model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {}}, "346f75e828204a6a99793697fce30407": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "TextModel", "state": {"layout": "IPY_MODEL_a380f022d4be49dab36c8d0faa42dff5", "style": "IPY_MODEL_c79a26fbafdf4d7583411e50fb5b8ab7", "value": "tonyfast"}}, "362910cbfc0046218137a8ca774d01df": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "SliderStyleModel", "state": {"description_width": ""}}, "5a98dbb19584451987ba82069068c910": {"model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {}}, "6067e814cf3b48a9a6ef5914b8296461": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "IntSliderModel", "state": {"behavior": "drag-tap", "description": "\ud83c\udf6a", "layout": "IPY_MODEL_1d4764a587e64acca2806b97f7d77b53", "style": "IPY_MODEL_d0b69c160b3b48e594e71e6f50e27839", "value": 3}}, "63d26925db594115abbafe7ef5ecaf0a": {"model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {}}, "6aba982b84e841f3a29e199b97bb6dcb": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "SliderStyleModel", "state": {"description_width": ""}}, "878cd30fc71541cc95e9c28c59b42e17": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "ButtonModel", "state": {"description": "submit", "layout": "IPY_MODEL_2fa3d6bb33334e87a3d887bd54d43a29", "style": "IPY_MODEL_0cdd3616ae7148d9b7a9e5cc03606455", "tooltip": null}}, "9a95dd6f101b4c34a4b8dd3b0f98375a": {"model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {}}, "a380f022d4be49dab36c8d0faa42dff5": {"model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {}}, "b8adf5b6221a4567b51f836d5f566b6c": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "SliderStyleModel", "state": {"description_width": ""}}, "c6e3eac55d054bc1807e06185dacd8ef": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "IntSliderModel", "state": {"behavior": "drag-tap", "description": "show more languages", "layout": "IPY_MODEL_1894d3dfb3af4bb2bc0b35fe13c9caa2", "max": 6, "min": 1, "style": "IPY_MODEL_b8adf5b6221a4567b51f836d5f566b6c", "value": 6}}, "c79a26fbafdf4d7583411e50fb5b8ab7": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "TextStyleModel", "state": {"description_width": "", "font_size": null, "text_color": null}}, "d0b69c160b3b48e594e71e6f50e27839": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "SliderStyleModel", "state": {"description_width": ""}}, "e9e09508f39f448b8360b30a049c0119": {"model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "SliderStyleModel", "state": {"description_width": ""}}}, "version_major": 2, "version_minor": 0}}, "title": "pidgy literate computing", "description": "you've heard of interactive computing, we'll call pidgy hyperactive computing."}
    notebook toolbar
    Activate
    cell ordering
    1

    pidgy

    you've heard of interactive computing, we'll call pidgy hyperactive computing.


    this presentation is written for the february 2023 jupyter community call .[^calls]

    restart and run all or it didn't happen

    [^md]: there is massive adoption of markdown as a tool for programmers. folks can use markdown and jekyll templating languages on github pages. github profiles are written in markdown. markdown is a gateway drug to html, javascript, and css.

    [^calls]: jupyter community calls are a monthly series of events to showcase what you are doing in and with jupyter. please consider submitting to or hosting a future community call sometime

    2 1 outputs.
    # my pidgy practices always have me indenting cells.
    # this habit means code will be rendered as code in markdown.
    # https://nbviewer.org/github/deathbeds/deathbeds.github.io/blob/master/deathbeds/2018-08-03-A-case-for-indented-code.ipynb
    
    # this is a presentation about pidgy so we start by loading the extension.
    # there is a pidgy kernel for the hardcore. 
    # in that case we recommend the hybrid `.md.ipynb` extension.
    
    if LITE := (__import__("sys").platform == "emscripten"): # compatability for jupyterlite
        %pip install pandas pidgy matplotlib ipywidgets toolz
        
    # activate pidgy
    %reload_ext pidgy
    from toolz.curried import *
    
    3

    the polyglot metalanguage

    pidgy is a pidgin metalanguage of python programming and jinja templates embedded inside markdown. literate programming is that aim to craft documentation and code at the same time. literate computing is when we do this interactively, and weave live computing into the narrative.

    4 2 outputs.

    the REPL overlayed with a literate computing workflow of tangle and weave.

    flowchart LR
    
    
    
        input[markdown]--tangle\nread-->IPython
    
        IPython--eval/template-->jinja
    
        jinja--weave\nprint-->output[markdown]
    
        output[markdown]-.loop-.->input
    
        html ---> input; css ---> input; javascript ---> input
    
        julia ---> magics; r---> magics; fortran ---> magics; magics ---> IPython
    
    
    mermaid graph syntax uses extended markdown syntax provided by jupyterlab-markup
        display(extra := IntSlider(6, min=1, max=6, description="show more languages")) # 6 lines in the graph
    

    pidgy is interested in exploring the interfaces of languages in computational essays. each language provides extra syntax for telling your story. with markdown we can include html, css, and javascript; code blocks can include more languages like mermaid. IPython is our polyglot glue language .

    < /> < /> < />
    5

    inspecting and doing more with a keypress

    Ctrl + I open inspector jupyterlab-deck

    translating markdown to python

    the %%tangle magic tangles markdown to python code for previewing and debugging. this magic will help you learn pidgy s indenting heuristics and language features provided by midgy .

    6 1 outputs.
    """we use the `%%tangle` magic interactively translate the document into code.
    
    some `pidgy` features are shown below like:
        
    * markdown docstrings"""
    
    def my_function():
        """functions with markdown docstrings"""
            
        ...
    ...
            
    """* defining blocks of markdown as variables"""
    
    my_url =\
    """https://api.github.com""";
    
    7

    an homage knuth's literate programming language

    image.png

    8 1 outputs.

    a mermaid homage to the dual usage of the WEB file format being translated to a document and programming language.

    flowchart LR
        WEB--WEAVE-->TEX--TeX-->DVI
        WEB--TANGLE-->PAS--PASCAL-->REL
    
    knuth's rational for choosing Pascal; the same motivation applies to python.

    I chose PASCAL as the programming language because it has received such widespread support from educational in- stitutions all over the world; it is not my favorite language for system programming, but it has become a "second language" for so many programmers that it provides an exceptionally effective medium of communication.

    9 1 outputs.

    reactive templates

    pidgy relies on a midgy to tangle markdown to code, it does not doing any work on displaying the input markdown. including the templating language is the innovation of pidgy that inlines live computation.

    pidgy templates are asynchronous reactive display objects that place live computation directly into the narrative.

    10 1 outputs.

    worrydream's cookies demo[^inventing]

    Tangle is a JavaScript library for creating reactive documents. Your readers can interactively explore possibilities, play with parameters, and see the document update immediately. Tangle is super-simple and easy to learn.

    the source code for the first TangleJs demo

    When you eat <span data-var="cookies" class="TKAdjustableNumber"> cookies</span>,
    you consume <span data-var="calories"> calories</span>. 
    
    var tangle = new Tangle(document, {
        initialize: function () { this.cookies = 3; },
        update:     function () { this.calories = this.cookies * 50; }
    });
    
    < /> < />

    [^inventing]: many folks working on computational interfaces are inspired by Bret Victor's inventing on principle

    11 2 outputs.

    When you eat 3 cookies, you consume 150 calories.

    🍪🍪🍪

    pidgy source code using html, markdown, jinja, and ipywidgets to create interactions

    {% set calories = 50 %}<!--- we can shield variables from the global scope -->
    When you eat {{cookies.value}} cookies,
    you consume {{cookies.value * calories}} calories. 
    
    <div hidden><!--indented code is python-->
    
            display(cookies := IntSlider(3, description="🍪"))
    </div>
    
    {{"🍪" * cookies.value}}
    
    12 1 outputs.

    live data in your document

    imports for the pandas matplotlib demo
    import pandas
    from pidgy import get_cell_id
    %matplotlib agg
    
    supporting methods for the interactive demo `
    @functools.lru_cache
    def get_gist(x, max=100):
    

    gather gist from the github api .

        return pandas.read_json(F"https://api.github.com/users/{x}/gists?per_page={max}")
    
    < />
    def tidy_gist(x):
    

    explode the gist repsonse into a dataframe of gist files

        gists = get_gist(x).set_index("id")
        return gists.files.apply(compose_left(dict.values, list)).explode().apply(pandas.Series).join(gists)
    
    13 3 outputs.

    an application in a cell.

    we've found information on 100 github gists, and 121 files, for @tonyfast. in this collection, there are 6 different languages included. their most common language is Jupyter Notebook.

    filename type language raw_url size url forks_url commits_url node_id git_pull_url ... files public created_at updated_at description comments user comments_url owner truncated
    id
    3181cb04cad6e16a2add26c646893db7 moi.ipynb text/plain Jupyter Notebook https://gist.githubusercontent.com/tonyfast/31... 4814 https://api.github.com/gists/3181cb04cad6e16a2... https://api.github.com/gists/3181cb04cad6e16a2... https://api.github.com/gists/3181cb04cad6e16a2... MDQ6R2lzdDMxODFjYjA0Y2FkNmUxNmEyYWRkMjZjNjQ2OD... https://gist.github.com/3181cb04cad6e16a2add26... ... {'moi.ipynb': {'filename': 'moi.ipynb', 'type'... True 2021-05-05 16:06:56+00:00 2021-05-05 16:07:29+00:00 0 NaN https://api.github.com/gists/3181cb04cad6e16a2... {'login': 'tonyfast', 'id': 4236275, 'node_id'... False
    82e8b9744c139a63febb1a3280e91cec pluck-attachments.ipynb text/plain Jupyter Notebook https://gist.githubusercontent.com/tonyfast/82... 4843 https://api.github.com/gists/82e8b9744c139a63f... https://api.github.com/gists/82e8b9744c139a63f... https://api.github.com/gists/82e8b9744c139a63f... MDQ6R2lzdDgyZThiOTc0NGMxMzlhNjNmZWJiMWEzMjgwZT... https://gist.github.com/82e8b9744c139a63febb1a... ... {'collection-ouputs.ipynb': {'filename': 'coll... True 2021-07-02 17:01:42+00:00 2021-07-05 17:52:46+00:00 0 NaN https://api.github.com/gists/82e8b9744c139a63f... {'login': 'tonyfast', 'id': 4236275, 'node_id'... False

    2 rows × 22 columns

    display(
        _github_user := Text("tonyfast"), button := Button(description="submit"))
    button.on_click(lambda x, id=get_cell_id(): print(id) or shell.weave.displays[id].update())
    
    language Jupyter Notebook Python Text Markdown HTML JSON
    ct 84 15 9 8 2 1
    14 1 outputs.

    et

    15 1 outputs.

    wrap up

    • this presentation had a number of incidental demos.

      • jupyterlab-deck
      • jupyterlab-markup
      • voila
      • mermaid
      • midgy
    • we have on and off cells now that all of the sources are markdown

    • the template syntax is a powerful way to include python variables inline. the traditional notebook format only allows for block level literate programs.

    • since literate programs are pidgin languages we can't expect them to be formalized. there are a lot of inconsistencies with the languages combined. jinja2 template implementations vary. markdown renderers implementation vary. python keeps adding language features.



    16

    https://monoskop.org/images/b/be/Nelson_Ted_Literary_Machines_c1987_chs_0-1.pdf https://pure.au.dk/ws/files/173226224/PPIG_2019_camera_ready.pdf