Skip to content

Instantly share code, notes, and snippets.

View parente's full-sized avatar
🦡

Peter Parente parente

🦡
View GitHub Profile
@parente
parente / README.md
Last active October 1, 2023 23:42
Jupyter Tidbit: Display an image gallery

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 / README.md
Last active May 11, 2019 00:09
progress example

Binder

@parente
parente / Dockerfile
Created March 15, 2019 22:24
jupyter/datascience-notebook
FROM jupyter/datascience-notebook:eb149a8c333a
@parente
parente / docker-stacks-811.ipynb
Created February 21, 2019 22:02
docker-stacks-811
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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 September 1, 2020 16:07
Jupyter Tidbit: Display handles

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 March 7, 2023 11:50
Jupyter Tidbit: IPython's ! returns an SList

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 September 12, 2021 14:40
Jupyter Tidbit: Run a notebook headlessly

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 September 3, 2018 18:06
docker-stacks #710
FROM jupyter/all-spark-notebook:8ccdfc1da8d5
@parente
parente / README.md
Last active September 14, 2023 13:25
Jupyter Tidbit: Run and say "done!"

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