Skip to content

Instantly share code, notes, and snippets.

@jiffyclub
jiffyclub / .gitconfig
Last active October 7, 2019 21:06
My git aliases
[core]
editor = code -nw
[alias]
st = status
ls = log --oneline --decorate
lg = log --oneline --decorate --graph
ff = merge --ff-only
mrg = merge --no-ff
ffpull = pull --ff-only
co = checkout
@jiffyclub
jiffyclub / mpl_sheets_pandas.ipynb
Created November 11, 2014 18:26
Matplotlib stylesheets + Pandas plots
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jiffyclub
jiffyclub / pygments_magic.py
Created April 15, 2013 03:27
Ipython magics for displaying source code files with syntax highlighting.
"""
IPython magics for displaying source code files with syntax highlighting.
This uses the Pygments library: http://pygments.org.
Two magics are available:
%highlight: This uses a terminal formatter and will work in any of IPython's
front ends.
%highlight_html: This uses an HTML formatter and is best used in the
@jiffyclub
jiffyclub / tserv
Last active September 3, 2020 09:14
Start a Tornado static file server in a given directory. To start the server in the current directory: `tserv .`. Then go to `http://localhost:8000` to browse the directory.
#!/usr/bin/env python
"""
Starts a Tornado static file server in a given directory.
To start the server in the current directory:
tserv .
Then go to http://localhost:8000 to browse the directory.
Use the --prefix option to add a prefix to the served URL,
@jiffyclub
jiffyclub / assert_frames_equal.ipynb
Last active October 27, 2020 17:02
Example of a function to compare two DataFrames independent of row/column ordering and with handling of null values.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jiffyclub
jiffyclub / long_string.ipynb
Created April 15, 2014 18:11
Example of splitting a long string over multiple lines (in an IPython Notebook). http://nbviewer.ipython.org/gist/jiffyclub/10754538
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jiffyclub
jiffyclub / precipout.py
Last active November 15, 2020 00:37
Example of using Orca to download and concatenate multiple datasets from the California Department of Water Resources. More on Orca at https://udst.github.io/orca/.
import sys
from datetime import datetime
import orca
from caldwr.parsers.precipout import load_precipout
# this will be replaced when calling orca.run, but it's good to
# have a placeholder here so things don't crash when evaluating
# stuff ala carte or with orca-server.
@jiffyclub
jiffyclub / snakeviz_magic.py
Last active February 8, 2021 14:16
Magics for starting Snakeviz from IPython. Use %snakeviz and %%snakeviz in place of %prun and %%prun to profile a block of code and launch a Snakeviz view of the profile.
import subprocess
import tempfile
import time
from IPython.core.magic import register_line_cell_magic
def snakeviz(line, cell=None):
"""
Profile code and display the profile in Snakeviz.
@jiffyclub
jiffyclub / conda.fish
Last active December 8, 2021 08:46
Activate and deactivate commands for working with conda environments in the fish shell. Currently assumes you are switching to a named environment, not specifying a directory.
function condalist -d 'List conda environments.'
for dir in (ls $HOME/miniconda3/envs)
echo $dir
end
end
function condactivate -d 'Activate a conda environment' -a cenv
if test -z $cenv
echo 'Usage: condactivate <env name>'
return 1
@jiffyclub
jiffyclub / svstatic
Last active January 20, 2022 06:00
Convert a SnakeViz HTML file into a self-contained static file that can be hosted anywhere. This script replaces instances of static files being loaded from the local server by having them come from the rawgit CDN.
#!/usr/bin/env python
"""
Prepare an HTML file from SnakeViz for use as a static page.
This makes it so all static files are loaded from a CDN instead
of from the local server.
To get the SnakeViz HTML file run the snakeviz CLI to load a profile
in your browser, than save that page as an HTML file to your computer.
Finally, run this script on that HTML file.