Skip to content

Instantly share code, notes, and snippets.

@catherinedevlin
Created November 30, 2015 10:49
Show Gist options
  • Save catherinedevlin/e1b407a912e018fac961 to your computer and use it in GitHub Desktop.
Save catherinedevlin/e1b407a912e018fac961 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"IPython Notebook\n",
"=========\n",
"\n",
"Catherine Devlin\n",
"----------------\n",
"\n",
"* catherine.devlin@gmail.com\n",
"* catherinedevlin.blogspot.com\n",
"\n",
"Hinterland PyLadies\n",
"------------------"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## \"Interactive\" Python?"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Command completion\n",
"* %lsmagic\n",
"* %pfile"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## One year, at PyCon..."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Awarded [2012 Free Software Award](http://www.fsf.org/news/2012-free-software-award-winners-announced-2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## What sorcery is this?"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* IPython kernel\n",
"* Webpage with JavaScript"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Amp up your introspection\n",
"-------------------------"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import re\n",
"import requests\n",
"print('ok')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"requests.get??"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"%p"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"print("
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"%quickref"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Break out of your shell"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"047-validator.shis a great file!\n",
"PandasTour.ipynbis a great file!\n",
"Untitled.ipynbis a great file!\n",
"Untitled1.ipynbis a great file!\n",
"demos.ipynbis a great file!\n",
"make_presentation.ipynbis a great file!\n",
"make_slides.shis a great file!\n",
"presentation.ipynbis a great file!\n",
"pyladies.ipynbis a great file!\n",
"serve.shis a great file!\n"
]
}
],
"source": [
"my_directory = !ls\n",
"for itm in my_directory:\n",
" print(itm + 'is a great file!')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PandasTour.ipynb demos.ipynb presentation.ipynb\r\n",
"Untitled.ipynb make_presentation.ipynb pyladies.ipynb\r\n"
]
}
],
"source": [
"ls"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"!head Unt"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Run not-Python"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"IF THAT'S YOUR THING\n"
]
}
],
"source": [
"%%ruby\n",
"say = \"if that's your thing\"\n",
"puts say.upcase"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Run bash scripts"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"XKCDify.py\n",
"d3js.ipynb\n",
"demos.ipynb\n",
"demo_wak.ipynb\n",
"make_presentation.ipynb\n",
"presentation.ipynb\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"ls: cannot access *.ipy: No such file or directory\n"
]
}
],
"source": [
"%%bash\n",
"for ext in py ipy ipynb; do\n",
" ls *.$ext\n",
"done"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Don't run bash scripts"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"['demos.ipynb',\n",
" 'make_presentation.ipynb',\n",
" 'Measuring g with an inclined plane.ipynb',\n",
" 'Music.ipynb',\n",
" 'presentation.ipynb']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"files = !ls *.ipynb\n",
"files"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Hybrid scripts"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"presentation.reveal.html\n",
"ls: cannot access *.ipy: No such file or directory\n",
"demos.ipynb\t\t\t\t Music.ipynb\n",
"make_presentation.ipynb\t\t\t presentation.ipynb\n",
"Measuring g with an inclined plane.ipynb\n"
]
}
],
"source": [
"for ext in ('html', 'ipy', 'ipynb'):\n",
" !ls *.{ext}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"make_presentation.ipynb\r\n"
]
}
],
"source": [
"!rm -f *.ipynb.2\n",
"!ls *_*.ipynb*"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Fits the way you experiment"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"### Matches experimental workflow\n",
"\n",
"### Keep your experiments"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Revolutionize Your Shared Workflow"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"> “Man is by nature a social animal; an individual who is unsocial naturally and not accidentally is either beneath \n",
"> our notice or more than human. Society is something that precedes the individual. Anyone who either cannot lead \n",
"> the common life or is so self-sufficient as not to need to, and therefore does not partake of society, is either \n",
"> a beast or a god. ”\n",
"> \n",
"> ― Aristotle, Politics"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Rich output"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Expressive documentation"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Executable, always-updated book"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"[Probablistic Programming & Bayesian Methods for Hackers](http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/) by Cameron Davidson-Pilon"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Math / Latex"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Inline TeX in Markdown: $\\sqrt{3x-1}+(1+x)^2$"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$$F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx$$"
],
"text/plain": [
"<IPython.core.display.Math at 0x25b3750>"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import Math\n",
"Math(r'F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx') "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Social coding"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Give a presentation"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
" ipython nbconvert --format reveal presentation.ipynb\n",
" cd nbconvert_build\n",
" python -m SimpleHTTPServer 8000 &\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Requires IPython 1.0"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### nbviewer"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Every notebook is a JSON file with \".ipynb\" extension"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\r\n",
" \"metadata\": {\r\n",
" \"name\": \"\"\r\n",
" },\r\n",
" \"nbformat\": 3,\r\n",
" \"nbformat_minor\": 0,\r\n",
" \"worksheets\": [\r\n",
" {\r\n",
" \"cells\": [\r\n",
" {\r\n"
]
}
],
"source": [
"!head presentation.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"* nbviewer.ipython.org/url/*.ipynb-url* serves it publicly!\n",
"* or nbviewer.ipython.org/*gist-number,\n",
"* downloadable"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"#### Example: PyOhio video downloads\n",
"\n",
"[catherinedevlin.pythoneers.com/pyohio-videos.ipynb](http://catherinedevlin.pythoneers.com/pyohio-videos.ipynb)\n",
"\n",
"[nbviewer.ipython.org/url/catherinedevlin.pythoneers.com/pyohio-videos.ipynb](http://nbviewer.ipython.org/url/catherinedevlin.pythoneers.com/pyohio-videos.ipynb)\n",
"\n",
"[https://gist.github.com/catherinedevlin/5636516](https://gist.github.com/catherinedevlin/5636516)\n",
"\n",
"[http://nbviewer.ipython.org/5636516](http://nbviewer.ipython.org/5636516)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### [wakari](https://www.wakari.io/) by Continuum Analytics"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Share a [link to a workbook](https://prod-vz-7.wakari.io:9028/notebook_relative/ipython-talk-pyohio2013/presentation.ipynb)\n",
"\n",
"or a [link to a bundle](https://www.wakari.io/sharing/bundle/catherine_devlin/ipython-talk-pyohio2013)\n",
"\n",
"... and your collaborators *don't even need Python*..."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Go learn this"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* This presentation: https://github.com/catherinedevlin/ipython-pyohio2013-talk\n",
"* [Gallery](https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks)\n",
"* [Videos](http://pyvideo.org/search?models=videos.video&q=ipython)\n",
"* [IPython In Depth](https://github.com/ipython/ipython-in-depth)\n",
"* don't forget `%quickref`, `%lsmagic`\n",
"* catherine.devlin@gmail.com for questions (or job offers!)"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment