Skip to content

Fix notebooks and update to nbformat v4 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 28, 2015
2,351 changes: 1,191 additions & 1,160 deletions featured/01_numpy_performance.ipynb

Large diffs are not rendered by default.

2,810 changes: 2,346 additions & 464 deletions featured/02_energy_minimization.ipynb

Large diffs are not rendered by default.

1,451 changes: 734 additions & 717 deletions featured/03_gps.ipynb

Large diffs are not rendered by default.

6,736 changes: 5,889 additions & 847 deletions featured/04_scikit.ipynb

Large diffs are not rendered by default.

820 changes: 415 additions & 405 deletions featured/05_turing.ipynb

Large diffs are not rendered by default.

1,121 changes: 561 additions & 560 deletions featured/06_vispy.ipynb

Large diffs are not rendered by default.

859 changes: 441 additions & 418 deletions notebooks/chapter01_basic/01_notebook.ipynb

Large diffs are not rendered by default.

567 changes: 287 additions & 280 deletions notebooks/chapter01_basic/02_pandas.ipynb

Large diffs are not rendered by default.

664 changes: 345 additions & 319 deletions notebooks/chapter01_basic/03_numpy.ipynb

Large diffs are not rendered by default.

474 changes: 247 additions & 227 deletions notebooks/chapter01_basic/04_magic.ipynb

Large diffs are not rendered by default.

521 changes: 268 additions & 253 deletions notebooks/chapter01_basic/05_config.ipynb

Large diffs are not rendered by default.

763 changes: 387 additions & 376 deletions notebooks/chapter01_basic/06_kernel.ipynb

Large diffs are not rendered by default.

491 changes: 254 additions & 237 deletions notebooks/chapter02_best_practices/07_unittests.ipynb

Large diffs are not rendered by default.

491 changes: 254 additions & 237 deletions notebooks/chapter02_best_practices/07_unittests_py2.ipynb

Large diffs are not rendered by default.

475 changes: 246 additions & 229 deletions notebooks/chapter03_notebook/01_blocks.ipynb

Large diffs are not rendered by default.

614 changes: 318 additions & 296 deletions notebooks/chapter03_notebook/02_nbformat.ipynb

Large diffs are not rendered by default.

