Skip to content

Instantly share code, notes, and snippets.

View pnavarro-algometrics's full-sized avatar

Pablo Navarro Castillo pnavarro-algometrics

  • Algometrics
  • Chile
View GitHub Profile
@pnavarro-algometrics
pnavarro-algometrics / numpy-sqlite3.py
Created April 27, 2011 14:03
Insert numpy array into a sqlite3 database
import sqlite3
import numpy
# Array of 4 columns and 100 rows
data = numpy.random.rand(100, 4)
# Create a sample database
conn = sqlite3.connect('/tmp/sample.db')
cursor = conn.cursor()
@pnavarro-algometrics
pnavarro-algometrics / subprocess-stdout.py
Created April 27, 2011 15:19
Capture the output of a command line command with subprocess
# Capture the output of a process
import shlex
import subprocess
cmdline = 'date --help'
p = subprocess.Popen(shlex.split(cmdline), stdout=subprocess.PIPE)
print(p.stdout.read())
@pnavarro-algometrics
pnavarro-algometrics / plot-price-time.py
Created May 19, 2011 17:00
Plot prices with time in the x axis
from numpy import *
from matplotlib.pylab import *
import matplotlib.dates as mdates
data = loadtxt('quotes.csv', delimiter=',')
# Epoch time to number (matlab and matplotlib format)
TIMEZONE_CORRECTION = 60.0 * 60 * 5
time = mdates.epoch2num(data[:, 0] / 1000.0 - TIMEZONE_CORRECTION)
bid = data[:, 1]