IPython and Jupyter Notebooks: Automatically Export .py and .html – Dev pro tips

Source: IPython and Jupyter Notebooks: Automatically Export .py and .html – Dev pro tips

 

Seriously a Go give this guy a thumbs up, a tweet, a Huge Thanks for all the Time and Hassle it Saves !! 🙂

 

The script that worked for me is copied below, in case the link ever disappears from the web 😉

It’s that valuable !!

 

“`

# For Jupyter 4.x, put the following in a file saved at ~/.jupyter/jupyter_notebook_config.py

# Restart Jupyter Notebook after saving this file. Viola !

# from: http://protips.maxmasnick.com/ipython-notebooks-automatically-export-py-and-html

# Based off of https://github.com/jupyter/notebook/blob/master/docs/source/extending/savehooks.rst

import io
import os
from notebook.utils import to_api_path

_script_exporter = None
_html_exporter = None

def script_post_save(model, os_path, contents_manager, **kwargs):
    """convert notebooks to Python script after save with nbconvert

    replaces `ipython notebook --script`
    """
    from nbconvert.exporters.script import ScriptExporter
    from nbconvert.exporters.html import HTMLExporter

    if model['type'] != 'notebook':
        return

    global _script_exporter
    if _script_exporter is None:
        _script_exporter = ScriptExporter(parent=contents_manager)
    log = contents_manager.log

    global _html_exporter
    if _html_exporter is None:
        _html_exporter = HTMLExporter(parent=contents_manager)
    log = contents_manager.log

    # save .py file
    base, ext = os.path.splitext(os_path)
    script, resources = _script_exporter.from_filename(os_path)
    script_fname = base + resources.get('output_extension', '.txt')
    log.info("Saving script /%s", to_api_path(script_fname, contents_manager.root_dir))
    with io.open(script_fname, 'w', encoding='utf-8') as f:
        f.write(script)

    # save html
    base, ext = os.path.splitext(os_path)
    script, resources = _html_exporter.from_filename(os_path)
    script_fname = base + resources.get('output_extension', '.txt')
    log.info("Saving html /%s", to_api_path(script_fname, contents_manager.root_dir))
    with io.open(script_fname, 'w', encoding='utf-8') as f:
        f.write(script)
c.FileContentsManager.post_save_hook = script_post_save
Advertisements

When You Lose Weight, Where Does it Go? The Answer May Surprise You

When You Lose Weight, Where Does it Go? The Answer May Surprise You.

 

A surprising answer is that a good portion is Exhaled !
Carbon in the form of respiration, when you exhale…!

Cellular Respiration:

http://i0.wp.com/mitchkirby.com/wp-content/uploads/2015/04/equation1.jpg?resize=300%2C62

glucose + Oxygen -> Water + Carbon Dioxide + Energy

For each bit of glucose converted to water and carbon dioxide,

40% – expells as carbon dioxide
60% – expells as water

Per pound of mass, approximately
84% leaves as H20 (60%+60%*40%)  (sweat, urine,..)
16% leaves as CO2 (40%*40%) (breathing out, exhaling)

 

You’ll Be Eating This Noodle Salad From Now Till September

https://www.yahoo.com/health/youll-be-eating-this-noodle-salad-from-now-till-118985193593.html
Every other Thursday, Elizabeth Stark from Brooklyn Supper will help you make salads you actually want to eat. Today: A fresh, multi-flavored noodle recipe that will show off the season’s prettiest produce. Rice noodles that you can make using the boil and steep method are essential for avoiding steamy kitchens.

Matt Mullenweg on Polyphasic Sleep, Tequila, and Building Billion-Dollar Companies | The Blog of Author Tim Ferriss

http://fourhourworkweek.com/2015/02/09/matt-mullenweg/