Code Test

http://moderndata.plot.ly/custom-styling-for-ipython-notebooks-with-3-lines-of-code/

http://nbviewer.jupyter.org/github/barbagroup/AeroPython/tree/master/

https://github.com/JENkt4k/notebook/blob/master/notebook/static/notebook/js/codecell.js

Bash

git clone --bare https://github.com/[user]/[repo].git
cd [repo].git

C++

int main()
{
  std::out << "hello world";
  return 0
}

Python

print hello world

In [2]:
%%html

<style>

html {
  font-size: 62.5% !important; }
body {
  font-size: 1.5em !important; /* currently ems cause chrome bug misinterpreting rems on body element */
  line-height: 1.6 !important;
  font-weight: 400 !important;
  font-family: "Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif !important;
  color: #222 !important; }

div{ border-radius: 0px !important;  }
div.CodeMirror-sizer{ background: rgb(244, 244, 248) !important; }
div.input_area{ background: rgb(244, 244, 248) !important; }

div.out_prompt_overlay:hover{ background: rgb(244, 244, 248) !important; }
div.input_prompt:hover{ background: rgb(244, 244, 248) !important; }

h1, h2, h3, h4, h5, h6 {
  color: #333 !important;
  margin-top: 0 !important;
  margin-bottom: 2rem !important;
  font-weight: 300 !important; }
h1 { font-size: 4.0rem !important; line-height: 1.2 !important;  letter-spacing: -.1rem !important;}
h2 { font-size: 3.6rem !important; line-height: 1.25 !important; letter-spacing: -.1rem !important; }
h3 { font-size: 3.0rem !important; line-height: 1.3 !important;  letter-spacing: -.1rem !important; }
h4 { font-size: 2.4rem !important; line-height: 1.35 !important; letter-spacing: -.08rem !important; }
h5 { font-size: 1.8rem !important; line-height: 1.5 !important;  letter-spacing: -.05rem !important; }
h6 { font-size: 1.5rem !important; line-height: 1.6 !important;  letter-spacing: 0 !important; }

@media (min-width: 550px) {
  h1 { font-size: 5.0rem !important; }
  h2 { font-size: 4.2rem !important; }
  h3 { font-size: 3.6rem !important; }
  h4 { font-size: 3.0rem !important; }
  h5 { font-size: 2.4rem !important; }
  h6 { font-size: 1.5rem !important; }
}

p {
  margin-top: 0 !important; }
  
a {
  color: #1EAEDB !important; }
a:hover {
  color: #0FA0CE !important; }
  
code {
  padding: .2rem .5rem !important;
  margin: 0 .2rem !important;
  font-size: 90% !important;
  white-space: nowrap !important;
  background: #F1F1F1 !important;
  border: 1px solid #E1E1E1 !important;
  border-radius: 4px !important; }
pre > code {
  display: block !important;
  padding: 1rem 1.5rem !important;
  white-space: pre !important; }
  
button{ border-radius: 0px !important; }
.navbar-inner{ background-image: none !important;  }
select, textarea{ border-radius: 0px !important; }

</style>


Code Test

Bash

git clone --bare https://github.com/[user]/[repo].git
cd [repo].git

C++

int main()
{
  std::out << "hello world";
  return 0;
}

Python

print "hello world"

In [10]:
print "hello world"


hello world

In [26]:
%env EDITOR=/usr/bin/nano


env: EDITOR=/usr/bin/nano

In [27]:
%edit


IPython will make a temporary file named: /tmp/ipython_edit_vnmGqD/ipython_edit_uolvX9.py

In [28]:
edit temp1.py

In [29]:
def hello():
    print "eat it"

In [30]:
%edit
def hello():
    print "eat it"


IPython will make a temporary file named: /tmp/ipython_edit_P0KKMR/ipython_edit_WYVQ38.py

In [14]:
%pwd


Out[14]:
u'/home/james/Documents/Git/MyGitHub/pynotes-general'

In [ ]:
from IPython.core.display import HTML
import urllib2
HTML(urllib2.urlopen('http://bit.ly/1Bf5Hft').read())

In [36]:
%%writefile filename.test.css
"""%%html

<style>

html {
  font-size: 62.5% !important; }
body {
  font-size: 1.5em !important; /* currently ems cause chrome bug misinterpreting rems on body element */
  line-height: 1.6 !important;
  font-weight: 400 !important;
  font-family: "Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif !important;
  color: #222 !important; }

div{ border-radius: 0px !important;  }
div.CodeMirror-sizer{ background: rgb(244, 244, 248) !important; }
div.input_area{ background: rgb(244, 244, 248) !important; }

div.out_prompt_overlay:hover{ background: rgb(244, 244, 248) !important; }
div.input_prompt:hover{ background: rgb(244, 244, 248) !important; }

h1, h2, h3, h4, h5, h6 {
  color: #333 !important;
  margin-top: 0 !important;
  margin-bottom: 2rem !important;
  font-weight: 300 !important; }
h1 { font-size: 4.0rem !important; line-height: 1.2 !important;  letter-spacing: -.1rem !important;}
h2 { font-size: 3.6rem !important; line-height: 1.25 !important; letter-spacing: -.1rem !important; }
h3 { font-size: 3.0rem !important; line-height: 1.3 !important;  letter-spacing: -.1rem !important; }
h4 { font-size: 2.4rem !important; line-height: 1.35 !important; letter-spacing: -.08rem !important; }
h5 { font-size: 1.8rem !important; line-height: 1.5 !important;  letter-spacing: -.05rem !important; }
h6 { font-size: 1.5rem !important; line-height: 1.6 !important;  letter-spacing: 0 !important; }

@media (min-width: 550px) {
  h1 { font-size: 5.0rem !important; }
  h2 { font-size: 4.2rem !important; }
  h3 { font-size: 3.6rem !important; }
  h4 { font-size: 3.0rem !important; }
  h5 { font-size: 2.4rem !important; }
  h6 { font-size: 1.5rem !important; }
}

p {
  margin-top: 0 !important; }
  
a {
  color: #1EAEDB !important; }
a:hover {
  color: #0FA0CE !important; }
  
code {
  padding: .2rem .5rem !important;
  margin: 0 .2rem !important;
  font-size: 90% !important;
  white-space: nowrap !important;
  background: #F1F1F1 !important;
  border: 1px solid #E1E1E1 !important;
  border-radius: 4px !important; }
pre > code {
  display: block !important;
  padding: 1rem 1.5rem !important;
  white-space: pre !important; }
  
button{ border-radius: 0px !important; }
.navbar-inner{ background-image: none !important;  }
select, textarea{ border-radius: 0px !important; }

</style>"""


Writing filename.test.css

In [3]:
from IPython.core.display import HTML

def blackbg():
	"""Black Background code mirror theme."""
	html = """
<style type="text/css">
.cm-s-ipython { background-color: black; color: lightblue; }
.cm-s-ipython span.cm-keyword {color: #00ff00; font-weight: bold;}
.cm-s-ipython span.cm-number {color: #ee88ee;}
.cm-s-ipython span.cm-operator {color: lime; font-weight: bold;}
.cm-s-ipython span.cm-meta {color: white;}
.cm-s-ipython span.cm-comment {color: cyan; font-style: italic;}
.cm-s-ipython span.cm-string {color: red;}
.cm-s-ipython span.cm-error {color: darkred;}
.cm-s-ipython span.cm-builtin {color: pink; font-weight: bold;}
.CodeMirror pre.CodeMirror-cursor {color: white; border-left: 1px solid white;}
.cm-s-ipython span.cm-variable {color: white;}
div.text_cell_input  {   background-color: black;    color: white;}
div.text_cell {   background-color: black;    color: white;}
div#notebook {    background-color: black;     background-image: none;     color: white;}
div.code_cell { background-color: black;    color: white;}
div.metaedit .maintoolbar{    background-color: black;    color: white;}
body{    background-color: black;    color: white;}
#notebook_name {  background-color: #333333;    color: white; background-image:none;}
span.ui-widget-content{  background-color: #333333;    color: white; background-image:none;}
div.ui-widget-content{  background-color: #333333;    color: white; background-image:none;}
div#ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only output_collapsed vbox{  
  background-color: black;    color: white;}
div.input_area{    background-color: black;    color: white;}
div.ui-widget-content { background-color: #333333; background-image: none;}
div.input_prompt {color:#6666CC; font-weight: bold;}
div.output_prompt {color:#CC6666; font-weight: bold;}
div.output_text {color:white;}
div.text_cell_render {color:white;}
span.item_name {color:white;}
.ui-widget-content a {color:white;}
div.tooltip .ui-corner-all .tooltiptext .smalltooltip {background-color: black; color:white;}
.pln {color:white} 
.typ {color:#f9f}
.lit {color:#BBB}
.kwd {color:#3e3}
.metaedit {background: transparent; border-color: transparent; color:white;}
.ui-button-text {background: #112; color:white; border-color:666;}
.ui-menubar  {background-color: transparent; background: transparent; background-image:none;}
.ui-widget-header  {background-color: transparent; background: transparent; background-image:none;}
.ui-helper-clearfix {background-color: transparent; background: transparent; background-image:none;}
.ui-corner-all {background: #112; color: white;}
.ui-widget  {background: #112; color: white;}
.ui-widget-content {background: #112; color: white;}
div.highlight {background:black;} /* needed for nbviewer */
div.output_stderr {background:#400;}
</style>"""
	return HTML(html)

Code Test

http://moderndata.plot.ly/custom-styling-for-ipython-notebooks-with-3-lines-of-code/

http://nbviewer.jupyter.org/github/barbagroup/AeroPython/tree/master/

Bash

git clone --bare https://github.com/[user]/[repo].git
cd [repo].git

C++

int main()
{
  std::out << "hello world";
  return 0
}

Python

print hello world

Append a style sheet to an HTML object

from json2html import *
from IPython.display import display, HTML

mydict = {a:1, b:2, c:3}

htmlcss = """
    <style type="text/css">
    th {   background-color: yellow;}
    </style>
    """

myhtml = HTML(json2html.convert(json = myjson))
myhtm.data = myhtm.data + htmlcss

In [7]:
from json2html import *
from IPython.display import display, HTML

mydict = { 'a':1, 'b':2, 'c':3}

htmlcss = """
    <style type="text/css">
    th {   background-color: yellow;}
    </style>
    """

myhtml = HTML(json2html.convert(json = mydict))
display(myhtml)


b2
c3
a1

In [8]:
#after executing this cell, both tables change: the left column will have a yellow bg
myhtml.data = myhtml.data + htmlcss
display(myhtml)


b2
c3
a1

In [ ]: