Skip to content

Instantly share code, notes, and snippets.

@jiffyclub
jiffyclub / svstatic
Last active Oct 19, 2020
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.
View svstatic
#!/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.
@jiffyclub
jiffyclub / markdown_doc
Last active Oct 14, 2020
This script turns Markdown into HTML using the Python markdown library and wraps the result in a complete HTML document with default Bootstrap styling so that it's immediately printable. Requires the python libraries jinja2, markdown, and mdx_smartypants.
View markdown_doc
#!/usr/bin/env python
import argparse
import sys
import jinja2
import markdown
TEMPLATE = """<!DOCTYPE html>
<html>
@jiffyclub
jiffyclub / conda.fish
Last active Sep 30, 2020
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.
View conda.fish
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 / tserv
Last active Sep 3, 2020
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.
View tserv
#!/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 / game_of_life.ipynb
Created Sep 24, 2012
Conway's Game of Life in an IPython Notebook
View game_of_life.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jiffyclub
jiffyclub / jdutil.py
Created Oct 18, 2011
Functions for converting dates to/from JD and MJD
View jdutil.py
"""
Functions for converting dates to/from JD and MJD. Assumes dates are historical
dates, including the transition from the Julian calendar to the Gregorian
calendar in 1582. No support for proleptic Gregorian/Julian calendars.
:Author: Matt Davis
:Website: http://github.com/jiffyclub
"""
@jiffyclub
jiffyclub / pygments_magic.py
Created Apr 15, 2013
Ipython magics for displaying source code files with syntax highlighting.
View pygments_magic.py
"""
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 / mpl_sheets_pandas.ipynb
Created Nov 11, 2014
Matplotlib stylesheets + Pandas plots
View mpl_sheets_pandas.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jiffyclub
jiffyclub / .gitconfig
Last active Oct 7, 2019
My git aliases
View .gitconfig
[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 / hdf_to_parquet.py
Last active Aug 8, 2019
Do the same thing in Spark and Pandas
View hdf_to_parquet.py
"""
Convert Pandas DFs in an HDFStore to parquet files for better compatibility
with Spark.
Run from the command line with:
spark-submit --driver-memory 4g --master 'local[*]' hdf5_to_parquet.py
"""
import pandas as pd
You can’t perform that action at this time.