Compiling Couchdb on Karmic
This had my annoyed for a while. When I came to run ./configure I got:
checking for JS_NewContext in -lmozjs... no checking for JS_NewContext in -ljs... no checking for JS_NewContext in -ljs3250... no checking for JS_NewContext in -ljs32... no configure: error: Could not find the js library. Is the Mozilla SpiderMonkey library installed?
I was unable to find much help until I looked at the instructions for installing from source http://wiki.apache.org/couchdb/Installing_on_Ubuntu?action=show&redirect=InstallingOnUbuntu. Which in retrospect would have been a good place to start. Use the following to stop the above error:
./configure --with-js-include=/usr/include/xulrunner-1.9.1.9/unstable --with-js-lib=/usr/lib/xulrunner-devel-1.9.1.9/lib
Oh and make sure you have xulrunner and its dev package installed.
Python and Notify OSD
Silly little bit of code that will tell you when a command line operation has finished.
#!/usr/bin/env python
import sys
import pynotify
if __name__ == '__main__':
if not pynotify.init ("icon-summary-body"):
sys.exit (1)
print sys.stdin.read()
n = pynotify.Notification ("Finished")
n.show()
This was based on https://wiki.ubuntu.com/NotificationDevelopmentGuidelines?action=AttachFile&do=view&target=icon-summary-body.py over on the article Notify OSD.
SimpleGeo
While pottering about I found SimpleGeo.
I’m still struggling a little for a use case for this. It’s cool and that’s enough for me, yes I am that fickle.
Its a simple enough idea and well implemented. You sign up for free. The free account gives you a single “layer”. A layer is a collection of data points that you wish to map. Paid for accounts allow more layers but as I’m only playing I’m not about to find out. Python is well supported but not very well documented.
http://help.simplegeo.com/faqs/api-documentation/clients-and-example-code contains what you need to get the libs downloaded and running. From here on I’m going to assume you have got it installed and running.
Creating a record:
from simplegeo import Record
r = Record('layername', '1', '53.762282', '-0.355662')
r
client.add_record(r)
b = client.add_record(r)
print client.get_record('layername', '1')
{'created': 1270653503, 'geometry':
{'type': 'Point', 'coordinates': [-0.35566199999999998, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'object'},
'layerLink': {'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': '1', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/1.json'}}
The code above creates and saves a record on Simple Geo’s servers and fetches the same record. Its all pretty simple stuff. Where it gets cool is using get_nearby. This allows you to send a location and get back all data points near that location.
print client.get_nearby(layer='layername',arg='53.762281,-0.3456')
{'type': 'FeatureCollection', 'features': [
{'distance': 355.3372151292516, 'created': 1270659182, 'geometry':
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'place'}, 'layerLink':
{'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': '1', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/1.json'}},
{'distance': 960.75183289629251, 'created': 1271073482, 'geometry':
{'type': 'Point', 'coordinates': [-0.33100000000000002, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'place'},
'layerLink': {'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': 'TheAdelphi', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/TheAdelphi.json'}}]}
Pushing the coolness a bit further is get_density. This takes a location and using Sky Hooks’ Spot Rank will predict the density of people in the supplied location.
print client.get_density('51.5019', '-0.1189', 'tue')
Also worth a mention is the method get_history. This will return the last 20 locations of the record with the supplied id.
print client.get_history('layername', '1')
{'type': 'GeometryCollection', 'geometries': [
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999],
'created': 1270659182},
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999],
'created': 1270659072},
{'type': 'Point', 'coordinates': [-0.35566199999999998, 53.762281999999999],
'created': 1270653503}]}
While this is all very cool the only gotcha I have found is that longitude and latitude can be the wrong way round. So if you are getting no hits check the long and lat from get_record are the right way round. This is mentioned in the documentation on the Simple Geo’s site.
Another super cool feature is the dashboard offered when you login to Simple Geo’s site. There is a Google maps instance which you can use to find you data on. Handy for debugging.
Due to the almost total lack of documentation I worked out most of the above using source http://github.com/simplegeo/python-simplegeo/blob/master/simplegeo/__init__.py. Its simple enough to read.
Once I find a use for this I will write up some stuff. In the mean time if you get stuck give me a shout, chances you will be stuck at the same point I was…
WebDriver and Select Boxes
This one had me puzzled for a while as I never took the time to sit down and read the documentation fully… I decided to look at this again after seeing the issue appear on the WebDriver mailing list. How to you use select and option html elements? Below is Python demo.
$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from webdriver_firefox.webdriver import FirefoxLauncher
>>> from webdriver_firefox.webdriver import WebDriver
>>> d = WebDriver()
>>> d.get("http://cassandra.appspot.com/")
>>> e = d.find_elements_by_xpath(
"/html/body/div[@id='container']/div[@id='search']/form[@id='searchForm']/div/select")
>>> r = e[0]
>>> t = r.find_elements_by_tag_name("option")
>>> t
[<webdriver_firefox.webelement.WebElement object at 0x8dd778c>,
<webdriver_firefox.webelement.WebElement object at 0x8dd772c>,
<webdriver_firefox.webelement.WebElement object at 0x8dd77ac>,
<webdriver_firefox.webelement.WebElement object at 0x8dd77ec>]
>>> for i in t:
... print i.get_text()
...
Artist
Location
last.fm Username
Venue
>>> t[2].set_selected()
>>>
Now in your WebDriver browser session the option box has changed to “last.fm Username”. Excuse the variable names but I wanted to make a note before I lost the code.
Speeding up the Web
Might be old news and to be honest it should be if you do web development Speed. This page from Google contains lots of tips for speeding up web pages, lots of useful tips and worth at least one read.
Little Script to Check Twitter’s Status
#!/usr/bin/env python
from lxml import html
print "Starting..."
page = html.parse("http://www.pingdom.com/reports/vb1395a6sww3/check_overview/?name=twitter.com%2Fhome")
if page:
try:
t = page.xpath("/html/body/div[@id='content']/table[1]/tr[2]/td")
status_icon = t[0].xpath("img/@src")[0]
status = status_icon.split('_')[2].split('.')[0]
date = t[1].text
print "Twitter is %s! Checked at: %s Pacific Time (GMT - 8:00)" % (status, date)
except:
print "Unable to correctly verify Twitters status"
else:
print "Can't access http://www.pingdom.com status page!"
Conduit from SVN
Installed in it from svn and kept getting: ImportError: No module named conduit
Fixed it with a: sudo cp -r /usr/lib/python2.6/site-packages/conduit /usr/lib/python2.6/ after failing with ./autogen.sh –prefix /usr
Get CouchDB up and running
run:
sudo apt-get install libcurl4-gnutls-dev libmozjs-dev libicu-dev erlang
This should be all you require to build and install apache-couchdb-0.9.0
Playing a DVD
A friend was getting the following error when playing some dvds:
[ 172.864397] Buffer I/O error on device sr0, logical block 278
Following https://help.ubuntu.com/community/RestrictedFormats/PlayingDVDs solved it.
Google Contact API
This is more for me as a reminder.
To find the postal address from a gdata.contacts.ContactEntry use:
import atom import gdata.contacts import gdata.contacts.service gd_client = gdata.contacts.service.ContactsService() gd_client.email = 'jo@gmail.com' gd_client.password = 'passdword' gd_client.source = 'exampleCo-exampleApp-1' gd_client.ProgrammaticLogin() from lxml import etree feed = gd_client.GetContactsFeed() entry = feed.entry[0] entry entry.postal_address[0].text '123 Fake Street'
Took me ages to figure that out…

