from IPython.core.display import display, HTML, Image

display(HTML("<style>.container { width:80% !important; }</style>"))

from traitlets.config.manager import BaseJSONConfigManager
path = "/home/damian/miniconda3/envs/rise_latest/etc/jupyter/nbconfig"
cm = BaseJSONConfigManager(config_dir="/home/aleg/.jupyter/nbconfig/")
cm.update(
    'livereveal', {
        'theme': 'simple',
        'transition': 'zoom',
        'transition-speed' :'fast',
        'start_slideshow_at': 'selected',
        'scroll': True,})

"""
Explanation: Introduction to Jupyter Notebook
Copyright : GNU General Public License v2
Author : Adrien Leger / &#97;&#108;&#101;&#103;&#64;&#101;&#98;&#105;&#46;&#97;&#99;&#46;&#117;&#107; / Github
Date : 17/11/2016
Source : https://jupyter.org/
Generic imports and notebook configuration + reveal configuration
End of explanation
"""


for i in range (5):
    print (i)

from random import choice
"".join(choice(["A","T","C","G"]) for i in range(100))

"""
Explanation: Jupyter notebook, spiritual son of Galileo

I therefore concluded and decided unhesitatingly, that there are three stars in the heavens moving about Jupiter, as Venus and Mercury round the Sun; which at length was established as clear as daylight by numerous subsequent observations. These observations also established that there are not only three, but four, erratic sidereal bodies performing their revolutions round Jupiter...the revolutions are so swift that an observer may generally get differences of position every hour.

Galileo trans Carlos, Sidereus Nuncius (1610), 1880, p47.

<p style="background-color:black;color:white;font-family:courier;font-size:150%">>>>jupyter notebook</p>


Open source, data science and scientific computing
A web application that run in your favorite browser
Create and share documents that contain live code, equations, visualizations and explanatory text
Example of application :
Data cleaning and transformation
Numerical simulation
Statistical modeling
Machine learning
...



Preview of the Jupyter command panel

Preview of a jupyter notebook

Why using Jupyter ?

Choice of language
* Support for over 40 programming languages such as Python, Bash, R, Julia ... (Jupyter = Julia + Python + R)
* Different optional Kernel can run interactive code in a particular programming language and return output to the user.

Readable code and easy to share with others
* .ipyn = Open document format based on JSON
* Can be export in many formats (html, latex, pdf...)
* Contain a complete record of the user's sessions (embed code, narrative text, equations and rich output)
* Can be put under version control
* Easy online sharing with Jupyter Notebook Viewer

Rich inline output and interactive widgets
* Code can produce HTML, images, videos, LaTeX, and JavaScript
* Interactive widgets to manipulate and visualize data in real time

Big data integration
* Leverage big data tools, such as Apache Spark, from Python and R
* Integration of data analysis and data visualization packages (pandas, scikit-learn, matplotlib, ggplot2, dplyr...)
* Can be ran from a computational node and forwarded in your local browser
The notebook is divided in “cells”


Markdown (for descriptions)


Code


Output (text, graphics, ...)


Markdown cells

Using directly Markdown synthax
See synthax at daringfireball
italic / bold / italic and bold 

Blockquote.

Second paragraph in the blockquote



Unordered list item
ordered sub-item
second sub-item




Title1
Title2
Title 3

Using HMTL formatted text
<p style="color:red;font-family:sans_serif">Sans serif red</p>

<p><b> Bold </b><i> Italic </i> <ins> Underligned </ins></p>

<h1> title 1 </h1>

<p style="background-color:black;color:white;font-family:courier;font-size:150%">Terminal like</p>

Display mathematics with MathJax
When $a \ne 0$ there are two solutions to $ax^2 + bx + c = 0$
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$$
Or mix everything together
This line mixes markdown formatting with <ins>HTML formatting</ins> and even MathJax mathematics 
* $a \sqrt 2$
* $b^2-4ac$
Code cells
The default language in a cell depends on the active kernel


Python3 kernel




Julia kernel




R kernel


Run a cell
Select a cell and press CTRL + ENTER
End of explanation
"""


ls ../

pwd

man ls

"""
Explanation: Easy Shell invocation
Independent of the kernel selected some common shell commands can be invoked directly 

alias
cat
cd
clear
cp
less
ls
man
mkdir
more
mv
pushd
pwd
rm
rmdir

Examples of direct shell commands
End of explanation
"""


!for l in *.ipynb; do echo $l; done

!cat "./[0]-Introduction_to_Jupyter_Notebook.ipynb" | grep "cell_type" | head

"""
Explanation: By adding the magic "!" any bash command can be run in Jupyter
End of explanation
"""


# Attribute a bash output to a python variable
a = !ls

# Loop with python over the lines returned previously
for file in a:
    # print with bash
    !echo {file}

"""
Explanation: You can even mix bash and python in the same cell
End of explanation
"""


%%bash
echo -e "Bash kernel!\n"

%%perl
print "PERL Kernel\n";

%%python3
print ("Python3 kernel")

%%R
cat ("R kernel")

%%javascript
alert("Javascript kernel");

"""
Explanation: More languages
You can also use special python Magics to run whole cells under other language interpreters
End of explanation
"""


