Skip to content

Instantly share code, notes, and snippets.

View luispedro's full-sized avatar

Luis Pedro Coelho luispedro

View GitHub Profile
@luispedro
luispedro / getidentica.py
Created January 14, 2010 14:58
Generate an email signature from identi.ca
#!/usr/bin/env python
# Copyright 2010 (C) Luis Pedro Coelho
# License: MIT
import urllib2
header = '''\
Luis Pedro Coelho
http://luispedro.org
'''
username = 'luispedro'
@luispedro
luispedro / gist:278594
Created January 16, 2010 02:10
Parse a date
import time
def parsedate(daterep):
'''
time = parsedate(daterep)
Parses a date written out in English.
'''
formats = ['%d %b %Y', '%d %B %Y', '%b %d %Y', '%B %d %Y']
for f in formats:
@luispedro
luispedro / passenger_wsgi.py
Created January 29, 2010 04:35
Debug passenger_wsgi on dreamhost
import sys, os
INTERP = "/home/papsweb/virtualenv/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(os.getcwd())
sys.path.append(os.getcwd()+'/papswebsite')
os.environ['DJANGO_SETTINGS_MODULE'] = "papswebsite.settings"
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
@luispedro
luispedro / gettwitter.py
Created February 2, 2010 04:04
get twitter status
#!/usr/bin/env python
# Copyright 2010 (C) Luis Pedro Coelho
# License: MIT
import urllib2
import simplejson
header = '''\
Luis Pedro Coelho
http://luispedro.org
'''
@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
@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 / 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 / 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)
def is_ascii(s):
'''
ascii = is_ascii(s)
Check whether a unicode string is ASCII
'''
try:
s = s.encode('ascii')
return True
except UnicodeError:
[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