Skip to content

Instantly share code, notes, and snippets.

View jamesp's full-sized avatar

James Penn jamesp

  • Met Office
  • Devon, UK
View GitHub Profile
import pandas as pd
p = pd.read_csv('m:/presents.csv')
p[:10]
plt.plot(p[:10])
p.columns= 'id x y z'.split()
p['volume'] = p.x * p.y * p.z

iPython basics

Using the console

  • autcomplete works on variable and function names
  • Up arrow takes you back to previously entered commands
  • %quickref gives an overview of available functionality.

magic commands

iPython has "magic" commands which are an set of meta functions for

@jamesp
jamesp / Predator Prey Model.ipynb
Created December 1, 2013 12:50
Learning about iPython notebooks using a simple predator-prey model.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import pylab as lab
# don't show all decimal places when printing
np.set_printoptions(precision=4)
# define a, b and c
a = np.ones([4,4])
print "a:\n", a
@jamesp
jamesp / gist:1385745
Created November 22, 2011 14:10
A simple cache for keeping timeseries data in memory
from bisect import bisect_left, bisect_right
class TimeseriesCache(object):
"""Store a timeseries of data in memory for random access."""
def __init__(self, ttl=None):
self.timestamps = []
self.data = []
self.ttl = ttl
def add(self, timestamp, data):

Steamed Fish with Garlic Ginger Soy Sauce

Serves: 2

Ingredients

  • 1 Whole Fish (approx. 400g), gutted with head and tail still on.
  • 5-6 Spring Onions
@jamesp
jamesp / gist:148093
Created July 16, 2009 01:24
Bloomberg API in jRuby
include Java
require 'blpapi3.jar'
opts = com.bloomberglp.blpapi.SessionOptions.new
opts.server_host = 'localhost'
opts.server_port = 8194
session = com.bloomberglp.blpapi.Session.new opts
service = '//blp/refdata'
throw "Can't start Bloomberg" unless session.start && session.open_service(service)
@jamesp
jamesp / Mac OSX Erlang Install
Created June 27, 2009 16:17
Setting up erlang on the mac
### Download and install
cd /tmp
curl http://erlang.org/download/otp_src_R13B03.tar.gz | tar zx
cd otp_src_R13B
./configure --enable-hipe
make
sudo make install
sudo mkdir -p /Library/Erlang/lib
mkdir -p ~/Library/Erlang/lib
@jamesp
jamesp / gist:106362
Created May 4, 2009 07:36
RStakeout
#!/usr/bin/env ruby
# Originally by Mike Clark.
#
# From http://www.pragmaticautomation.com/cgi-bin/pragauto.cgi/Monitor/StakingOutFileChanges.rdoc
#
# Runs a user-defined command when files are modified.
#
# Can use Ruby's Dir[] to get file glob. Quote your args to take advantage of this.
#
# Built in library imports
import mimetypes
import re
import os
import sys
# Server imports
import urlparse
import cgi
class Juno(object):