What it is


In [ ]:
message = "Hello PyOhio"

In [ ]:
print(" * ".join(l for l in message.upper()))

introspection


In [ ]:
import r

In [ ]:
re.

In [ ]:
re?

In [ ]:
re.sub(

In [ ]:
%p

In [ ]:
conference = 'PyOhio'

In [ ]:
?co*

getting help


In [ ]:
%quickref

In [ ]:
%lsmagic

In [ ]:
%magic

Repair and keep experiments

get around


In [ ]:
pwd

In [ ]:
cd projects/

In [ ]:
rm -f *.log

In [ ]:
cd /var/log/apache2/

In [ ]:
ls err*

In [ ]:
cd /tmp

In [ ]:
cd -

In [ ]:
cd --project

In [ ]:
cp /var/log/apache2/error.log .

In [ ]:
ls *.log

In [ ]:
head er

Run Python


In [ ]:
ls

In [ ]:
%run read_errlog.py

In [ ]:
%debug

In [ ]:
!gedit read_errlog.py

In [ ]:
%load read_errlog.py

In [ ]:
import glob
import re
import collections

result = collections.defaultdict(int)
error_finder = re.compile(r'(.*?)\[(\w+)](.*)')
for fname in glob.glob('*.log'):
    with open(fname) as infile:
        for line in infile.readlines():
            match = error_finder.search(line)
            if match:
                result[match.group(2)] += 1
print (result)

Performance info


In [ ]:
%run?

In [ ]:
%run -t read_errlog.py

In [ ]:
%run -p read_errlog.py

Back to the slideshow!

LaTeX in Markdown

Inline TeX in Markdown: $\sqrt{3x-1}+(1+x)^2$

d3js


In [ ]:
from IPython.display import Javascript, HTML

In [ ]:
Javascript("""$.getScript('http://d3js.org/d3.v3.min.js')""")

In [ ]:
HTML("""
<style>

circle {
  fill: rgb(31, 119, 180);
  fill-opacity: .25;
  stroke: rgb(31, 119, 180);
  stroke-width: 1px;
}

.leaf circle {
  fill: #ff7f0e;
  fill-opacity: 1;
}

text {
  font: 10px sans-serif;
}

</style>
""")

In [ ]:
Javascript("""

// This unhides the output area
container.show();

// element is the jQuery element we will append to
var e = element.get(0);
    
var diameter = 600,
    format = d3.format(",d");

var pack = d3.layout.pack()
    .size([diameter - 4, diameter - 4])
    .value(function(d) { return d.size; });

var svg = d3.select(e).append("svg")
    .attr("width", diameter)
    .attr("height", diameter)
  .append("g")
    .attr("transform", "translate(2,2)");

d3.json("files/flare.json", function(error, root) {
  var node = svg.datum(root).selectAll(".node")
      .data(pack.nodes)
    .enter().append("g")
      .attr("class", function(d) { return d.children ? "node" : "leaf node"; })
      .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });

  node.append("title")
      .text(function(d) { return d.name + (d.children ? "" : ": " + format(d.size)); });

  node.append("circle")
      .attr("r", function(d) { return d.r; });

  node.filter(function(d) { return !d.children; }).append("text")
      .attr("dy", ".3em")
      .style("text-anchor", "middle")
      .text(function(d) { return d.name.substring(0, d.r / 3); });
});

d3.select(self.frameElement).style("height", diameter + "px");
""")

ipython_doctester by me


In [ ]:
from ipython_doctester import test

In [ ]:
@test
def count_os(word):
    """Return number of 'o's in a string.
    >>> count_os('dynamic language')
    0
    >>> count_os('Python')
    1
    >>> count_os('Ohio')
    2
    """
    return word.count('o')

ipython_sql by me


In [ ]:
%load_ext sql

In [ ]:
%sql postgresql://will:longliveliz@localhost/shakes

In [ ]:
name = 'Duke'
%sql SELECT * FROM character WHERE charname = :name

In [ ]:
gertrudes = %sql SELECT * FROM character WHERE charname = 'Gertrude'
gertrudes[0].description

ipyythonblocks by Matt Davis


In [ ]:
from ipythonblocks import BlockGrid
grid = BlockGrid(8, 8, fill=(123, 234, 123))
grid

In [ ]:
grid[2, 4] = (255, 255, 255)
grid

In [ ]:
from IPython.display import clear_output
import time
base_color = [50, 50, 50]
for i in range(200):
    clear_output()
    for row_number in range(grid.height):
        for column_number in range(grid.width):
            grid[row_number, column_number] = (base_color[0], base_color[1]+row_number*20, base_color[2]+column_number*20)
    grid.show()
    base_color[0] += 1
    base_color[1] += 1
    base_color[2] += 1
    time.sleep(0.02)