Skip to content

Instantly share code, notes, and snippets.

@rday
rday / gist:2644245
Created May 9, 2012 12:43
Quick IP addresses functions
import socket
import struct
def quadtolong(ip):
return struct.unpack('!L',socket.inet_aton(ip))[0]
def longtoquad(long):
return socket.inet_ntoa(struct.pack('!L', long))
def inc_ip(ip):
@rday
rday / gist:3504674
Created August 28, 2012 21:52
Abstract wrapper to allow connection pools
type InitFunction func() (interface{}, error)
type ConnectionPoolWrapper struct {
size int
conn chan interface{}
}
/**
Call the init function size times. If the init function fails during any call, then
the creation of the pool is considered a failure.
@rday
rday / gist:3504712
Created August 28, 2012 21:59
ConnectionPool Implementation
/**
This function creates a connection to the database. It shouldn't have to know anything
about the pool, It will be called N times where N is the size of the requested pool.
*/
func initCirrusConnections() (interface{}, error) {
dbserver, _ := configFile.GetString("default", "dbserver")
dbuser, _ := configFile.GetString("default", "dbuser")
dbpass, _ := configFile.GetString("default", "dbpass")
db := autorc.New("tcp", "", dbserver, dbuser, dbpass)
@rday
rday / gist:3711685
Created September 13, 2012 03:36
Install Golang
# Setup your home directory to handle a go installation
mkdir ~/go
cd ~/
# Grab and untar the binary the binary
# If you have a 64bit system, use http://go.googlecode.com/files/go1.0.2.linux-amd64.tar.gz
wget http://go.googlecode.com/files/go1.0.2.linux-386.tar.gz
tar -xzf go1.0.2.linux-386.tar.gz
# Setup your environment to handle the root Go install
@rday
rday / gist:3712141
Created September 13, 2012 05:45
Json decode
package main
import "fmt"
import "encoding/json"
import "net/http"
import "bytes"
type Test struct{
Name string
Token string
@rday
rday / gist:4742553
Last active December 12, 2015 08:18
#
# Skeleton code, don't use this because it isn't going to work for you
"""
This is heavily taken from the MovingAverage
"""
import numpy
import talib
from numbers import Number
@rday
rday / gist:4745333
Created February 9, 2013 13:50
TA Transform take#2
'''
As usual, this is a wallofcode beta, don't use this in real life
'''
import numpy
import talib
from talib.abstract import Function
from numbers import Number
from collections import defaultdict
@rday
rday / gist:4964113
Created February 15, 2013 22:30
Datecheck
# Verify that our benchmark msgpack file is up to date
bm_list = msgpack.loads(fp_bm.read())
bm_date, _ = bm_list[len(bm_list)-1]
last_date = datetime(bm_date[0], bm_date[1], bm_date[2])
today = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
if last_date < today-timedelta(days=1):
update_benchmarks(last_date)
fp_bm = get_datafile('benchmark.msgpack', "rb")
@rday
rday / TATransform.py
Created March 4, 2013 02:36
TATransform example for handling two talib functions, SMA and BBands.
import numpy
from talib.abstract import Function
from numbers import Number
from collections import defaultdict
from zipline.transforms.utils import EventWindow, TransformMeta
class TATransform(object):
"""
@rday
rday / batch_transform.py
Created March 4, 2013 02:40
TA Lib batch_transform
@batch_transform
def bbands_transform(data, sid1):
print "bbands_transform()"
print data
inputs = {}
inputs['high'] = numpy.asarray([v for v in data.high[sid1]])
inputs['open'] = numpy.asarray([v for v in data.open[sid1]])
inputs['low'] = numpy.asarray([v for v in data.low[sid1]])
inputs['close'] = numpy.asarray([v for v in data.close[sid1]])