Skip to content

Instantly share code, notes, and snippets.

@yang-zhang
yang-zhang / ipy_hide_input
Created January 25, 2017 20:12 — 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…
#! /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 02:00
Add autoreload to the top of notebook to reload modules before executing code
%load_ext autoreload
%autoreload 2
# https://ipython.org/ipython-doc/3/config/extensions/autoreload.html
@yang-zhang
yang-zhang / jupyter notebook header
Last active December 8, 2018 20:54
Common commands to add to top of jupyter notebooks
%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 02:04
Check out remote github branch
git fetch origin
git checkout -b target_branch origin/target_branch
@yang-zhang
yang-zhang / howto add github remote
Created May 19, 2018 02:07
How to 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 02:09
How to remove file from git but keep locally
git rm --cached -r file_to_remove_and_keep_local.py
@yang-zhang
yang-zhang / howto format date time python
Last active August 24, 2018 18:05
Format printable date time in python
import datetime
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
datetime.datetime.now().strftime('%Y-%m-%d-%H')
@yang-zhang
yang-zhang / howto reload module py3
Created May 19, 2018 02:14
Reload module in Python3
from importlib import reload
reload(some_module)
@yang-zhang
yang-zhang / howto jupyter display dataframe options
Last active November 20, 2019 15:12
How to set dataframe display options for IPython and Jupyter notebook
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 02:25
How to untar all tar files in a directory
!for a in `ls -1 *.tar`; do tar xf $a; done