319 changes: 165 additions & 154 deletions notebooks/chapter03_notebook/03_controls.ipynb
Original file line number Diff line number Diff line change
@@ -1,154 +1,165 @@
{
"metadata": {
"name": "",
"signature": "sha256:3ac8512f1eab399da758b33b61abb8225f8d6b129cf9456e316cb5e44f2bbb2c"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": [],
"source": [
"> This is one of the 100 recipes of the [IPython Cookbook](http://ipython-books.github.io/), the definitive guide to high-performance scientific computing and data science in Python.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3.3. Adding custom controls in the notebook toolbar"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The CSS and Javascript of the HTML notebook can be customized through the files in `~/.ipython/profile_default/static/custom`, where `~` is your `HOME` directory, and `default` is your IPython profile. In this short recipe, we will use this feature to add a new button in the notebook toolbar on top of every notebook. Specifically, this button renumbers linearly all code cells."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. First, we are going to inject Javascript code directly in the notebook. This is useful for testing purposes, or if you don't want your changes to be permanent. The Javascript code will be loaded with that notebook only. To do this, we can just use the `%%javascript` cell magic."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%javascript\n",
"// This function allows us to add buttons \n",
"// to the notebook toolbar.\n",
"IPython.toolbar.add_buttons_group([\n",
"{\n",
" // The button's label.\n",
" 'label': 'renumber all code cells',\n",
" \n",
" // The button's icon.\n",
" // See a list of Font-Awesome icons here:\n",
" // http://fortawesome.github.io/Font-Awesome/icons/\n",
" 'icon': 'icon-list-ol',\n",
" \n",
" // The callback function.\n",
" 'callback': function () {\n",
" \n",
" // We retrieve the lists of all cells.\n",
" var cells = IPython.notebook.get_cells();\n",
" \n",
" // We only keep the code cells.\n",
" cells = cells.filter(function(c)\n",
" {\n",
" return c instanceof IPython.CodeCell; \n",
" })\n",
" \n",
" // We set the input prompt of all code cells.\n",
" for (var i = 0; i < cells.length; i++) {\n",
" cells[i].set_input_prompt(i + 1);\n",
" }\n",
" }\n",
"}]);"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Running this code cell adds a button in the toolbar. Clicking on this button automatically updates the prompt numbers of all code cells."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. To make these changes permanent, i.e. to add this button on every notebook open within the current profile, we can open the file `~/.ipython/profile_default/static/custom/custom.js` and add the following code:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```javascript\n",
"$([IPython.events]).on('app_initialized.NotebookApp',\n",
" function(){\n",
"\n",
" // Copy of the Javascript code above (step 1).\n",
" IPython.toolbar.add_buttons_group([\n",
" {\n",
" // The button's label.\n",
" 'label': 'renumber all code cells',\n",
"\n",
" // The button's icon.\n",
" // See a list of Font-Awesome icons here:\n",
" // http://fortawesome.github.io/Font-Awesome/icons/\n",
" 'icon': 'icon-list-ol',\n",
"\n",
" // The callback function.\n",
" 'callback': function () {\n",
"\n",
" // We retrieve the lists of all cells.\n",
" var cells = IPython.notebook.get_cells();\n",
"\n",
" // We only keep the code cells.\n",
" cells = cells.filter(function(c)\n",
" {\n",
" return c instanceof IPython.CodeCell; \n",
" })\n",
"\n",
" // We set the input prompt of all code cells.\n",
" for (var i = 0; i < cells.length; i++) {\n",
" cells[i].set_input_prompt(i + 1);\n",
" }\n",
" }\n",
" }]);\n",
"});\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code put here will be automatically loaded as soon as a notebook page is loaded."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).\n",
"\n",
"> [IPython Cookbook](http://ipython-books.github.io/), by [Cyrille Rossant](http://cyrille.rossant.net), Packt Publishing, 2014 (500 pages)."
]
}
],
"metadata": {}
}
]
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> This is one of the 100 recipes of the [IPython Cookbook](http://ipython-books.github.io/), the definitive guide to high-performance scientific computing and data science in Python.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3.3. Adding custom controls in the notebook toolbar"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The CSS and Javascript of the HTML notebook can be customized through the files in `~/.ipython/profile_default/static/custom`, where `~` is your `HOME` directory, and `default` is your IPython profile. In this short recipe, we will use this feature to add a new button in the notebook toolbar on top of every notebook. Specifically, this button renumbers linearly all code cells."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. First, we are going to inject Javascript code directly in the notebook. This is useful for testing purposes, or if you don't want your changes to be permanent. The Javascript code will be loaded with that notebook only. To do this, we can just use the `%%javascript` cell magic."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%javascript\n",
"// This function allows us to add buttons \n",
"// to the notebook toolbar.\n",
"IPython.toolbar.add_buttons_group([\n",
"{\n",
" // The button's label.\n",
" 'label': 'renumber all code cells',\n",
" \n",
" // The button's icon.\n",
" // See a list of Font-Awesome icons here:\n",
" // http://fortawesome.github.io/Font-Awesome/icons/\n",
" 'icon': 'icon-list-ol',\n",
" \n",
" // The callback function.\n",
" 'callback': function () {\n",
" \n",
" // We retrieve the lists of all cells.\n",
" var cells = IPython.notebook.get_cells();\n",
" \n",
" // We only keep the code cells.\n",
" cells = cells.filter(function(c)\n",
" {\n",
" return c instanceof IPython.CodeCell; \n",
" })\n",
" \n",
" // We set the input prompt of all code cells.\n",
" for (var i = 0; i < cells.length; i++) {\n",
" cells[i].set_input_prompt(i + 1);\n",
" }\n",
" }\n",
"}]);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Running this code cell adds a button in the toolbar. Clicking on this button automatically updates the prompt numbers of all code cells."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. To make these changes permanent, i.e. to add this button on every notebook open within the current profile, we can open the file `~/.ipython/profile_default/static/custom/custom.js` and add the following code:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```javascript\n",
"$([IPython.events]).on('app_initialized.NotebookApp',\n",
" function(){\n",
"\n",
" // Copy of the Javascript code above (step 1).\n",
" IPython.toolbar.add_buttons_group([\n",
" {\n",
" // The button's label.\n",
" 'label': 'renumber all code cells',\n",
"\n",
" // The button's icon.\n",
" // See a list of Font-Awesome icons here:\n",
" // http://fortawesome.github.io/Font-Awesome/icons/\n",
" 'icon': 'icon-list-ol',\n",
"\n",
" // The callback function.\n",
" 'callback': function () {\n",
"\n",
" // We retrieve the lists of all cells.\n",
" var cells = IPython.notebook.get_cells();\n",
"\n",
" // We only keep the code cells.\n",
" cells = cells.filter(function(c)\n",
" {\n",
" return c instanceof IPython.CodeCell; \n",
" })\n",
"\n",
" // We set the input prompt of all code cells.\n",
" for (var i = 0; i < cells.length; i++) {\n",
" cells[i].set_input_prompt(i + 1);\n",
" }\n",
" }\n",
" }]);\n",
"});\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code put here will be automatically loaded as soon as a notebook page is loaded."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).\n",
"\n",
"> [IPython Cookbook](http://ipython-books.github.io/), by [Cyrille Rossant](http://cyrille.rossant.net), Packt Publishing, 2014 (500 pages)."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading