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
/* jQuery methods for accessing HTML comments and comment text | |
Only tested in Safari. */ | |
jQuery.fn.comments = function() { | |
return this.contents().filter(function() { | |
return this.nodeType == 8; | |
}) | |
}; | |
jQuery.fn.commentText = function() { | |
var s = []; |
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
/* Expanded form of a bookmarklet for extracting rev=canonical OR tinyurling a page */ | |
(function(){ | |
var url=document.location; | |
var links=document.getElementsByTagName('link'); | |
var found=0; | |
for(var i = 0, l; l = links[i]; i++) { | |
if (l.getAttribute('rev') == 'canonical' || (/alternate short/).exec(l.getAttribute('rel'))) { | |
found=l.getAttribute('href'); | |
break; | |
} |
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
""" | |
Convert numbers from base 10 integers to base X strings and back again. | |
Sample usage: | |
>>> base20 = BaseConverter('0123456789abcdefghij') | |
>>> base20.from_decimal(1234) | |
'31e' | |
>>> base20.from_decimal('31e') | |
1234 |
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
(* | |
Open a new tab in Safari (and move focus to the URL bar) | |
I have this configured as a Quicksilver trigger for ctrl+alt+T | |
*) | |
tell application "Safari" to activate | |
tell application "System Events" | |
tell process "Safari" | |
click menu item "New Tab" of menu "File" of menu bar 1 | |
end tell |
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
# Code for using http://developer.yahoo.com/geo/placemaker/ | |
import urllib, httplib2 | |
h = httplib2.Http() | |
URL = 'http://wherein.yahooapis.com/v1/document' | |
API_KEY = 'your-Yahoo-API-key' | |
def placemaker(text, doctype='text/plain'): | |
head, response = h.request(URL, 'POST', headers={ |
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
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, |