Archive for the 'Programming Languages' Category

Geographic Queries on Google App Engine

Posted in Locality and Space, Python on May 28th, 2008 at 12:05:13

I made a post over on the MetaCarta Labs blog about doing geographic queries on App Engine:

???????? ????? ????????In this way, I was able to put together a geographic bounding box query, on top of Google App Engine, using a Geohash-like algorithm as a storage format, and use that query to power a FeatureServer Demo App Engine application, doing geographic queries of non-point features on top of App Engine/BigTable. Simply create a Geoindex object of the bounding box of your feature, and then use lower-left/upper-right points as bounds for your Geohash when querying.

Geographic Queries on Google App Engine

Probably of interest to some of the people who read this.

First Attempt at IronPython

Posted in IronPython, Locality and Space, Python, TileCache, default on June 20th, 2007 at 06:53:26

My first attempt to do something useful with IronPython:

>>> import urllib
>>> urllib.urlopen("http://crschmidt.net/")
Traceback (most recent call last):
  File httplib, line unknown, in getreply
  File httplib, line unknown, in getresponse
  File httplib, line unknown, in __init__
  File System, line unknown, in set_ReceiveBufferSize
  File System, line unknown, in SetSocketOption
WindowsError: Invalid arguments

Note that I’m working on OS X, and my exception is a WindowsError. Fancy.

(I was inspired by Bill Thorp’s efforts to get TileCache working on IronPython: Round 1, Round 2. However, I’m not all that inspired now.)

Still, it is kind of cool that IronPython just ran — I didn’t expect that to work. Maybe there’s something to this mono business after all.

TileCache Under Windows… It Just Works ™

Posted in Apache, Python, TileCache on February 7th, 2007 at 10:53:06

It’s cool when software works.

So, I needed to test the latest TileCache in Windows. I’ve got a relatively clean Windows laptop I keep around for this. None of the niceties that I would typically want on a machine I used full time — no Firefox, no cygwin, no vim, etc. Just a straight up Windows install, with things like Google Earth installed.

So, starting from that, I started by downloading Apache from the Apache Download Page. I downloaded “Win32 Binary (MSI Installer): apache_2.2.4-win32-x86-no_ssl.msi“, and ran the installer directly. This got http://localhost/ serving a page that says “It works!”.

Next, I downloaded the Python 2.5 Windows installer , and again selected all the defaults.

Next, I downloaded TileCache 1.4, as a .zip file, since I know how well Windows supports .tar.gz files. I extracted the zip file into C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin.

Lastly, I edited C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\tilecache-1.4\tilecache.cgi so that the first line of the file read “#!C:/Python25/python.exe -u”, and visited http://localhost/cgi-bin/tilecache-1.4/tilecache.cgi/1.0.0/basic/0/0/0.png …

And it worked! I got an image. I never expected setting up Apache, Python, and TileCache to just… well… work.

optparse module

Posted in Programming Languages, Python on January 14th, 2007 at 12:49:19

Wow, I’d never used the optparse module before. That’s pretty damn cool. (And to think I came close to writing my own option parser for a bit before I looked up the documentation.) The automatic addition of –help output is super-cool too. I definitely need to start using this in more of my code.

Hooray for Python!

Regular Expression HOWTO

Posted in Python on June 19th, 2006 at 02:01:14

Whenever I’m about to do something with the Python Regular Expression module, I immediately google “amk python re”, which leads me to A.M. Kuchling’s RE HOWTO. I can’t think of anything that I would find useful with regular expressions that is not covered in this document, and I highly encourage you to use it as a reference when you think you might find it handy.

Learning Letters

Posted in Ning, Python on February 8th, 2006 at 11:48:39

Julie’s at home these days - since we found out she’s deaf in one ear, we pulled her out of school to do more one-on-one learning at home.

She’s good at associating words with the visual representation of the letter - she’ll see “S”, and say “That’s what Sienna’s name starts with!” - but bad at names of letters. So, I hacked up a quick wxPython script from the wxPython samples that will just show an uppercase and lowercase letter, which she can click through. It’s basically a quick-and-dirty flashcard program: source available, of course.

Because I wanted to track her progress, I hacked up a little Ning App to track her learning. As of today, she only recognizes J (for Julie) and X on the first try. So, we’ll track it and see how she does. LearningLetters. 20 minute app, probably less. It’s crude, but it works.

It’s easy to make this work for just about anything you want to track. Just modify the ‘choices’ array.

Ning Components: XNC_Comment

Posted in Ning, PHP on February 3rd, 2006 at 08:03:59

A long time ago, when I first started working in the Ning playground, the first thing that impressed me about it was the fact that it had ready built components for so much *stuff*. Comments. Ratings. Flickr. Amazon. Calendars. Questionairres (Which is a very difficult word to spell right.)

