Skip to content

Instantly share code, notes, and snippets.

View brianspiering's full-sized avatar

Brian Spiering brianspiering

  • San Francisco, CA, USA
View GitHub Profile
@brianspiering
brianspiering / Default (OSX).sublime-keymap
Created February 8, 2014 19:10
My Sublime Text 2 key bindings
[{ "keys": ["super+k", "super+t"], "command": "title_case" },
{ "keys": ["super+shift+r"], "command": "Marked" }
]
@brianspiering
brianspiering / load_packages.r
Last active August 29, 2015 13:56
Automatically check and install packages in R
# Setup Packages ---------------------------------------------------------------
# List of packages for session
.packages <- c("devtools", "dplyr", "ggplot2", "markdown")
# Install CRAN packages (if not already installed)
.inst <- .packages %in% installed.packages()
if(length(.packages[!.inst]) > 0) install.packages(.packages[!.inst])
# Load packages for session
lapply(.packages, require, character.only=TRUE)
@brianspiering
brianspiering / .bashrc
Last active August 29, 2015 13:56
My .bashrc
# Set up virtual environments for Python
# ------------------------------------------------------------
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
# Start R quietly
# ------------------------------------------------------------
alias R='R -q'
### Added by the Heroku Toolbelt
@brianspiering
brianspiering / Log analysis
Created November 25, 2014 15:56
Sum the events for each day using the reduce algorithm.
# Sum the events for each day using the reduce algorithm.
from itertools import groupby
from operator import itemgetter
logs = [('2009-09-02', 11),
('2009-09-02', 3),
('2009-09-03', 10),
('2009-09-03', 4),
('2009-09-03', 22),
@brianspiering
brianspiering / template.r
Created May 3, 2015 15:37
Template for R programs
#! /usr/bin/env Rscript
# File description -------------------------------------------------------------
#
#
# Setup packages ---------------------------------------------------------------
# List of packages for session
.packages = c("devtools",
"stringr",
@brianspiering
brianspiering / print_text_in_color.py
Last active November 17, 2015 20:55
Print text to terminal in color
#!/usr/bin/env python
""" Print text to terminal in color!
The way of the future.
"""
import sys
# Define ASCII color codes
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = map(lambda x: x+30, range(8))
#!/usr/bin/env bash
# Automagically update all packages on a Mac
#
# Some people would consider this approach "harmful". I want to be on the cutting edge...
# The new features from the community are very nice. But more importantly, I want to break my code early and loudly.
# This approach cultivates long-term code resilience.
################################################################################
# brew: Manages all command line utilities and Mac binaries (via Cask).
brew update && brew install `brew outdated`
#!/usr/bin/env bash
# Setup a new Mac by installing all apps automatically
# Install Homebrew, http://brew.sh/
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew tap caskroom/cask
{
"color_scheme": "Packages/MarkdownEditing/MarkdownEditor-Dark.tmTheme",
"draw_centered": false
}
@brianspiering
brianspiering / start.ipy
Last active February 1, 2017 15:42
Jupyter Notebook: IPython kernal defaults
# ~/.ipython/profile_default/startup/start.ipy
# HT: http://people.duke.edu/~ccc14/sta-663-2016/Customizing_Jupyter.html
from functools import reduce, partial
import itertools as it
import glob
import operator as op
import os
import sys