Skip to content

Instantly share code, notes, and snippets.

@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]])
@rday
rday / list_ma.py
Created June 5, 2013 17:29
List moving average
def moving_average(data_set, period=3):
avgs = []
for idx, item in enumerate(data_set[period-1:]):
avgs.append(round(sum(data_set[idx:period+idx]) / float(period), 2))
return avgs
data = [1, 2, 3, 6, 9, 12, 20, 28, 30, 25, 22, 20, 15, 12, 10]
@rday
rday / ex.py
Created June 13, 2013 23:41
A brief example
import time
import numpy as np
def naive():
x = 0
y = 0
for i in range(1, 1001):
x += pow(i, 2)
y += i
return pow(y, 2) - x
@rday
rday / astmod.c
Created August 30, 2013 14:43
Asterisk mod sample
static void *rtp_thread(void *args)
{
struct ap_info* thread_info = args;
struct ast_frame *f = NULL;
struct ast_rtp *astRtp = NULL; // XXX <-- Replaced by rtp_engine
int pktCnt=0;
int res = 0;
astRtp = ast_rtp_new_fd(thread_info->sockFd); // XXX <-- Doesn't event exist anymore
@rday
rday / context.go
Last active December 31, 2015 07:39
Brief example of an application specific context
// Struct to hold all my application's commonly used packages
type MySpecialContext struct {
Render render.Render
Logger *log.Logger
Session sessions.Session
Db *mgo.Database
Ctx martini.Context
App *ApplicationConfig
}
@rday
rday / Makefile
Last active January 4, 2016 22:49
Makefile for the rump kernel python package
# XXX
# When building the latest version of Python (3.5.1) some binaries are built in order
# to build other binaries. For example, we need the Parser/pgen binary to generate a
# parser from the Grammar file. This requires us to build some *host* binaries before
# we apply patches and build the target (-rumprun) version of Python.
#
# The problem is that the 'hostbuild' task looks like it could be done better. I'm
# looking for ideas to improve that piece.
include ../Makefile.inc
@rday
rday / stack.go
Created January 7, 2016 01:30
Golang stacktrace
[negroni] Completed 200 OK in 3.955256ms
[negroni] Started GET /authfail
[negroni] Completed 200 OK in 10.011542ms
[negroni] Started GET /authfail
[negroni] Completed 200 OK in 9.598809ms
[negroni] Started GET /authfail
[negroni] Completed 200 OK in 11.324298ms
[negroni] Started GET /authfail
cannot handle page request order 16/0x1000!
panic: fatal error: malloc deadlock