Skip to content

Instantly share code, notes, and snippets.

@cowlicks
Last active December 26, 2015 02:19
Show Gist options
  • Select an option

  • Save cowlicks/7077935 to your computer and use it in GitHub Desktop.

Select an option

Save cowlicks/7077935 to your computer and use it in GitHub Desktop.

Revisions

  1. cowlicks revised this gist Oct 21, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion serve_slides.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/usr/bin/env python
    """A script to generate and serve the slides from a ipython notebook
    that auto updates the slides. Usage:
    that auto updates the slides. It would be nice to include something like
    this in IPython. Usage:
    >>> python serve_slides.py presentation.ipynb
  2. cowlicks revised this gist Oct 21, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions serve_slides.py
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    import pyinotify

    infile = sys.argv[1]
    # A hack because nbconvert lacks documentation.
    # It would be better to use IPython's API but...
    serve = 'ipython nbconvert --to slides --post serve ' + infile
    export = 'ipython nbconvert --to slides ' + infile

    @@ -25,7 +25,7 @@ def onChange(ev):
    notifier = pyinotify.Notifier(wm)

    # generate and serve the slides.
    serve = subprocess.Popen(serve.split(" "))
    serve = subprocess.Popen(serve.split(' '))

    while True:
    try:
  3. cowlicks created this gist Oct 21, 2013.
    38 changes: 38 additions & 0 deletions serve_slides.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/usr/bin/env python
    """A script to generate and serve the slides from a ipython notebook
    that auto updates the slides. Usage:
    >>> python serve_slides.py presentation.ipynb
    """

    import sys
    import subprocess
    import pyinotify

    infile = sys.argv[1]
    # A hack because nbconvert lacks documentation.
    serve = 'ipython nbconvert --to slides --post serve ' + infile
    export = 'ipython nbconvert --to slides ' + infile

    def onChange(ev):
    """Regenerate slides from the notebook."""
    subprocess.call(export.split(' '))

    # Setup pyinotify to watch the notebook.
    wm = pyinotify.WatchManager()
    wm.add_watch(infile, pyinotify.IN_MODIFY, onChange)
    notifier = pyinotify.Notifier(wm)

    # generate and serve the slides.
    serve = subprocess.Popen(serve.split(" "))

    while True:
    try:
    # Start watching the notebook for changes.
    notifier.loop()
    except KeyboardInterrupt:
    # Clean up
    serve.kill()
    notifier.stop()
    break