Last night, after setting up X\_Query, I thought “hm, what if people want to comment?” And as I did, I remembered those components. I went into the developer documentation and looked up XNC\_Comment, which had a great, simple example of how to add comments to any content object.

But I didn’t have any content objects. The app is built as an API, so there was no need for Content Objects (at least not until I build up the documentation).

So I built a couple quick lines to add Content where I need it:

<?php
$d = XN\_Query::create(’content’)->filter(”owner”)->filter(”type”, “=”, “Page”)->filter(’title’, ‘=’, $\_SERVER['SCRIPT\_FILENAME'])->uniqueResult();
if (!$d) {
$d = XN\_Content::Create(”Page”, $\_SERVER['SCRIPT\_FILENAME']);
$d->save();
}
?>

Once this is done, the $d is an object for the current page. Once you’ve done that, you can just slightly modify the example from XNC_Comment:

require\_once ‘XNC/Comment.php’;
$newComment = new XNC\_Comment($d);
// Handle any form submission of adding a new comment
if ($newComment->willProcessForm()) {
    
$newComment->processForm();
} elseif (
$newComment->lastError() != XNC\_Comment::ERROR\_FORM\_ABSENT) {
    print
$newComment->lastError();
}
// Display the add a comment form (unless it was just submitted and saved)
if ($newComment->canProcessForm()) {
    echo
$newComment->buildForm();
}
// Display a list of comments belonging to a parent object
if ($d->my->content($newComment->referenceAttribute,true)) {
    foreach (
$d->my->content($newComment->referenceAttribute,true) as $comment) {
        echo new
XNC\_Comment($comment);
    }
}

Now, you’ve got comments on any page you want! Just include these two chunks of code at the bottom of each page. This is one of the easiest things I’ve done. Now anyone can take these code snippets and use them in any Ning app. Hm… maybe the next step is to build a code snippets repository…

XQuery: Remote XN_Querys

Posted in Ning, Python on February 2nd, 2006 at 23:41:12

I said a while ago that the coolest part of Ning was the content store. I’m now working on a proof of concept to prove it.

So, there’s a bunch of Roshambo (Rock Scissors Paper) apps. Or at least a couple. Or at least two: Roshambo and Fifteen, my personal 15-option version.

So, I know that I’ve played a handful of games, and don’t want to scroll back through them. The app itself doesn’t offer an API itself, so there’s no easy way to get the data out, and I hate screenscraping.

So, I built a query app. XQuery. The homepage kind of documents what it can do so far, but it’s nowhere near done. It was just a one hour hack. Then I built the Roshambo Results Viewer. I also then extracted the logic into a simple Roshambo Python Script — usage ‘python roshambo.py crschmidt’.

Expect more to come of this.

GPS Display

Posted in Bluetooth, GPS Devices, Mobile Platform, Python, Symbian Python on January 14th, 2006 at 14:32:32

Today, there are a large number of cheap bluetooth GPS devices on the market. These devices allow you to connect to the device wirelessly, which is great for when you’re driving and don’t want cables draped all over the car.

However, what happens when you can’t drag your computer out to act as a display of your position? No bluetooth GPS on the market today for under $500 has a display of any kind. When you consider that these things can be had for $70, that makes purchasing one go from likely, to ridiculous. What’s the point of a handheld, easy to use GPS if you can’t use it to see where you are?

GPSDisplay ScreenshotIf you’ve been asking this question, I’ve got software which has an answer for you. GPSDisplay will allow you to connect to NMEA compatible Bluetooth GPS devices and display your position fix. It is written entirely in Python, using NMEA code from Forum Nokia. It requires only that you first install Python for Series 60 on your device, and should work on all first and second generation Series 60 phones. Simply download the .sis file, send it to your phone, and you’ll be all set to go — you can use your phone as a display for that new cheap Bluetooth GPS you bought, and stop dragging your laptop out into the woods to go Geocaching.

Open Guide to Boston Updates

Posted in OpenGuides, Perl on January 6th, 2006 at 01:40:15

Over the past couple months, I’ve been importing a large chunk of data, largely from Zami, into the Open Guide to Boston. Tonight, the guide crossed the 1000 place mark, and I decided that showing everything on one map was no longer making much sense.

The result? Boston Mashup - pick the categories you want, and they’ll be dropped onto a map, with a different color for each type of marker (up to 7 - I don’t have that many colored markers yet).

I’ve still got more I want to do with it, but it works, and works pretty well: much better than I expected it to. Thanks to perigrin for helping me work around my Perl ineptitude and solve the problems I needed to.

Not really much to say about it other than that: try it out, let me know what you think. I’m happy with it, at least as a starting point, so I think that’s probably a good sign.