<jupyter_start><jupyter_text>Jigsaw in IPythonThis notebook demonstrates using the %jigsaw magic in IPython.Dependencies:1. system running IPython or Jupyter2. [metakernel](https://github.com/Calysto/metakernel) OverviewJigsaw is a combination of Google's Blockly drag-and-drop interface in the browser with Python. With Jigsaw, you can:* do many Python tasks in the block-only view* have access to predefined Python variables* create functions and variables in Jigsaw, but use them in Python cellsTo use in IPython, you need to add the metakernel magics for IPython:<jupyter_code>from metakernel import register_ipython_magics
register_ipython_magics()<jupyter_output><empty_output><jupyter_text>Next, let's define some Python things:<jupyter_code>x = 42
def myfunc(a, b):
    return a + b<jupyter_output><empty_output><jupyter_text>Now, we create a Jigsaw workspace named "workspace1". This will create two files in this subdirectory:1. workspace1.html2. workspace1.xmlOnce you have the Jigsaw workspace showing, then you can start dragging blocks around:<jupyter_code>%jigsaw Python --workspace workspace1<jupyter_output><empty_output><jupyter_text>In the above example, I pulled a print block from the Text category on the left, and a variable block from the Variables category. Snapping them together forms a valid program. I then clicked on the "Run" button to run the code. x got its value from the Python cell above.Let's create another workspace:<jupyter_code>%jigsaw Python --workspace workspace2<jupyter_output><empty_output><jupyter_text>In the above example, I dragged the following blocks:    1. print from Text2. expression from Python3. set ... to from Variables4. sqrt(2) from MathI had to click on the set block and create a new variable named "sqrt_two". I also had to click on the math constant block to change pi to sqrt(2).If you click on the "Generate Python Code" it will create a new cell below:<jupyter_code>import math


print((myfunc(5, 6)))
sqrt_two = math.sqrt(2)<jupyter_output><empty_output><jupyter_text>If you enter the variable named "sqrt_two" in the following cell and run it, you get as output the result from running the Jigsaw blocks:<jupyter_code>sqrt_two<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06783468104222821, 'fraction_numerical': 0.008984725965858042, 'mean_word_length': 5.959375, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '569899', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 671, 'n_tokens_neox': 656, 'n_words': 272, 'path': 'examples/Jigsaw in IPython.ipynb', 'repo_name': 'jnahmias/metakernel', 'size': '2226'}