Last active
May 3, 2016 12:37
-
-
Save disarticulate/7286d7cebf8c071db81be49ee247e1a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"nbformat_minor": 0, "nbformat": 4, "metadata": {"language_info": {"nbconvert_exporter": "python", "version": "3.5.1+", "mimetype": "text/x-python", "name": "python", "codemirror_mode": {"version": 3, "name": "ipython"}, "pygments_lexer": "ipython3", "file_extension": ".py"}, "kernelspec": {"display_name": "Python 3", "name": "python3", "language": "python"}}, "cells": [{"source": ["%%javascript\n", "require.config({paths: {\n", " d3: \"https://cdn.rawgit.com/ElDeveloper/a6fc14f8993a1b8ad843/raw/ca8d8c12125cd93ccf6902c4dacce473e4cf2c3b/d3.v3.min\",\n", " topojson: \"https://cdn.rawgit.com/ElDeveloper/7d4f4a12683b03008435/raw/7ab04a76821117541a86764036e41edb00fae4f3/topojson.v1.min\",\n", " datamaps: \"https://cdn.rawgit.com/ElDeveloper/61b29679961d29e94db1/raw/d05e3e44485a414b4f32b16457c5bcef6de1a6a7/datamaps.all\",\n", " handlebars: \"https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.amd\"\n", " }\n", " }\n", " );\n", "\n", "require([\"d3\", \"topojson\", \"datamaps\",\"handlebars\"], function(a, b, c, d) {\n", " window.Handlebars = d\n", "});"], "execution_count": 1, "cell_type": "code", "outputs": [{"metadata": {}, "data": {"text/plain": ["<IPython.core.display.Javascript object>"], "application/javascript": ["require.config({paths: {\n", " d3: \"https://cdn.rawgit.com/ElDeveloper/a6fc14f8993a1b8ad843/raw/ca8d8c12125cd93ccf6902c4dacce473e4cf2c3b/d3.v3.min\",\n", " topojson: \"https://cdn.rawgit.com/ElDeveloper/7d4f4a12683b03008435/raw/7ab04a76821117541a86764036e41edb00fae4f3/topojson.v1.min\",\n", " datamaps: \"https://cdn.rawgit.com/ElDeveloper/61b29679961d29e94db1/raw/d05e3e44485a414b4f32b16457c5bcef6de1a6a7/datamaps.all\",\n", " handlebars: \"https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.amd\"\n", " }\n", " }\n", " );\n", "\n", "require([\"d3\", \"topojson\", \"datamaps\",\"handlebars\"], function(a, b, c, d) {\n", " window.Handlebars = d\n", "});"]}, "output_type": "display_data"}], "metadata": {"collapsed": false}}, {"source": ["from IPython.display import HTML\n", "handlebars = ''"], "execution_count": 2, "cell_type": "code", "outputs": [], "metadata": {"collapsed": true}}, {"source": ["%%javascript\n", "var kernel = IPython.notebook.kernel;\n", "var handlebars = Handlebars.VERSION\n", "var command = \"handlebars = \" + \"'\"+handlebars+\"'\";\n", "kernel.execute(command);"], "execution_count": 3, "cell_type": "code", "outputs": [{"metadata": {}, "data": {"text/plain": ["<IPython.core.display.Javascript object>"], "application/javascript": ["var kernel = IPython.notebook.kernel;\n", "var handlebars = Handlebars.VERSION\n", "var command = \"handlebars = \" + \"'\"+handlebars+\"'\";\n", "kernel.execute(command);"]}, "output_type": "display_data"}], "metadata": {"collapsed": false}}, {"source": ["handlebars"], "execution_count": 4, "cell_type": "code", "outputs": [{"execution_count": 4, "metadata": {}, "data": {"text/plain": ["''"]}, "output_type": "execute_result"}], "metadata": {"collapsed": false}}, {"source": ["%%javascript\n", "var kernel = IPython.notebook.kernel;\n", "var thename = window.document.getElementById(\"notebook_name\").innerHTML;\n", "var command = \"theNotebook = \" + \"'\"+thename+\"'\";\n", "kernel.execute(command);"], "execution_count": 7, "cell_type": "code", "outputs": [{"metadata": {}, "data": {"text/plain": ["<IPython.core.display.Javascript object>"], "application/javascript": ["var kernel = IPython.notebook.kernel;\n", "var thename = window.document.getElementById(\"notebook_name\").innerHTML;\n", "var command = \"theNotebook = \" + \"'\"+thename+\"'\";\n", "kernel.execute(command);"]}, "output_type": "display_data"}], "metadata": {"collapsed": false}}, {"source": ["print(theNotebook)"], "execution_count": 8, "cell_type": "code", "outputs": [{"name": "stdout", "text": ["load arbitrary library in jupyter\n"], "output_type": "stream"}], "metadata": {"collapsed": false}}, {"source": ["import json\n", "from pprint import pprint\n", "obreros = json.load(open(theNotebook+'.ipynb','r'))\n", "obreros"], "execution_count": 12, "cell_type": "code", "outputs": [{"execution_count": 12, "metadata": {}, "data": {"text/plain": ["{'cells': [{'cell_type': 'code',\n", " 'execution_count': 1,\n", " 'metadata': {'collapsed': False},\n", " 'outputs': [{'data': {'application/javascript': ['require.config({paths: {\\n',\n", " ' d3: \"https://cdn.rawgit.com/ElDeveloper/a6fc14f8993a1b8ad843/raw/ca8d8c12125cd93ccf6902c4dacce473e4cf2c3b/d3.v3.min\",\\n',\n", " ' topojson: \"https://cdn.rawgit.com/ElDeveloper/7d4f4a12683b03008435/raw/7ab04a76821117541a86764036e41edb00fae4f3/topojson.v1.min\",\\n',\n", " ' datamaps: \"https://cdn.rawgit.com/ElDeveloper/61b29679961d29e94db1/raw/d05e3e44485a414b4f32b16457c5bcef6de1a6a7/datamaps.all\",\\n',\n", " ' handlebars: \"https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.amd\"\\n',\n", " ' }\\n',\n", " ' }\\n',\n", " ' );\\n',\n", " '\\n',\n", " 'require([\"d3\", \"topojson\", \"datamaps\",\"handlebars\"], function(a, b, c, d) {\\n',\n", " ' window.Handlebars = d\\n',\n", " '});'],\n", " 'text/plain': ['<IPython.core.display.Javascript object>']},\n", " 'metadata': {},\n", " 'output_type': 'display_data'}],\n", " 'source': ['%%javascript\\n',\n", " 'require.config({paths: {\\n',\n", " ' d3: \"https://cdn.rawgit.com/ElDeveloper/a6fc14f8993a1b8ad843/raw/ca8d8c12125cd93ccf6902c4dacce473e4cf2c3b/d3.v3.min\",\\n',\n", " ' topojson: \"https://cdn.rawgit.com/ElDeveloper/7d4f4a12683b03008435/raw/7ab04a76821117541a86764036e41edb00fae4f3/topojson.v1.min\",\\n',\n", " ' datamaps: \"https://cdn.rawgit.com/ElDeveloper/61b29679961d29e94db1/raw/d05e3e44485a414b4f32b16457c5bcef6de1a6a7/datamaps.all\",\\n',\n", " ' handlebars: \"https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.amd\"\\n',\n", " ' }\\n',\n", " ' }\\n',\n", " ' );\\n',\n", " '\\n',\n", " 'require([\"d3\", \"topojson\", \"datamaps\",\"handlebars\"], function(a, b, c, d) {\\n',\n", " ' window.Handlebars = d\\n',\n", " '});']},\n", " {'cell_type': 'code',\n", " 'execution_count': 2,\n", " 'metadata': {'collapsed': True},\n", " 'outputs': [],\n", " 'source': ['from IPython.display import HTML\\n', \"handlebars = ''\"]},\n", " {'cell_type': 'code',\n", " 'execution_count': 3,\n", " 'metadata': {'collapsed': False},\n", " 'outputs': [{'data': {'application/javascript': ['var kernel = IPython.notebook.kernel;\\n',\n", " 'var handlebars = Handlebars.VERSION\\n',\n", " 'var command = \"handlebars = \" + \"\\'\"+handlebars+\"\\'\";\\n',\n", " 'kernel.execute(command);'],\n", " 'text/plain': ['<IPython.core.display.Javascript object>']},\n", " 'metadata': {},\n", " 'output_type': 'display_data'}],\n", " 'source': ['%%javascript\\n',\n", " 'var kernel = IPython.notebook.kernel;\\n',\n", " 'var handlebars = Handlebars.VERSION\\n',\n", " 'var command = \"handlebars = \" + \"\\'\"+handlebars+\"\\'\";\\n',\n", " 'kernel.execute(command);']},\n", " {'cell_type': 'code',\n", " 'execution_count': 4,\n", " 'metadata': {'collapsed': False},\n", " 'outputs': [{'data': {'text/plain': [\"''\"]},\n", " 'execution_count': 4,\n", " 'metadata': {},\n", " 'output_type': 'execute_result'}],\n", " 'source': ['handlebars']},\n", " {'cell_type': 'code',\n", " 'execution_count': 7,\n", " 'metadata': {'collapsed': False},\n", " 'outputs': [{'data': {'application/javascript': ['var kernel = IPython.notebook.kernel;\\n',\n", " 'var thename = window.document.getElementById(\"notebook_name\").innerHTML;\\n',\n", " 'var command = \"theNotebook = \" + \"\\'\"+thename+\"\\'\";\\n',\n", " 'kernel.execute(command);'],\n", " 'text/plain': ['<IPython.core.display.Javascript object>']},\n", " 'metadata': {},\n", " 'output_type': 'display_data'}],\n", " 'source': ['%%javascript\\n',\n", " 'var kernel = IPython.notebook.kernel;\\n',\n", " 'var thename = window.document.getElementById(\"notebook_name\").innerHTML;\\n',\n", " 'var command = \"theNotebook = \" + \"\\'\"+thename+\"\\'\";\\n',\n", " 'kernel.execute(command);']},\n", " {'cell_type': 'code',\n", " 'execution_count': 8,\n", " 'metadata': {'collapsed': False},\n", " 'outputs': [{'name': 'stdout',\n", " 'output_type': 'stream',\n", " 'text': ['load arbitrary library in jupyter\\n']}],\n", " 'source': ['print(theNotebook)']},\n", " {'cell_type': 'code',\n", " 'execution_count': 9,\n", " 'metadata': {'collapsed': False},\n", " 'outputs': [],\n", " 'source': ['import json\\n',\n", " 'from pprint import pprint\\n',\n", " \"obreros = json.load(open(theNotebook+'.ipynb','r'))\"]},\n", " {'cell_type': 'code',\n", " 'execution_count': 11,\n", " 'metadata': {'collapsed': False},\n", " 'outputs': [],\n", " 'source': ['json.dump(obreros,open(\"test.json\", \"w\"))']},\n", " {'cell_type': 'code',\n", " 'execution_count': None,\n", " 'metadata': {'collapsed': True},\n", " 'outputs': [],\n", " 'source': []}],\n", " 'metadata': {'kernelspec': {'display_name': 'Python 3',\n", " 'language': 'python',\n", " 'name': 'python3'},\n", " 'language_info': {'codemirror_mode': {'name': 'ipython', 'version': 3},\n", " 'file_extension': '.py',\n", " 'mimetype': 'text/x-python',\n", " 'name': 'python',\n", " 'nbconvert_exporter': 'python',\n", " 'pygments_lexer': 'ipython3',\n", " 'version': '3.5.1+'}},\n", " 'nbformat': 4,\n", " 'nbformat_minor': 0}"]}, "output_type": "execute_result"}], "metadata": {"collapsed": false}}, {"source": ["json.dump(obreros,open(\"test.json\", \"w\"))"], "execution_count": 13, "cell_type": "code", "outputs": [], "metadata": {"collapsed": false}}, {"source": [], "execution_count": null, "cell_type": "code", "outputs": [], "metadata": {"collapsed": true}}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just some examples of how to use libraries using RequireJS included in the Jupyter front end.
Also demonstrates how to get the name of the notebook, and load the notebook itself into a object using json.