<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Notebook snippets"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TODO**:\n",
    "* howto avoid loosing matplotlib interactive rendering when a document is converted to HTML ?\n",
    "  * https://www.reddit.com/r/IPython/comments/36p360/try_matplotlib_notebook_for_interactive_plots/\n",
    "  * http://stackoverflow.com/questions/36151181/exporting-interactive-jupyter-notebook-to-html\n",
    "  * https://jakevdp.github.io/blog/2013/12/05/static-interactive-widgets/\n",
    "* table of contents (JS)\n",
    "* matplotlib / D3.js interaction\n",
    "* matplotlib animations: how to make it faster\n",
    "* inspiration\n",
    "  * http://louistiao.me/posts/notebooks/embedding-matplotlib-animations-in-jupyter-notebooks/\n",
    "  * https://github.com/ltiao/notebooks\n",
    "  * https://blog.dominodatalab.com/lesser-known-ways-of-using-notebooks/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%html\n",
    "<div id=\"toc\"></div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%javascript\n",
    "var toc = document.getElementById(\"toc\");\n",
    "toc.innerHTML = \"<b>Table of contents:</b>\";\n",
    "toc.innerHTML += \"<ol>\"\n",
    "\n",
    "var h2_list = document.getElementsByTagName(\"h2\");\n",
    "for (var i = 0; i < h2_list.length; i++) {\n",
    "    var h2 = h2_list[i];\n",
    "    var h2_str = h2.textContent.slice(0, -1);  // \"slice(0, -1)\" remove the last character \n",
    "    toc.innerHTML += \"<li><a href=\\\"#\" + h2_str.replace(/\\s+/g, '-') + \"\\\">\" + h2_str + \"</a></li>\";\n",
    "}\n",
    "\n",
    "toc.innerHTML += \"</ol>\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Import directives"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "\n",
    "# As an alternative, one may use: %pylab notebook\n",
    "\n",
    "# For old Matplotlib and Ipython versions, use the non-interactive version:\n",
    "# %matplotlib inline or %pylab inline\n",
    "\n",
    "# To ignore warnings (http://stackoverflow.com/questions/9031783/hide-all-warnings-in-ipython)\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "import math\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import ipywidgets\n",
    "from ipywidgets import interact"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Useful keyboard shortcuts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Enter **edit mode**: Enter\n",
    "* Enter **command mode**: Escape\n",
    "\n",
    "In **command** mode:\n",
    "\n",
    "* Show keyboard shortcuts: h\n",
    "\n",
    "\n",
    "* Insert a cell above the selection: a\n",
    "* Insert a cell below the selection: b\n",
    "* Switch to Markdown: m\n",
    "\n",
    "\n",
    "* Delete the selected cells: dd (type twice 'd' quickly)\n",
    "* Undo cell deletion: z\n",
    "\n",
    "\n",
    "* Execute the selected cell: Ctrl + Enter\n",
    "* Execute the selected cell and select the next cell: Shift + Enter\n",
    "* Execute the selected cell and insert below: Alt + Enter\n",
    "\n",
    "\n",
    "* Toggle output: o\n",
    "* Toggle line number: l\n",
    "\n",
    "\n",
    "* Copy selected cells: c\n",
    "* Paste copied cells below: v\n",
    "\n",
    "\n",
    "* Select the previous cell: k\n",
    "* Select the next cell: j\n",
    "\n",
    "In **edit** mode:\n",
    "\n",
    "* Code completion or indent: Tab\n",
    "* Tooltip: Shift + Tab\n",
    "    * Type \"Shift + Tab\" twice to see the online documentation of the selected element\n",
    "    * Type \"Shift + Tab\" 4 times to the online documentation in a dedicated frame\n",
    "\n",
    "\n",
    "* Indent: \u2318]  (on MacOS)\n",
    "* Dedent: \u2318[  (on MacOS)\n",
    "\n",
    "\n",
    "* Execute the selected cell: Ctrl + Enter\n",
    "* Execute the selected cell and select the next cell: Shift + Enter\n",
    "* Execute the selected cell and insert below: Alt + Enter\n",
    "\n",
    "\n",
    "* Cut a cell at the current cursor position: Ctrl + Shift + -"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Matplotlib"
   ]<commit_msg>Misc updates.<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Notebook snippets, tips and tricks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TODO**:\n",
    "* Read https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/\n",
    "* Read http://blog.juliusschulz.de/blog/ultimate-ipython-notebook\n",
    "* howto avoid loosing matplotlib interactive rendering when a document is converted to HTML ?\n",
    "  * https://www.reddit.com/r/IPython/comments/36p360/try_matplotlib_notebook_for_interactive_plots/\n",
    "  * http://stackoverflow.com/questions/36151181/exporting-interactive-jupyter-notebook-to-html\n",
    "  * https://jakevdp.github.io/blog/2013/12/05/static-interactive-widgets/\n",
    "* table of contents (JS)\n",
    "* matplotlib / D3.js interaction\n",
    "* matplotlib animations: how to make it faster\n",
    "* inspiration\n",
    "  * http://louistiao.me/posts/notebooks/embedding-matplotlib-animations-in-jupyter-notebooks/\n",
    "  * https://github.com/ltiao/notebooks\n",
    "  * https://blog.dominodatalab.com/lesser-known-ways-of-using-notebooks/\n",
    "* Howto make (personalized) Reveal.js slides from this notebook: https://forum.poppy-project.org/t/utiliser-jupyter-pour-des-presentations-etape-par-etape-use-jupyter-to-present-step-by-step/2271/2\n",
    "* See https://blog.dominodatalab.com/lesser-known-ways-of-using-notebooks/\n",
    "\n",
    "Extension wishlist and todo:\n",
    "- Table of content\n",
    "- Hide some blocks in the HTML export\n",
    "    - See https://github.com/jupyter/notebook/issues/534\n",
    "- Customize CSS in HTML export\n",
    "- Add disqus in HTML export\n",
    "    - See: https://github.com/jupyter/nbviewer/issues/80\n",
    "    - Example: http://nbviewer.jupyter.org/gist/tonyfast/977184c1243287e7e55e\n",
    "- Add metadata header/footer (initial publication date, last revision date, author, email, website, license, ...)\n",
    "- Vim like editor/navigation shortcut keys (search, search+edit, ...)\n",
    "- Spell checking\n",
    "    - See https://github.com/ipython/ipython/issues/3216#issuecomment-59507673 and http://www.simulkade.com/posts/2015-04-07-spell-checking-in-jupyter-notebooks.html\n",
    "    \n",
    "Inspiration:\n",
    "- https://github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-Jupyter-Notebooks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%html\n",
    "<div id=\"toc\"></div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%javascript\n",
    "var toc = document.getElementById(\"toc\");\n",
    "toc.innerHTML = \"<b>Table of contents:</b>\";\n",
    "toc.innerHTML += \"<ol>\"\n",
    "\n",
    "var h2_list = document.getElementsByTagName(\"h2\");\n",
    "for (var i = 0; i < h2_list.length; i++) {\n",
    "    var h2 = h2_list[i];\n",
    "    var h2_str = h2.textContent.slice(0, -1);  // \"slice(0, -1)\" remove the last character \n",
    "    toc.innerHTML += \"<li><a href=\\\"#\" + h2_str.replace(/\\s+/g, '-') + \"\\\">\" + h2_str + \"</a></li>\";\n",
    "}\n",
    "\n",
    "toc.innerHTML += \"</ol>\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Import directives"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "\n",
    "# As an alternative, one may use: %pylab notebook\n",
    "\n",
    "# For old Matplotlib and Ipython versions, use the non-interactive version:\n",
    "# %matplotlib inline or %pylab inline\n",
    "\n",
    "# To ignore warnings (http://stackoverflow.com/questions/9031783/hide-all-warnings-in-ipython)\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "import math\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import ipywidgets\n",
    "from ipywidgets import interact"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Useful keyboard shortcuts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Enter **edit mode**: Enter\n",
    "* Enter **command mode**: Escape\n",
    "\n",
    "In **command** mode:\n",
    "\n",
    "* Show keyboard shortcuts: h\n",
    "\n",
    "\n",
    "* Find and replace: f\n",
    "\n",
    "\n",
    "* Insert a cell above the selection: a\n",
    "* Insert a cell below the selection: b\n",
    "* Switch to Markdown: m\n",
    "\n",
    "\n",
    "* Delete the selected cells: dd (type twice 'd' quickly)\n",
    "* Undo cell deletion: z\n",
    "\n",
    "\n",
    "* Execute the selected cell: Ctrl + Enter\n",
    "* Execute the selected cell and select the next cell: Shift + Enter\n",
    "* Execute the selected cell and insert below: Alt + Enter\n",
    "\n",
    "\n",
    "* Toggle output: o\n",
    "* Toggle line number: l\n",
    "\n",
    "\n",
    "* Copy selected cells: c\n",
    "* Paste copied cells below: v\n",
    "\n",
    "\n",
    "* Select the previous cell: k\n",
    "* Select the next cell: j\n",
    "\n",
    "In **edit** mode:\n",
    "\n",
    "* Code completion or indent: Tab\n",
    "* Tooltip: Shift + Tab\n",
    "    * Type \"Shift + Tab\" twice to see the online documentation of the selected element\n",
    "    * Type \"Shift + Tab\" 4 times to the online documentation in a dedicated frame\n",
    "\n",
    "\n",
    "* Indent: ⌘]  (on MacOS)\n",
    "* Dedent: ⌘[  (on MacOS)\n",
    "\n",
    "\n",
    "* Execute the selected cell: Ctrl + Enter\n",
    "* Execute the selected cell and select the next cell: Shift + Enter\n",
    "* Execute the selected cell and insert below: Alt + Enter\n",
    "\n",
    "\n",
    "* Cut a cell at the current cursor position: Ctrl + Shift + -"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Matplotlib"
   ]
{'fraction_non_alphanumeric': 0.20422405876951333, 'fraction_numerical': 0.013039485766758493, 'mean_word_length': 2.522315653298836, 'pattern_counts': {'":': 74, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 15, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, '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}}
{'dir': 'git-commits-cleaned', 'id': '7289565', 'n_tokens_mistral': 4117, 'n_tokens_neox': 4048, 'n_words': 887}