skip to main content

@tonyfast s notebooks

site navigation
notebook summary
title
adding shell and css fence directives to midgy
description
some markdown code fences in midgy have transpile code with functions that operate on the contents of the fence. for example, toml, json, and yaml fences will load the string into python object. this post talks about the subprocess fences.
cells
9 total
6 code
state
executed out of order
kernel
Python [conda env:p311] *
language
python
name
conda-env-p311-py
lines of code
52
outputs
9
table of contents
{"kernelspec": {"display_name": "Python [conda env:p311] *", "language": "python", "name": "conda-env-p311-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.11.3"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {}, "version_major": 2, "version_minor": 0}}, "title": "adding shell and css fence directives to midgy", "description": "some markdown code fences in midgy have transpile code with functions that operate on the contents of the fence. for example, toml, json, and yaml fences will load the string into python object. this post talks about the subprocess fences."}
notebook toolbar
Activate
cell ordering
1

adding shell and css fence directives to midgy

some markdown code fences in midgy have transpile code with functions that operate on the contents of the fence. for example, toml , json , and yaml fences will load the string into python object. this post talks about the subprocess fences.

all of these behaviors can be turned off using ~~~ fences

2
    import midgy, pandas, json
1 outputs.
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[82], line 1
----> 1 import midgy, pandas, jsons

ModuleNotFoundError: No module named 'jsons'
3 1 outputs.
{'description': 'passed throught toml.loads'}
4

IPython exposes ! syntactic sugar to process shell commands. we use this code fence syntax to trigger shell commands.

5 2 outputs.

whats the date?

print\
date

see how this is similar to the IPython version following?

!date
Mon Feb 26 01:13:49 PM PST 2024

Mon Feb 26 01:13:49 PM PST 2024

6 2 outputs.

the advantange though is that with this version we run blocks of bash

print\
echo "one fish"
echo "two fish"

which is strikingly similar the IPython %%bash magic

%%bash
echo "red fish"
echo "blue fish"

the outputs can be stored as variables in both these forms.

one fish
two fish

red fish
blue fish

7

more examples

8 1 outputs.

maybe we want to work with out git history as a pandas series?

log = pandas.Series(

git log
    .splitlines())
log.groupby(log.str.extract("commit\s+(?P<commit>\S+)").ffill().commit).apply(
    lambda s: "".join(s.iloc[3:])
).to_frame("msg")
9 2 outputs.

maybe we want to search some json using jq and explore it interactively

display({"application/json":
        json.loads(
jq  .cells[0] Untitled10.ipynb
)}, raw=True)