Skip to content

Instantly share code, notes, and snippets.

View jgosmann's full-sized avatar

Jan Gosmann jgosmann

View GitHub Profile
@jgosmann
jgosmann / git_svn_bash_prompt.sh
Created June 14, 2011 21:03 — forked from woods/git_svn_bash_prompt.sh
Set color bash prompt according to git/svn branch, and return status of last command.
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the branch/status of the current git repository
# * the branch of the current subversion repository
# * the return value of the previous command
#
# USAGE:
@jgosmann
jgosmann / flexmock_numpy.py
Created December 8, 2011 13:36
Example of incompatibility between flexmock and numpy arrays
from flexmock import *
import numpy as np
import unittest
class FlexmockNumpyTest(unittest.TestCase):
def testFlexmockNumpy(self):
someArray = np.array([[0, 1], [2, 3]])
equalToSomeArray = someArray.copy()
function! PythonAndRopeComplete(findstart, base)
if a:findstart
let result = pythoncomplete#Complete(a:findstart, a:base)
let s:useRope = 1
if result > 0
silent! if len(pythoncomplete#Complete(0, a:base)) > 0
let s:useRope = 0
endif
endif
if s:useRope
@jgosmann
jgosmann / spike_train_metrics.md
Last active December 10, 2015 22:18
Spike train metrics still to implement in spykeutils.

Done

  • VP distance (with choseable kernel)
  • van Rossum's distance
  • Schreiber et al similarity measure -> basically equivalent to CS distance, but is a computationally more efficient implementation
  • Inner-product distance measures (norm distance, Cauchy-Schwarz)
  • Multi-neuron variants of VP and van Rossum distance
  • Hunter-Milton Similarity
  • Event synchronization
@jgosmann
jgosmann / empty_matcher.py
Created July 18, 2013 15:16
PyHamcrest matcher for matching empty sequences.
from hamcrest.core.base_matcher import BaseMatcher
class Empty(BaseMatcher):
def _matches(self, item):
if hasattr(item, '__len__'):
return len(item) == 0
elif hasattr(item, 'count'):
return item.count() == 0
raise TypeError('%s cannot be tested for emptiness.' % (
@jgosmann
jgosmann / xmasregex.py
Created December 15, 2013 23:46
Generate a regular expression matching all numbers of the following form: - Any number of digits as written out English words (case insensitive) followed by at least one whitespace. Any number witch typos (e.g. eihgt instead of eight) are allowed, but no character must move more than one position. - followed by any number of digits.
#!/usr/bin/nev python
def gen_switch_typo_variants(string):
if len(string) < 2:
return [string]
var1 = [string[0] + v for v in gen_switch_typo_variants(string[1:])]
var2 = [string[1::-1] + v for v in gen_switch_typo_variants(string[2:])]
return var1 + var2
@jgosmann
jgosmann / .gitignore
Created January 22, 2014 20:05
Global .gitignore template.
.*.swp
.ropeproject
@jgosmann
jgosmann / broadcast.py
Last active August 29, 2015 13:56
List which broadcasts all operations to its elements.
class Broadcast(list):
"""List which broadcasts all operations to its elements."""
def __getattr__(self, name):
if name.startswith('__'):
# Necessary to allow easy casting to numpy arrays.
raise AttributeError(
"No implicit broadcast of attributes starting with '__'. Use "
"explicit call to broadcast().")
@jgosmann
jgosmann / ipylisting.py
Created February 6, 2014 22:15
Code to include formatted sources in IPython notebooks.
# Some code do include nicely formatted source code listings of external
# files. Unfortunately, these listings will not be included using
# nbconvert to convert the notebook to a PDF.
import IPython
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
def include_listing(filename):
$pdflatex = "xelatex %O %S";
$pdf_mode = 1;
$postscript_mode = $dvi_mode = 0;