Skip to content

Instantly share code, notes, and snippets.

@parente
Last active January 27, 2016 14:18
Show Gist options
  • Save parente/587e2bc8b335e90d890b to your computer and use it in GitHub Desktop.
Save parente/587e2bc8b335e90d890b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Gist on Demand\n\nOn-the-fly recipe for using [minrk's gist extension](https://github.com/minrk/ipython_extensions/) on a Jupyter Notebook server (>=v4.0)."
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "import notebook.nbextensions",
"execution_count": 4,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Install to the user directory where we should have access."
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "notebook.nbextensions.install_nbextension('https://rawgithub.com/minrk/ipython_extensions/master/nbextensions/gist.js', \n user=True)",
"execution_count": 5,
"outputs": [
{
"text": "downloading https://rawgithub.com/minrk/ipython_extensions/master/nbextensions/gist.js to /tmp/tmpvleoz37l/gist.js\ncopying /tmp/tmpvleoz37l/gist.js -> /home/jovyan/.local/share/jupyter/nbextensions/gist.js\n",
"name": "stdout",
"output_type": "stream"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Enable the extension right away."
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "%%javascript\nJupyter.utils.load_extensions('gist')",
"execution_count": 6,
"outputs": [
{
"metadata": {},
"data": {
"application/javascript": "Jupyter.utils.load_extensions('gist')",
"text/plain": "<IPython.core.display.Javascript object>"
},
"output_type": "display_data"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Then:\n\n1. Get a [personal access token from GitHub](https://github.com/settings/tokens) that has *gist* permissions.\n2. Click the <i class=\"fa-share fa\"></i> share button in the toolbar.\n3. Enter your access token when prompted.\n4. Click the nbviewer link to see your gisted notebook. (nbviewer caches renders so it may not show your latest changes immediately.)\n5. Click the <i class=\"fa-share fa\"></i> share button again in the toolbar to update your gist. (The gist ID is preserved in the notebook file.)"
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "markdown",
"source": "<p class=\"alert alert-warning\">NOTE: Your token is stored in the browser localStorage for the current notebook server domain. Any JS scripts loaded from the domain can access your token.</p>"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "PS: This notebook was posted as a gist using its own recipe &#x1F648;&#x1F649;&#x1F64A;"
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"mimetype": "text/x-python",
"name": "python",
"codemirror_mode": {
"version": 3,
"name": "ipython"
},
"file_extension": ".py",
"version": "3.4.4",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
},
"gist_id": "587e2bc8b335e90d890b"
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment