Skip to content

Instantly share code, notes, and snippets.

View luispedro's full-sized avatar

Luis Pedro Coelho luispedro

View GitHub Profile
import numpy as np
import mahotas
from scipy import ndimage
img = mahotas.imread('copy_cam1.jpg')
img = img.mean(2)
img = img.astype(float)
bead = img[433:443,495:512]
sy,sx = bead.shape
@luispedro
luispedro / lda.tex
Created April 5, 2011 16:29
LDA in TIKZ
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (theta) at (0,0) [circle, draw] {$\theta$};
\node (z) at (2,0) [circle, draw] {$z$};
\node (w) at (4,0) [circle, draw] {$w$};
\node (alpha) at (1,2) [circle, draw] {$\alpha$};
@luispedro
luispedro / load_sparse.py
Created September 21, 2010 13:28
Load a scipy.sparse.csr_matrix
# Load a sparse matrix.
import numpy as np
from scipy import sparse
def load_sparse(filename, dtype=np.float32):
with file(filename) as input:
ny,nx = input.readline().strip().split()
nelems = int(input.readline().strip())
@luispedro
luispedro / bloomfilter.py
Created August 7, 2010 22:07
Bloom filter in python
import numpy as np
def insert_bit(array, index):
inner = (index % 64)
index //= 64
array[index] |= (1 << inner)
def is_set(array, index):
inner = (index % 64)
index //= 64
[Script Info]
Title: Untitled
ScriptType: V4.00+
Collisions: Normal
Timer: 100
WrapStyle: 0
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeThrough, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default, Sans, 16, &H00FFFFFF, &H00FFFFFF, &H00674436, &HFFFFFFF8, -1, 0, 0, 0, 100, 90, 0, 0, 1, 2.1, 0.5, 2, 15, 15, 15, 0
def is_ascii(s):
'''
ascii = is_ascii(s)
Check whether a unicode string is ASCII
'''
try:
s = s.encode('ascii')
return True
except UnicodeError:
@luispedro
luispedro / create_directories.py
Created April 19, 2010 13:55
create directories
from os import path, mkdir, errno
def create_directories(dname):
'''
create_directories(dname)
Recursively create directories.
'''
if dname.endswith('/'): dname = dname[:-1]
head, tail = path.split(dname)
@luispedro
luispedro / bio.txt
Created April 2, 2010 19:48
biography
Luis Pedro Coelho is a PhD candidate in computational biology at Carnegie
Mellon University. He is interested in computational biology that is both
theoretically well-grounded and yields insights into real systems. Luis has a
BS and MS in computer science from Instituto Superior Técnico. He is a
Fulbright Scholar and has won multiple awards for academic or research
excellence.
Outside academia, Luis has been involved in theatre (having produced the
student group at IST and starred in several productions), as well as received a
prize in a short story competition. He has taught computer usage in
@luispedro
luispedro / timeout.py
Created March 23, 2010 22:40
set operation timers in python
from __future__ import division, with_statement
import signal
__all__ = ['TimeOutError', 'timeout']
class TimeOutError(Exception):
def __init__(self):
Exception.__init__(self,'Timeout')
def _raise_TimeOut(sig, stack):
@luispedro
luispedro / context_processors.py
Created February 10, 2010 04:23
template globals for Django
import settings
def add_globals(request):
return settings.TEMPLATE_GLOBALS