This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In settings.py: | |
import os | |
OUR_ROOT = os.path.realpath(os.path.dirname(__file__)) | |
# In urls.py: | |
from django.conf import settings | |
import os | |
urlpatterns = patterns('', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Django: validate that an uploaded file is a valid PDF | |
import pyPdf # from http://pybrary.net/pyPdf/ | |
from pyPdf.utils import PdfReadError | |
class DocumentForm(forms.ModelForm): | |
pdf = forms.FileField() | |
class Meta: | |
model = Document | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
(function(loc) { | |
if (loc.pathname == '/') { | |
return; | |
} | |
var uri_re = | |
/^(?:(?:[^:\/?#]+):)?(?:\/\/(?:[^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/; | |
var target_domain = ''; | |
loc.href.replace(uri_re, function(all, path, query, frag) { | |
var dst, src; dst = src = path + (query ? '?' + query : ''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkvirtualenv lxml-install-env | |
New python executable in lxml-install-env/bin/python | |
Installing setuptools...asy......... done. | |
(lxml-install-env)$ easy_install lxml | |
Searching for lxml | |
Reading http://pypi.python.org/simple/lxml/ | |
Reading http://codespeak.net/lxml | |
Best match: lxml 2.2.2 | |
Downloading http://codespeak.net/lxml/lxml-2.2.2.tgz | |
Processing lxml-2.2.2.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd /tmp | |
wget http://codespeak.net/lxml/lxml-2.2.2.tgz | |
tar -xzvf lxml-2.2.2.tgz | |
cd lxml-2.2.2 | |
cd libs/ | |
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz | |
wget ftp://xmlsoft.org/libxml2/libxslt-1.1.24.tar.gz | |
cd .. | |
python setup.py build --static-deps --libxml2-version=2.7.3 --libxslt-version=1.1.24 | |
sudo python setup.py install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import freebase # http://code.google.com/p/freebase-python/ | |
def bulk_lookup(ids): | |
return freebase.mqlreadmulti([species_query(i) for i in ids]) | |
def _species_query(id): | |
return { | |
'id': id, | |
'type': '/biology/organism_classification', | |
'name': None, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import freebase, json | |
freebase.search('tiger', | |
type = '/biology/organism_classification', | |
limit = 5, | |
mql_output = json.dumps([{ | |
'id': None, | |
'name': None, | |
'/biology/organism_classification/scientific_name': None | |
}]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime, time | |
def to_isoformat(dt): | |
return dt.isoformat().split('.')[0] | |
def from_isoformat(s): | |
s = s.split('.')[0] | |
return datetime.datetime( | |
*time.strptime(s, '%Y-%m-%dT%H:%M:%S')[:6] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def json_diffs(a, b, path='_'): | |
errors = [] | |
if type(a) != type(b): | |
return ['%s: Type of a (%s) != type of b (%s)' % (path, type(a), type(b))] | |
if type(a) == dict: | |
for key in a: | |
new_path = path + ('[%s]' % key) | |
if key not in b: | |
errors.append('%s: Key %s present in a but not in b' % (new_path, key)) | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
svn co svn://svn.xapian.org/xapian/branches/geospatial xapian-geo | |
sudo apt-get install build-essential m4 perl python zlib1g-dev uuid-dev wget | |
sudo apt-get install libpcre3-dev | |
sudo apt-get install flex bison | |
cd xapian-geo/ | |
./bootstrap | |
./configure --enable-maintainer-mode --enable-documentation=no --with-python | |
make | |
sudo make install | |
cd /usr/lib |