├── extensions ├── __init__.py ├── disable_autoscroll.py ├── print_page.py ├── msgmagic.py ├── reprrequests.py ├── editmate.py ├── nbtoc.html ├── closure.py ├── abstraction.py ├── pretty_func_repr.py ├── inactive.py ├── jinjasolution.py ├── namespaces.py ├── nbtoc.js ├── nbtoc.py ├── pil_display.py ├── nbinput.py ├── retina.py ├── inspector.py ├── timers.py ├── autosave.py └── writeandexecute.py ├── .gitignore ├── nbextensions ├── dontsaveoutput.js ├── restart-run-all-no-exceptions.js ├── editor-tabs.js ├── toc.css ├── qtconsole-button.js ├── renumber-button.js ├── celltags.js ├── toc.js ├── gist.js └── inorder.js ├── COPYING.BSD └── README.md /extensions/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | # Packages 3 | *.egg 4 | *.egg-info 5 | dist 6 | build 7 | eggs 8 | parts 9 | bin 10 | var 11 | sdist 12 | develop-eggs 13 | .installed.cfg 14 | .ipynb_checkpoints 15 | 16 | # Installer logs 17 | pip-log.txt 18 | 19 | mathjax 20 | contrib 21 | 22 | # Unit test / coverage reports 23 | .coverage 24 | .tox 25 | 26 | #Translations 27 | *.mo 28 | 29 | #Mr Developer 30 | .mr.developer.cfg 31 | -------------------------------------------------------------------------------- /extensions/disable_autoscroll.py: -------------------------------------------------------------------------------- 1 | """ 2 | Extension for disabling autoscrolling long output, which is super annoying sometimes 3 | 4 | Usage: 5 | 6 | %load_ext disable_autoscroll 7 | 8 | You can also put the js snippet below in profile_dir/static/js/custom.js 9 | """ 10 | 11 | from IPython.display import display, Javascript 12 | 13 | disable_js = """ 14 | IPython.OutputArea.prototype._should_scroll = function(lines) { 15 | return false; 16 | } 17 | """ 18 | 19 | def load_ipython_extension(ip): 20 | display(Javascript(disable_js)) 21 | print ("autoscrolling long output is disabled") 22 | -------------------------------------------------------------------------------- /extensions/print_page.py: -------------------------------------------------------------------------------- 1 | """Disable the IPython notebook pager 2 | 3 | turn paged output into print statements 4 | """ 5 | 6 | from __future__ import print_function 7 | from IPython.core import page 8 | 9 | _save_page = None 10 | 11 | def load_ipython_extension(ip): 12 | global _save_page 13 | if not hasattr(ip, 'kernel'): 14 | # not in a kernel, nothing to do 15 | return 16 | ip.set_hook('show_in_pager', page.as_hook(page.display_page), 90) 17 | 18 | def unload_ipython_extension(ip): 19 | if hasattr(ip, 'display_page'): 20 | ip.display_page = _save_page 21 | -------------------------------------------------------------------------------- /extensions/msgmagic.py: -------------------------------------------------------------------------------- 1 | """ 2 | Illustration of a configurable Magics class 3 | 4 | To use: 5 | 6 | %load_ext msgmagic 7 | %msg 8 | %config MsgMagic 9 | %config MsgMagic.message = "Hello, there!" 10 | %msg 11 | """ 12 | from IPython.config import Configurable 13 | from IPython.core.magic import magics_class, Magics, line_magic 14 | 15 | from IPython.utils.traitlets import Unicode 16 | 17 | @magics_class 18 | class MsgMagic(Magics, Configurable): 19 | message = Unicode("my message", config=True, help="The message printed by `%msg`") 20 | 21 | def __init__(self, shell): 22 | Configurable.__init__(self, parent=shell) 23 | Magics.__init__(self, shell) 24 | # this adds me to the `%config` list: 25 | shell.configurables.append(self) 26 | 27 | @line_magic 28 | def msg(self, line): 29 | print(self.message) 30 | 31 | def load_ipython_extension(ip): 32 | ip.magics_manager.register(MsgMagic) 33 | -------------------------------------------------------------------------------- /extensions/reprrequests.py: -------------------------------------------------------------------------------- 1 | def repr_request(r, p, cycle): 2 | p.text('{} {}\n'.format(r.status_code, r.url)) 3 | p.text('headers: ') 4 | for name in sorted(r.headers): 5 | p.text(' {}: {}\n'.format(name, r.headers[name])) 6 | p.text('\nbody ({}):\n'.format(r.headers.get('content-type', 'unknown'))) 7 | try: 8 | p.pretty(r.json()) 9 | except ValueError: 10 | try: 11 | if len(r.text) > 1024: 12 | p.text(r.text[:1024]) 13 | p.text('...[%i bytes]' % len(r.content)) 14 | else: 15 | p.text(r.text) 16 | except Exception: 17 | if len(r.content) > 1024: 18 | p.pretty(r.content[:1024]) 19 | p.text('...[%i bytes]' % len(r.content)) 20 | else: 21 | p.pretty(r.content) 22 | 23 | def load_ipython_extension(ip): 24 | ip.display_formatter.formatters['text/plain'].for_type('requests.models.Response', repr_request) 25 | -------------------------------------------------------------------------------- /extensions/editmate.py: -------------------------------------------------------------------------------- 1 | """ 2 | Use TextMate as the editor 3 | 4 | THIS EXTENSION IS OBSOLETE 5 | 6 | Usage: %load_ext editmate 7 | 8 | Now when you %edit something, it opens in textmate. 9 | This is only necessary because the textmate command-line entrypoint 10 | doesn't support the +L format for linenumbers, it uses `-l L`. 11 | 12 | """ 13 | 14 | from subprocess import Popen, list2cmdline 15 | from IPython.core.error import TryNext 16 | 17 | def edit_in_textmate(self, filename, linenum=None, wait=True): 18 | cmd = ['mate'] 19 | if wait: 20 | cmd.append('-w') 21 | if linenum is not None: 22 | cmd.extend(['-l', str(linenum)]) 23 | cmd.append(filename) 24 | 25 | proc = Popen(list2cmdline(cmd), shell=True) 26 | if wait and proc.wait() != 0: 27 | raise TryNext() 28 | 29 | def load_ipython_extension(ip): 30 | try: 31 | from IPython.lib.editorhooks import mate 32 | except ImportError: 33 | ip.set_hook('editor', edit_in_textmate) 34 | else: 35 | mate() 36 | -------------------------------------------------------------------------------- /nbextensions/dontsaveoutput.js: -------------------------------------------------------------------------------- 1 | // Remove outputs from saved data. 2 | // Saves bandwidth on slow connections, etc. 3 | // THIS IS DESTRUCTIVE in that opening a notebook and saving it will delete your output data. 4 | // 5 | // install me with 6 | // jupyter nbextension install [url-to-this-file] 7 | // and enable me with 8 | // jupyter nbextension enable dontsaveoutput 9 | 10 | 11 | define(["notebook/js/notebook"], function (notebook) { 12 | "use strict"; 13 | function load () { 14 | var origToJSON = notebook.Notebook.prototype.toJSON; 15 | notebook.Notebook.prototype.toJSON = function () { 16 | var data = origToJSON.apply(this); 17 | console.log("Deleting outputs prior to save."); 18 | data.cells.map(function (cell) { 19 | if (cell.cell_type == 'code') { 20 | // clear outputs so we don't save them 21 | cell.outputs = []; 22 | } 23 | }); 24 | return data; 25 | }; 26 | } 27 | 28 | return { 29 | load_ipython_extension: load 30 | }; 31 | }); 32 | -------------------------------------------------------------------------------- /nbextensions/restart-run-all-no-exceptions.js: -------------------------------------------------------------------------------- 1 | // Add Restart & Run All (no exceptions) item to Kernel menu 2 | // Same as Restart & Run All, but continue execution on exception 3 | 4 | define(function (require, exports, module) { 5 | "use strict"; 6 | var $ = require('jquery'); 7 | var Jupyter = require('base/js/namespace'); 8 | 9 | function restart_run_all_no_exceptions() { 10 | var nb = Jupyter.notebook; 11 | return nb.restart_kernel().then(function () { 12 | nb.get_cells().map(function (cell) { 13 | cell.execute(false); 14 | }); 15 | }); 16 | } 17 | 18 | function load_extension () { 19 | // add menu entry 20 | $('li#restart_run_all').before( 21 | $('