Skip to content

Instantly share code, notes, and snippets.

View lightscalar's full-sized avatar

Matthew J. Lewis lightscalar

View GitHub Profile
@lightscalar
lightscalar / fill_between.md
Created June 5, 2014 13:51
Fill between two curves in matplotlib

Given data x, upper, and lower, you can plot the area between the two curves lower & upper using this code:

fill_between(x, upper, lower, facecolor='#ffcc33', alpha=0.4)
@lightscalar
lightscalar / amazon_with_python.md
Last active August 3, 2017 15:48
Configuring AMAZON for Python Development

First, let's upgrade the Amazon Linux setup to include Python 2.7.6. Most of these instructions from excellent article by Kreutzberger at http://www.lecloud.net/post/61401763496/install-update-to-python-2-7-and-latest-pip-on-ec2.

Unfortunately Amazon Linux 3.4 AMIs still ship with Python 2.6 which makes it impossible to run many Python apps. Also the installation and update/upgrade of Pip through yum python-pip fails and puts packages into the old 2.6 lib folder.

Here is my solution to upgrade to Python 2.7 including the latest Pip & Virtualenv. Just copy & paste line by line:

# install build tools 
sudo yum install make automake gcc gcc-c++ kernel-devel git-core -y 
@lightscalar
lightscalar / tricks.md
Created August 30, 2013 11:47
Tricks
for collection in $scope.collections
  collection.key_length = Object.keys(collection.keys).length
  var first_key
  for k of collection.keys
    first_key = k
    break
  collection.selected_key = collection.keys[first_key]
@lightscalar
lightscalar / uuid.md
Created August 27, 2013 13:03
Ruby UUID

Generate a UUID using UUIDTools:

UUIDTools::UUID.timestamp_create().to_s
@lightscalar
lightscalar / pickles.md
Created June 27, 2013 17:50
Pickling Python Files...
import cPickle as pickle

with open('%s.dat' $ bucket_id, 'wb') as outfile:
    pickle.dump(meta, outfile, protocol=pickle.HIGHEST_PROTOCOL)
@lightscalar
lightscalar / ruby_array.md
Last active December 17, 2015 05:28
Ruby Array Tricks

Suppose you have an array of multiple (i.e., more than two) ruby arrays,

ary = [[1,2,3,4], [4,5,6,7], [8,9,10,11]]

To zip together these arrays in an element-wise fashion, we can use the array's zip method:

zipped_ary = ary[0].zip(*ary.last(ary.size-1)) # => [[1,4,8], [2,5,9], [3,6,10], [4,7,22]]
@lightscalar
lightscalar / postgres.md
Created May 8, 2013 13:37
Getting POSTGRES launched

After installing the latest & greatest:

To have launchd start postgresql at login:

    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

Then to load postgresql now:

    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
@lightscalar
lightscalar / ruby-2.0.0.md
Created May 8, 2013 12:33
How to upgrade cleanly to ruby 2.0 via RVM

Upgrading to ruby 2.0:

$ rvm remove 2.0.0 # get rid of unsuccessful installation
$ rvm get head --autolibs=3 # get the latest RVM and build required libs
$ rvm requirements # just in case, install all other required stuff
$ rvm install ruby-2.0.0
$ rvm --default use ruby-2.0.0
@lightscalar
lightscalar / matplotlib.md
Created April 12, 2013 13:26
How to make things look nice in matplotlib.

Changing Fonts, etc.

To change the fonts on the plots to something nice,

    # Set the fonts to be something nice.
    font = {'family': 'helvetica', 'weight': 'light', 'size': 18}
    matplotlib.rc('font', **font)
@lightscalar
lightscalar / pandas.md
Last active December 14, 2015 00:39
Useful things related to PANDAS

Useful PANDAS Stuff

Installation & Upgrade

In order to upgrade pandas on OSX (or *NIX), use pip:

sudo pip install pandas --upgrade