Skip to content

Instantly share code, notes, and snippets.

@caiofcm
Last active August 15, 2018 13:04
Show Gist options
  • Select an option

  • Save caiofcm/490a77c289bf9a36141013c440a1493d to your computer and use it in GitHub Desktop.

Select an option

Save caiofcm/490a77c289bf9a36141013c440a1493d to your computer and use it in GitHub Desktop.
Jupyter Auxiliaries files
# Reference: https://svds.com/jupyter-notebook-best-practices-for-data-science/
import os
from subprocess import check_call
def post_save(model, os_path, contents_manager):
"""post-save hook for converting notebooks to .py scripts"""
if model['type'] != 'notebook':
return # only do this for notebooks
d, fname = os.path.split(os_path)
check_call(['jupyter', 'nbconvert', '--to', 'script', fname], cwd=d)
# check_call(['jupyter', 'nbconvert', '--to', 'html', fname], cwd=d)
c.FileContentsManager.post_save_hook = post_save
{#
This template helps in the convertion of ipynb to html hiding Input or Output blocks
Curently it is using the Slides UI in the View Cell Tabs:
- Hide Input; Hide Output = skip
- Hide Input; Show Output = Fragment
- Show Input; Hide Output = sub-slide
#}
{%- extends 'full.tpl' -%}
{% block input_group -%}
{%- if cell.metadata.hide_input or nb.metadata.hide_input or
cell.metadata.get('slideshow', {}).get('slide_type', False) == 'skip' or
cell.metadata.get('slideshow', {}).get('slide_type', False) == 'fragment' -%}
{%- else -%}
{{ super() }}
{%- endif -%}
{% endblock input_group %}
{% block output_group -%}
{%- if cell.metadata.hide_output or
cell.metadata.get('slideshow', {}).get('slide_type', False) == 'skip' or
cell.metadata.get('slideshow', {}).get('slide_type', False) == 'sub-slide' -%}
{%- else -%}
{{ super() }}
{%- endif -%}
{% endblock output_group %}
{% block output_area_prompt %}
{%- if cell.metadata.hide_input or nb.metadata.hide_input or
cell.metadata.get('slideshow', {}).get('slide_type', False) == 'skip' or
cell.metadata.get('slideshow', {}).get('slide_type', False) == 'fragment' -%}
<div class="prompt"> </div>
{%- else -%}
{{ super() }}
{%- endif -%}
{% endblock output_area_prompt %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment