Skip to content

Instantly share code, notes, and snippets.

View parente's full-sized avatar
🦡

Peter Parente parente

🦡
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@parente
parente / postinstall.sh
Last active April 23, 2024 06:11
Post-install script to disable SSH password authentication, install latest Docker with AUFS on Ubuntu 14.04 VMs
#!/bin/bash
# Disable password authentication
sudo grep -q "ChallengeResponseAuthentication" /etc/ssh/sshd_config && sed -i "/^[^#]*ChallengeResponseAuthentication[[:space:]]yes.*/c\ChallengeResponseAuthentication no" /etc/ssh/sshd_config || echo "ChallengeResponseAuthentication no" >> /etc/ssh/sshd_config
sudo grep -q "^[^#]*PasswordAuthentication" /etc/ssh/sshd_config && sed -i "/^[^#]*PasswordAuthentication[[:space:]]yes/c\PasswordAuthentication no" /etc/ssh/sshd_config || echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
sudo service ssh restart
# Install latest Docker
sudo apt-get update
sudo apt-get -y install linux-image-extra-$(uname -r)
sudo sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -"
@parente
parente / README.md
Last active December 26, 2023 14:31
Jupyter Tidbit: Use nbconvert to clear notebook outputs

Summary

nbconvert has a preprocessor that clears cell outputs from notebook files, leaving cell inputs intact.

Example

The following shell command reads my_input_notebook.ipynb, removes its cell outputs, prints the cleaned notebook to stdout, and redirects that output to a new notebook file named my_output_notebook.ipynb.

jupyter nbconvert my_input_notebook.ipynb --to notebook --ClearOutputPreprocessor.enabled=True --stdout > my_output_notebook.ipynb
@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 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
@parente
parente / nginx.conf
Last active April 3, 2023 16:00
nginx.conf recipe for username-based authorization levels for a Docker registry
user www-data;
worker_processes 1;
daemon off;
events {
worker_connections 1024;
}
http {
upstream docker-registry {
@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 November 30, 2022 04:44
Jupyter Tidbit: Kernels for text files in JupyterLab

Summary

You can associate a Console panel and kernel with a text editor in JupyterLab, and use it to execute selected code, RStudio style.

  1. Create or open a text source file in JupyterLab.
  2. Right click in the text editor panel.
  3. Click Create Console for Editor.
  4. Select a kernel matched to the programming language you want to execute in the file.
  5. Notice the Console panel that appears.
  6. Highlight one or more lines back in the text editor you'd like to run.
@parente
parente / nbwhisk.ipynb
Last active November 28, 2022 19:51
Jupyter Notebooks as OpenWhisk Actions
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@parente
parente / md.css
Created June 27, 2013 02:29
Default stylesheet I use for rendering markdown into html based on my lsr.css for restructuredText.
body {
font-family: 'Helvetica Neue', sans;
background: #ffffff;
color: #222;
margin: 2em auto;
padding: 0 2em;
width: 48em;
line-height: 1.5em;
font-size: 16px;
font-weight: 300;