Skip to content

Instantly share code, notes, and snippets.

View tristanwietsma's full-sized avatar

Tristan Wietsma tristanwietsma

  • Chicago, Illinois
View GitHub Profile
@tristanwietsma
tristanwietsma / govfeed.py
Created June 12, 2014 15:59
Bit.ly USA.gov feed
import socket, time
# http://www.usa.gov/About/developer-resources/1usagov.shtml
s = socket.socket()
s.connect(('developer.usa.gov', 80))
s.send('GET /1usagov HTTP/1.0\n\n')
s.setblocking(False)
while True:
//Practically all this code comes from https://github.com/alangrafu/radar-chart-d3
//I only made some additions and aesthetic adjustments to make the chart look better
//(of course, that is only my point of view)
//Such as a better placement of the titles at each line end,
//adding numbers that reflect what each circular level stands for
//Not placing the last level and slight differences in color
//
//For a bit of extra information check the blog about it:
//http://nbremer.blogspot.nl/2013/09/making-d3-radar-chart-look-bit-better.html
@tristanwietsma
tristanwietsma / mockery.py
Created July 8, 2014 02:52
Mocking Boto with Moto
import boto
from moto import mock_s3
from model import MyModel
@mock_s3
def test_save_study():
conn = boto.connect_s3()
conn.create_bucket('mybucket')
require 'pp'
require 'socket'
module BluetoothPolarHrm
AF_BLUETOOTH=31 # these are correct for the Linux Bluez stack
BTPROTO_RFCOMM=3
class << self
def connect_bt address_str,channel=1
bytes=address_str.split(/:/).map {|x| x.to_i(16) }
s=Socket.new(AF_BLUETOOTH, :STREAM, BTPROTO_RFCOMM)
class LazyCollection extends Backbone.Collection
indexQuerystring: 'index'
index: 1
lastLength: 0
fetch: (options) ->
options or= {}
if options.reset
@index = 1
@lastLength = 0
else
/*
** Client side - /public/src/app.js
*/
var myApp = {
// Collections
Collections: {
list: Backbone.Collection.extend()
},
// Views
@tristanwietsma
tristanwietsma / README
Last active August 29, 2015 14:20
Jest Example
# Jest Example
This is directly from the jest website.
## Requirements
- node
- npm
## Install
@tristanwietsma
tristanwietsma / animals.txt
Last active December 16, 2015 18:29
Go file I/O example This shows how to read a text file in Go, line-by-line. The file is supplied via command-line. A list of lines is built using a slice and the append function. Duplicate lines are prevented using a map. The resulting list of lines is sorted and displayed.
Aardvark
Elephant
Albatross
Alligator
Alpaca
Anaconda
Ant
Anteater
Antelope
Armadillo
@tristanwietsma
tristanwietsma / batchjobs.py
Created April 30, 2013 01:15
Batch execution Given an list of shell commands, this script batches them out according to user-defined batch size or default CPU count.
import threading, os, sys
from multiprocessing import cpu_count
NUM_CPUS = cpu_count()
def batch_process(command_list, batch_size=NUM_CPUS):
iteratorlock = threading.Lock()
exceptions = []
cmd = command_list.__iter__()
@tristanwietsma
tristanwietsma / eurodollar_exdates.py
Created April 30, 2013 01:26
CME Eurodollar futures expiration date calculator
from datetime import datetime, date, timedelta
def EurodollarExpirations():
start = datetime.now().date()
n = 20
ex = [date(2008,12,15)]
for i in range(120):
x = ex[-1]
x += timedelta(days=91)
if x.day <= 12: x += timedelta(days=7)