Skip to content

Instantly share code, notes, and snippets.

🕐
Focusing on @wearethorn

Peter Parente parente

🕐
Focusing on @wearethorn
Block or report user

Report or block parente

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@parente
parente / README.md
Last active Nov 12, 2019
Jupyter Tidbit: Display an image gallery
View README.md

Summary

JupyterLab and Jupyter Notebook can display HTML-embedded images in notebook documents. You can use the IPython.display.HTML class to structure these images into a basic image gallery.

Example

Binder

The notebook below defines a gallery() function that accepts a list of image URLs, local image

@parente
parente / Dockerfile
Created Mar 15, 2019
jupyter/datascience-notebook
View Dockerfile
FROM jupyter/datascience-notebook:eb149a8c333a
View docker-stacks-811.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View jupyter-nbviewer-692.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@parente
parente / README.md
Last active Nov 4, 2018
Jupyter Tidbit: Display handles
View README.md

Summary

IPython's display() function can return a DisplayHandle object. You can use a DisplayHandle to update the output of one cell from any other cell in a Jupyter Notebook.

Example

Binder

The display_handle.ipynb notebook below calls display(display_id=True) to get a display handle instance. It then uses the DisplayHandle.display method to show some initial, static Markdown. Later, in a different cell, it calls DisplayHandle.update in a loop to show a range of emoji characters.

@parente
parente / README.md
Last active Sep 16, 2018
Jupyter Tidbit: IPython's ! returns an SList
View README.md

Summary

IPython shell assignment (the ! operator) evaluates a command using the local shell (e.g., bash) and returns a string list (IPython.utils.text.SList). An SList is a list-like object containing "chunks" of stdout and stderr, properties for accessing those chunks in different forms, and convenience methods for operating on them.

Example

Binder

The SList.ipynb notebook below uses SList properties to access the output of a shell command as a list-like of strings, a newline-separated string, a space-separated string, and a list of pathlib.Path objects. The notebook then uses the SList.fields() and SList.grep() methods to extract columns from and search command output.

@parente
parente / README.md
Last active Sep 5, 2018
Jupyter Tidbit: Run a notebook headlessly
View README.md

Summary

You can use nbconvert to execute a notebook from the command line (aka headlessly) and store the results in a new notebook file, an HTML file, a PDF, etc. Tools based on nbconvert, like papermill and nbflow, take this capability a step further and let you easily parameterize and chain notebooks.

Example

Binder

The command below executes the notebook named run_me.ipynb and outputs a new notebook file named you_ran_me.ipynb with all cell outputs captured. nbconvert executes the run_me.ipynb notebook using the kernel the notebook document declares in its metadata, python3 in this example.

@parente
parente / Dockerfile
Last active Sep 3, 2018
docker-stacks #710
View Dockerfile
FROM jupyter/all-spark-notebook:8ccdfc1da8d5
@parente
parente / README.md
Last active Aug 28, 2018
Jupyter Tidbit: Run and say "done!"
View README.md

Summary

Many modern web browsers provide a speech synthesis API for JavaScript. You can write and invoke a function to have your notebook speak when it finishes executing certain cells, whether you're running it in JupyterLab (>=0.34) or classic Jupyter Notebook.

def speak(text):
    from IPython.display import Javascript as js, clear_output
    # Escape single quotes
You can’t perform that action at this time.