Skip to content

Instantly share code, notes, and snippets.

@nkrumm
nkrumm / hack.sh
Created June 6, 2013 04:34 — forked from erikh/hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@nkrumm
nkrumm / matplotlib_color_Gen
Created June 7, 2013 15:27
color generator for matplotlib
NUM_COLORS = 22
cm = get_cmap('gist_rainbow')
for i in range(NUM_COLORS):
color = cm(1.*i/NUM_COLORS) # color will now be an RGBA tuple
@nkrumm
nkrumm / infinite defaultdict
Created June 9, 2013 21:38
infinite default dict (courtesy of @raymondh)
infinite_defaultdict = lambda: defaultdict(infinite_defaultdict)
d = infinite_defaultdict()
d['x']['y']['z'] = 10
@nkrumm
nkrumm / Matplotlib Tufte Style
Created June 11, 2013 23:54
Styles an matplotlib axes with minimalist features (a la Edward Tufte)
def tuftestyle(ax):
"""Styles an axes object to have minimalist graph features"""
ax.grid(True, 'major', color='w', linestyle='-', linewidth=1.5,alpha=0.6)
ax.patch.set_facecolor('white')
#ax.set_axisbelow(True)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
ax.spines["bottom"].set_visible(False)
@nkrumm
nkrumm / draw_bars
Created June 11, 2013 23:57
Draw horizontal p-value comparison bars in barplots
def drawBars(ax, s, ypos, xpos = [0.5,1.5], tick_height = 0.02, fontsize=12, fontcolor="black"):
ypos = ypos/float(ax.get_ylim()[1]) + tick_height
trans = transforms.blended_transform_factory(ax.transData, ax.transAxes)
l = Line2D([xpos[0], xpos[0], xpos[1], xpos[1]],[ypos, ypos+tick_height, ypos+tick_height, ypos], lw=1.5, c="k", transform=trans)
ax.text(xpos[0] + ((xpos[1]-xpos[0])/2.), ypos + (tick_height*1.5), s=s, ha= "center", va="bottom", fontsize=fontsize, color=fontcolor, transform=trans)
ax.add_line(l)
@nkrumm
nkrumm / autolabel barplots
Created June 11, 2013 23:58
Handy function to label barplots
def autolabel(ax,rects,text,fmt=None,below=False,offset_fraction=0.05):
for rect,t in zip(rects,text):
height = rect.get_height()+rect.get_y()
if below:
ax.text(rect.get_x()+rect.get_width()/2., (1-offset_fraction)*height, t,
ha='center', va='top', **fmt)
else:
ax.text(rect.get_x()+rect.get_width()/2., (1+offset_fraction)*height, t,
ha='center', va='bottom', **fmt)
@nkrumm
nkrumm / github_cli.bash
Last active December 21, 2015 00:59
git hub command line improvements
Improve the log (https://coderwall.com/p/euwpig?i=3&p=1&t=git)
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
Enable color in git:
git config --global --add color.ui true
Make git push only push the current branch
git config --global push.default current
@nkrumm
nkrumm / gist:6245527
Created August 15, 2013 22:25
Show all duplicated lines in a dataframe
pd.concat(g for _, g in df.groupby("duplicated_key_name") if len(g) > 1)
@nkrumm
nkrumm / gist:6710127
Created September 26, 2013 05:16
colorful PS1
# Reset
Color_Off="\[\033[0m\]" # Text Reset
# Regular Colors
Black="\[\033[0;30m\]" # Black
Red="\[\033[0;31m\]" # Red
Green="\[\033[0;32m\]" # Green
Yellow="\[\033[0;33m\]" # Yellow
Blue="\[\033[0;34m\]" # Blue
Purple="\[\033[0;35m\]" # Purple
@nkrumm
nkrumm / macros.simple_table.html
Last active December 24, 2015 00:59
simple_table jinja2 macro
{% macro simple_table(data, rowlink_prefix, column_order, column_names, id_field="_id") %}
<table class="table table-hover table-condensed" data-provides="rowlink">
{{ table_header(column_names|default(column_order|default(data[0])))}}
<tbody>
{% for row in data %}
<tr>
{% for item in column_order|default(row) %}
{% if (rowlink_prefix != None) and (item == id_field) %}
<td><a href='{{ rowlink_prefix + row[item] | string }}'>{{ row[item] }}</a></td>