Skip to content

Instantly share code, notes, and snippets.

View breuderink's full-sized avatar

Boris Reuderink breuderink

View GitHub Profile
@breuderink
breuderink / siks2tex.py
Created September 30, 2011 14:16
Converter for SIKS dissertation list to LaTeX
#!/usr/bin/env python
'''
Quick and dirty hack to get the SIKS dissertation list in LaTeX.
'''
import argparse, re, operator, itertools, sys
parser = argparse.ArgumentParser(
description='Convert SIKS dissertation list to LaTeX.')
parser.add_argument('txt')
parser.add_argument('tex')
@breuderink
breuderink / parse_log.py
Created May 13, 2012 11:01
Parser for HMI-AWoW logs.
#!/usr/bin/env python
import argparse, logging
from collections import namedtuple
import numpy as np
# TODO:
# - diff scan_code and key_id?
LOG_MOUSE_EVENTS = {
512 : 'mouse movement',
@breuderink
breuderink / client.py
Created July 11, 2012 13:07
Proof of concept of using Flask to serve EEG.
import json
import numpy as np
import requests
for i in range(1000):
# get some EEG samples
r = requests.get('http://localhost:5000/eeg/%d' % i)
S = np.fromstring(r.json['samples'].decode('base64'), np.float32)
S.shape = r.json['shape']
print 'Received:', r.json.keys(), S.shape
@breuderink
breuderink / gist:4194169
Created December 3, 2012 10:49
Memory leak with Jansson?
float mp_detection(mp_response_t *response, const char *detector_name)
{
json_t *json;
json_error_t error;
float p;
if (!response->ready) {
return NAN;
}
@breuderink
breuderink / gist:4225152
Created December 6, 2012 15:11
MindPlay Lua example
-- Initialize API:
mp = mindplay.init('localhost:5000', 'test_user', '1')
for i=0,10000 do
print('Frame ' .. i .. '.');
-- Update transfers in progress:
if (i % math.floor(FPS/3)) == 0 then
-- Perform (non-blocking) request for a detection:
print('Requesting prediction...')
response = mindplay.request_detection(mp)
@breuderink
breuderink / gist:4225173
Created December 6, 2012 15:12
MindPlay C example
#include "mindplay.h"
#define FPS 30
int main(void)
{
mp_api_t mp;
mp_response_t *response = NULL;
float p;
/* To start using MindPlay, we setup an API with with a server address, a
@breuderink
breuderink / gist:4412463
Created December 30, 2012 11:43
Closures, partial application caveats in Python
It can be convenient to generate a series of related, but different functions.
For example, I had to evaluate a statistical model with different parameters.
But the results were surprising, as can be seen with this simplified example:
>>> funs = [lambda : x for x in range(10)]
>>> print [f() for f in funs]
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
I would have expected each of these functions to return a different value.
The same problem occurs when we define a regular function:
@breuderink
breuderink / gist:4546493
Created January 16, 2013 11:27
Show EDF problem with Emotiv data.
import logging, argparse, itertools
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import eegtools
log = logging.getLogger(__name__)
@breuderink
breuderink / brainvision.py
Created August 19, 2013 08:33
Python skeleton to read BrainVision EEG files.
# License: BSD 3-clause
# Author: Boris Reuderink
import logging, re, os.path, StringIO, itertools
from ConfigParser import SafeConfigParser
import numpy as np
# TODO:
# - add encoding of commas (\1)
# - verify units for resolution in UTF8
clear all; clear path;
addpath('/data1/toolbox/fieldtrip_new/');
ft_defaults;
fname = '/data1/import/agboekenweek/import2/03/eeg_03.bdf'
cfg.dataset = fname
hdr = ft_read_header(fname)
evt = ft_read_event(fname)
dat = ft_read_data(fname)