Skip to content

Instantly share code, notes, and snippets.

@yang-zhang
yang-zhang / ipy_hide_input
Created Jan 25, 2017 — forked from hannes-brt/ipy_hide_input
This is a simple command line tool that adds a small snippet of Javascript to the end of the HTML output of `ipython nbconvert` that hides the input code in the output. This works for both '--to html' and '--to slides' The tool works both when given a file name or by reading from stdin: ```bash ipy_hide_input input_file.slides.html ipython nbcon…
View ipy_hide_input
#! /usr/bin/env python
"""
The MIT License (MIT)
Copyright (c) 2013 Hannes Bretschneider
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
@yang-zhang
yang-zhang / howto autoreload
Last active May 19, 2018
Add autoreload to the top of notebook to reload modules before executing code
View howto autoreload
%load_ext autoreload
%autoreload 2
# https://ipython.org/ipython-doc/3/config/extensions/autoreload.html
@yang-zhang
yang-zhang / jupyter notebook header
Last active Dec 8, 2018
Common commands to add to top of jupyter notebooks
View jupyter notebook header
%load_ext autoreload
%autoreload 2
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
pd.set_option('max_colwidth',500)
@yang-zhang
yang-zhang / howto checkout remote branch
Created May 19, 2018
Check out remote github branch
View howto checkout remote branch
git fetch origin
git checkout -b target_branch origin/target_branch
View howto add github remote
git remote add upstream https://github.com/some_user/their_repo.git
@yang-zhang
yang-zhang / howto remove git file keep local
Created May 19, 2018
How to remove file from git but keep locally
View howto remove git file keep local
git rm --cached -r file_to_remove_and_keep_local.py
@yang-zhang
yang-zhang / howto format date time python
Last active Aug 24, 2018
Format printable date time in python
View howto format date time python
import datetime
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
datetime.datetime.now().strftime('%Y-%m-%d-%H')
View howto reload module py3
from importlib import reload
reload(some_module)
@yang-zhang
yang-zhang / howto jupyter display dataframe options
Last active Nov 20, 2019
How to set dataframe display options for IPython and Jupyter notebook
View howto jupyter display dataframe options
import pandas as pd
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', -1)
@yang-zhang
yang-zhang / howto untar all tar files
Created May 20, 2018
How to untar all tar files in a directory
View howto untar all tar files
!for a in `ls -1 *.tar`; do tar xf $a; done