Skip to content

Commit 15df7c7

Browse files
committed
Merge pull request ipython-books#16 from ipython-books/nbfv4
Fix notebooks and update to nbformat v4
2 parents 22436d2 + 24b5ee3 commit 15df7c7

File tree

110 files changed

+41418
-29222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+41418
-29222
lines changed

featured/01_numpy_performance.ipynb

Lines changed: 1191 additions & 1160 deletions
Large diffs are not rendered by default.

featured/02_energy_minimization.ipynb

Lines changed: 2346 additions & 464 deletions
Large diffs are not rendered by default.

featured/03_gps.ipynb

Lines changed: 734 additions & 717 deletions
Large diffs are not rendered by default.

featured/04_scikit.ipynb

Lines changed: 5889 additions & 847 deletions
Large diffs are not rendered by default.

featured/05_turing.ipynb

Lines changed: 415 additions & 405 deletions
Large diffs are not rendered by default.

featured/06_vispy.ipynb

Lines changed: 561 additions & 560 deletions
Large diffs are not rendered by default.

notebooks/chapter01_basic/01_notebook.ipynb

Lines changed: 441 additions & 418 deletions
Large diffs are not rendered by default.

notebooks/chapter01_basic/02_pandas.ipynb

Lines changed: 287 additions & 280 deletions
Large diffs are not rendered by default.

notebooks/chapter01_basic/03_numpy.ipynb

Lines changed: 345 additions & 319 deletions
Large diffs are not rendered by default.

notebooks/chapter01_basic/04_magic.ipynb

Lines changed: 247 additions & 227 deletions
Large diffs are not rendered by default.

notebooks/chapter01_basic/05_config.ipynb

Lines changed: 268 additions & 253 deletions
Large diffs are not rendered by default.

notebooks/chapter01_basic/06_kernel.ipynb

Lines changed: 387 additions & 376 deletions
Large diffs are not rendered by default.

notebooks/chapter02_best_practices/07_unittests.ipynb

Lines changed: 254 additions & 237 deletions
Large diffs are not rendered by default.

notebooks/chapter02_best_practices/07_unittests_py2.ipynb

Lines changed: 254 additions & 237 deletions
Large diffs are not rendered by default.

notebooks/chapter03_notebook/01_blocks.ipynb

Lines changed: 246 additions & 229 deletions
Large diffs are not rendered by default.

notebooks/chapter03_notebook/02_nbformat.ipynb

