Skip to content

Instantly share code, notes, and snippets.

View maedoc's full-sized avatar

marmaduke woodman maedoc

  • now
  • here
View GitHub Profile
@maedoc
maedoc / metafu.py
Last active December 30, 2015 10:19
Reminder of how Python metaclasses work
offset=[0]
def log(f):
def wrap(*args, **kwds):
tab = '\t'*offset[0]
print tab, f, args, kwds
offset[0] += 1
ret = f(*args, **kwds)
print tab, f, ' () -> ', ret
offset[0] -= 1
@maedoc
maedoc / traits_ndarray.py
Last active July 27, 2017 02:06
NDArray traits type based on IPython's traitlets module.
"""
traits_ndarray
--------------
I was taking the IPython.utils.traitlets for a spin;
the only really useful thing missing was an NDArray
which validates on certain shape and type constraints
and notifies for interesting kinds of inequalities
id(x)==id(y), (x==y).all(), allclose(x, y).
@maedoc
maedoc / seeg_bip.py
Created January 15, 2014 10:43
sEEG bipolar w/ MNE-Python
import sys
import glob
import numpy as np
from mne import fiff, event, epochs
from iidc import detect, stat, util, cluster
#### Data
# Load the data, then eliminate all but the sEEG channels
@maedoc
maedoc / show_ascii.py
Created January 17, 2014 09:24
`show()` a matplotlib figure in ASCII
# coding: utf-8
import PIL
import tempfile
def show_ascii(w=200, h=50, chars=' .\',;"oO%8@#'):
from pylab import tight_layout, savefig
tight_layout()
with tempfile.NamedTemporaryFile(suffix='.png') as f:
savefig(f.name)
@maedoc
maedoc / gist:8878751
Created February 8, 2014 08:50
Benchmark class generator vs function generator
# coding: utf-8
import time
import operator as op
import numpy as np
# equivalent generators
def foo(n):
@maedoc
maedoc / hrepl.py
Last active August 29, 2015 13:56
control Python REPL over HTTP
import os
import sys
import atexit
import tempfile
import traceback
from urlparse import urlparse, parse_qs
import BaseHTTPServer
try:
from cStringIO import StringIO
@maedoc
maedoc / foo_data.py
Created March 7, 2014 16:34
unruly adapter
import numpy
from tvb.adapters.uploaders.abcuploader import ABCUploader
from tvb.basic.logger.builder import get_logger
from tvb.core.adapters.exceptions import LaunchException
from tvb.datatypes.time_series import TimeSeries
from tvb.adapters.uploaders import foo_data_impl
class FooDataImporter(ABCUploader):
@maedoc
maedoc / pip-requirements.bat
Created March 8, 2014 08:34
Getting started with TVB from sources
pip install --user cherrypy formencode sqlalchemy sqlalchemy-migrate genshi simplejson cfflib nibabel apscheduler mod_pywebsocket psutil minixsv
@maedoc
maedoc / less-useful
Last active August 29, 2015 13:57
constrast stack traces
In [2]: %run new_importer_launcher.py
HDF5-DIAG: Error detected in HDF5 (1.8.9) thread 0:
#000: ..\..\src\H5F.c line 1534 in H5Fopen(): unable to open file
major: File accessability
minor: Unable to open file
#001: ..\..\src\H5F.c line 1223 in H5F_open(): unable to open file: time = Mon Mar 10 10:01:15 2014
, name = 'C:\Users\duke\TVB\PROJECTS\Default_Project_admin\17\TimeSeries_896585d1-a832-11e3-92b8-8851fb5dbed8.h5', tent_flags = 1
major: File accessability
minor: Unable to open file
#002: ..\..\src\H5FD.c line 1101 in H5FD_open(): open failed
@maedoc
maedoc / gist:9461756
Created March 10, 2014 09:10
start up log
C:\Users\duke\Desktop\TVB\svn\trunk>python bin\app.py clean
C:\Users\duke\Desktop\TVB\svn\trunk>python bin\app.py clean
C:\Users\duke\Desktop\TVB\svn\trunk>python bin\app.py start web
Found the first free port: 8080.
['python', '-m', 'tvb.interfaces.web.run', 'tvb.config', '-profile', 'DEPLOYMENT_PROFILE']
C:\Users\duke\Desktop\TVB\svn\trunk>2014-03-10 10:07:27,315 - INFO - tvb.interfaces.web.mplh5.mplh5_server - MPLH5 back-end server s
2014-03-10 10:07:32,203 - ERROR - tvb.datatypes.surfaces_scientific - Failed to import geodesic distance package from externals...