Lines changed: 318 additions & 296 deletions
Large diffs are not rendered by default.
Lines changed: 165 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,165 @@
1-
{
2-
"metadata": {
3-
"name": "",
4-
"signature": "sha256:3ac8512f1eab399da758b33b61abb8225f8d6b129cf9456e316cb5e44f2bbb2c"
5-
},
6-
"nbformat": 3,
7-
"nbformat_minor": 0,
8-
"worksheets": [
9-
{
10-
"cells": [
11-
{
12-
"cell_type": "markdown",
13-
"metadata": [],
14-
"source": [
15-
"> 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"
16-
]
17-
},
18-
{
19-
"cell_type": "markdown",
20-
"metadata": {},
21-
"source": [
22-
"# 3.3. Adding custom controls in the notebook toolbar"
23-
]
24-
},
25-
{
26-
"cell_type": "markdown",
27-
"metadata": {},
28-
"source": [
29-
"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."
30-
]
31-
},
32-
{
33-
"cell_type": "markdown",
34-
"metadata": {},
35-
"source": [
36-
"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."
37-
]
38-
},
39-
{
40-
"cell_type": "code",
41-
"collapsed": false,
42-
"input": [
43-
"%%javascript\n",
44-
"// This function allows us to add buttons \n",
45-
"// to the notebook toolbar.\n",
46-
"IPython.toolbar.add_buttons_group([\n",
47-
"{\n",
48-
" // The button's label.\n",
49-
" 'label': 'renumber all code cells',\n",
50-
" \n",
51-
" // The button's icon.\n",
52-
" // See a list of Font-Awesome icons here:\n",
53-
" // http://fortawesome.github.io/Font-Awesome/icons/\n",
54-
" 'icon': 'icon-list-ol',\n",
55-
" \n",
56-
" // The callback function.\n",
57-
" 'callback': function () {\n",
58-
" \n",
59-
" // We retrieve the lists of all cells.\n",
60-
" var cells = IPython.notebook.get_cells();\n",
61-
" \n",
62-
" // We only keep the code cells.\n",
63-
" cells = cells.filter(function(c)\n",
64-
" {\n",
65-
" return c instanceof IPython.CodeCell; \n",
66-
" })\n",
67-
" \n",
68-
" // We set the input prompt of all code cells.\n",
69-
" for (var i = 0; i < cells.length; i++) {\n",
70-
" cells[i].set_input_prompt(i + 1);\n",
71-
" }\n",
72-
" }\n",
73-
"}]);"
74-
],
75-
"language": "python",
76-
"metadata": {},
77-
"outputs": []
78-
},
79-
{
80-
"cell_type": "markdown",
81-
"metadata": {},
82-
"source": [
83-
"Running this code cell adds a button in the toolbar. Clicking on this button automatically updates the prompt numbers of all code cells."
84-
]
85-
},
86-
{
87-
"cell_type": "markdown",
88-
"metadata": {},
89-
"source": [
90-
"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:"
91-
]
92-
},
93-
{
94-
"cell_type": "markdown",
95-
"metadata": {},
96-
"source": [
97-
"```javascript\n",
98-
"$([IPython.events]).on('app_initialized.NotebookApp',\n",
99-
" function(){\n",
100-
"\n",
101-
" // Copy of the Javascript code above (step 1).\n",
102-
" IPython.toolbar.add_buttons_group([\n",
103-
" {\n",
104-
" // The button's label.\n",
105-
" 'label': 'renumber all code cells',\n",
106-
"\n",
107-
" // The button's icon.\n",
108-
" // See a list of Font-Awesome icons here:\n",
109-
" // http://fortawesome.github.io/Font-Awesome/icons/\n",
110-
" 'icon': 'icon-list-ol',\n",
111-
"\n",
112-
" // The callback function.\n",
113-
" 'callback': function () {\n",
114-
"\n",
115-
" // We retrieve the lists of all cells.\n",
116-
" var cells = IPython.notebook.get_cells();\n",
117-
"\n",
118-
" // We only keep the code cells.\n",
119-
" cells = cells.filter(function(c)\n",
120-
" {\n",
121-
" return c instanceof IPython.CodeCell; \n",
122-
" })\n",
123-
"\n",
124-
" // We set the input prompt of all code cells.\n",
125-
" for (var i = 0; i < cells.length; i++) {\n",
126-
" cells[i].set_input_prompt(i + 1);\n",
127-
" }\n",
128-
" }\n",
129-
" }]);\n",
130-
"});\n",
131-
"```"
132-
]
133-
},
134-
{
135-
"cell_type": "markdown",
136-
"metadata": {},
137-
"source": [
138-
"The code put here will be automatically loaded as soon as a notebook page is loaded."
139-
]
140-
},
141-
{
142-
"cell_type": "markdown",
143-
"metadata": {},
144-
"source": [
145-
"> You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).\n",
146-
"\n",
147-
"> [IPython Cookbook](http://ipython-books.github.io/), by [Cyrille Rossant](http://cyrille.rossant.net), Packt Publishing, 2014 (500 pages)."
148-
]
149-
}
150-
],
151-
"metadata": {}
152-
}
153-
]
154-
}
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"> 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"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"# 3.3. Adding custom controls in the notebook toolbar"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"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."
22+
]
23+
},
24+
{
25+
"cell_type": "markdown",
26+
"metadata": {},
27+
"source": [
28+
"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."
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {
35+
"collapsed": false
36+
},
37+
"outputs": [],
38+
"source": [
39+
"%%javascript\n",
40+
"// This function allows us to add buttons \n",
41+
"// to the notebook toolbar.\n",
42+
"IPython.toolbar.add_buttons_group([\n",
43+
"{\n",
44+
" // The button's label.\n",
45+
" 'label': 'renumber all code cells',\n",
46+
" \n",
47+
" // The button's icon.\n",
48+
" // See a list of Font-Awesome icons here:\n",
49+
" // http://fortawesome.github.io/Font-Awesome/icons/\n",
50+
" 'icon': 'icon-list-ol',\n",
51+
" \n",
52+
" // The callback function.\n",
53+
" 'callback': function () {\n",
54+
" \n",
55+
" // We retrieve the lists of all cells.\n",
56+
" var cells = IPython.notebook.get_cells();\n",
57+
" \n",
58+
" // We only keep the code cells.\n",
59+
" cells = cells.filter(function(c)\n",
60+
" {\n",
61+
" return c instanceof IPython.CodeCell; \n",
62+
" })\n",
63+
" \n",
64+
" // We set the input prompt of all code cells.\n",
65+
" for (var i = 0; i < cells.length; i++) {\n",
66+
" cells[i].set_input_prompt(i + 1);\n",
67+
" }\n",
68+
" }\n",
69+
"}]);"
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"Running this code cell adds a button in the toolbar. Clicking on this button automatically updates the prompt numbers of all code cells."
77+
]
78+
},
79+
{
80+
"cell_type": "markdown",
81+
"metadata": {},
82+
"source": [
83+
"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:"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"metadata": {},
89+
"source": [
90+
"```javascript\n",
91+
"$([IPython.events]).on('app_initialized.NotebookApp',\n",
92+
" function(){\n",
93+
"\n",
94+
" // Copy of the Javascript code above (step 1).\n",
95+
" IPython.toolbar.add_buttons_group([\n",
96+
" {\n",
97+
" // The button's label.\n",
98+
" 'label': 'renumber all code cells',\n",
99+
"\n",
100+
" // The button's icon.\n",
101+
" // See a list of Font-Awesome icons here:\n",
102+
" // http://fortawesome.github.io/Font-Awesome/icons/\n",
103+
" 'icon': 'icon-list-ol',\n",
104+
"\n",
105+
" // The callback function.\n",
106+
" 'callback': function () {\n",
107+
"\n",
108+
" // We retrieve the lists of all cells.\n",
109+
" var cells = IPython.notebook.get_cells();\n",
110+
"\n",
111+
" // We only keep the code cells.\n",
112+
" cells = cells.filter(function(c)\n",
113+
" {\n",
114+
" return c instanceof IPython.CodeCell; \n",
115+
" })\n",
116+
"\n",
117+
" // We set the input prompt of all code cells.\n",
118+
" for (var i = 0; i < cells.length; i++) {\n",
119+
" cells[i].set_input_prompt(i + 1);\n",
120+
" }\n",
121+
" }\n",
122+
" }]);\n",
123+
"});\n",
124+
"```"
125+
]
126+
},
127+
{
128+
"cell_type": "markdown",
129+
"metadata": {},
130+
"source": [
131+
"The code put here will be automatically loaded as soon as a notebook page is loaded."
132+
]
133+
},
134+
{
135+
"cell_type": "markdown",
136+
"metadata": {},
137+
"source": [
138+
"> You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).\n",
139+
"\n",
140+
"> [IPython Cookbook](http://ipython-books.github.io/), by [Cyrille Rossant](http://cyrille.rossant.net), Packt Publishing, 2014 (500 pages)."
141+
]
142+
}
143+
],
144+
"metadata": {
145+
"kernelspec": {
146+
"display_name": "Python 3",
147+
"language": "python",
148+
"name": "python3"
149+
},
150+
"language_info": {
151+
"codemirror_mode": {
152+
"name": "ipython",
153+
"version": 3
154+
},
155+
"file_extension": ".py",
156+
"mimetype": "text/x-python",
157+
"name": "python",
158+
"nbconvert_exporter": "python",
159+
"pygments_lexer": "ipython3",
160+
"version": "3.4.2"
161+
}
162+
},
163+
"nbformat": 4,
164+
"nbformat_minor": 0
165+
}

0 commit comments

Comments
 (0)