My Paste Pony

my-paste-unicorn

OK, so it’s actually a unicorn, but pony sounds better in the post title. Made in Gimp by tracing over the Paste ASCII Unicorn. Silly but fun. To see the ASCII original:

$ easy_install Paste
>>> import paste.pony
>>> print paste.pony.UNICORN.decode('base64').decode('zlib')

Eclipse for Python Web Development on Ubuntu

Updated 14 July 2009 for Eclipse 3.5. Now using Aptana to install PyDev.

Overview

So, I think I’ve finally decided that I prefer Eclipse for Python Web development over NetBeans. (I prefer Wing IDE over both for straight Python development, but that’s another post.) Eclipse’s Python support, via PyDev, seems more advanced and NetBeans has some annoying issues. Eclipse also seems a bit snappier, at least on my machine (YMMV, blah blah).

Eclipse takes a bit more effort to set up, but once you’ve done it a couple times, it’s pretty straightforward. The hard part is keeping track of the links to the Eclipse update sites and remembering a few odd bits of configuration. This document gives details on installing Eclipse for Python Web development with Aptana, PyDev, and Subclipse.

The instructions here are Linux/Ubuntu-centric, but the instructions for getting to the Platform Binary–the smallest possible Eclipse download, as far as I can tell–are applicable to all platforms.

Download Eclipse

If you go to the Eclipse downloads page (http://www.eclipse.org/downloads/), you’ll see packages for Java and C++ along with some other options. If you’re doing ONLY Python development, you might wonder which version to download. These versions install cruft I don’t want or need. I finally found what I think is the smallest possible Eclipse package, the so-called Platform Runtime Library.

Install Eclipse

Extract the downloaded package: tar xvzf eclipse-platform-3.5-linux-gtk.tar.gz. I rename the resulting eclipse directory to eclipse-3.5, move it to ~/.local,  and create a symlink in ~/.local/bin to the eclipse executable: ln -s ~/.local/eclipse-3.5/eclipse ~/.local/bin/eclipse

Configure Eclipse

Edit ~/.local/eclipse-3.5/eclipse.ini. Find the line containing “-vmargs”. Add a new line directly below that: -Djava.library.path=/usr/lib/jni. Save and close. Fire up Eclipse.

Install Aptana

  • Help > Install New Software… > Add
    • Name: Aptana
    • Location: http://update.aptana.com/install/studio
  • Click OK, click the Aptana Studio checkbox, click Next, click Finish, wait…, click Yes to restart Eclipse
  • When Eclipse restarts, a Customize Aptana Studio window should open automatically…

Install PyDev

  • Under Web Application Platforms, check PyDev
  • Check any other plugins you want to install (I install Subclipse in a separate step below)
  • Click the Install button
  • An Available Software window opens where more check boxes need to be clicked, analogous to the ones you just clicked (note: annoying)
  • Check the boxes, click Next, click Next again, accept license(s), click Finish, wait…
  • Click Yes to restart Eclipse

Install Subclipse

  • Prerequisite: sudo apt-get install libsvn-java
  • Help > Install New Software… > Add
    • Name: Subclipse
    • Location: http://subclipse.tigris.org/update_1.4.x/ (Subclipse 1.4 supports Subversion 1.5, which is what’s installed on Ubuntu)
  • Click OK, check only first item in list (which contains 4 sub-items), click Next, click Finish, wait…, click Yes to restart Eclipse
  • Preferences > General > Editors > Text Editors > Quick Diff:
    • Check ‘Enable quick diff’ and ‘Show differences in overview ruler’
    • Use this reference source: Pristine SVN Copy

Supervisor now supports Python 2.6

I’ve been using Supervisor for a few months now to manage some app servers at work. Good stuff; solid. My only gripe with it was that it didn’t run properly under Python 2.6[1,2]. I had to install Python 2.5 just to run Supervisor, which isn’t a super big deal but is kind of annoying. The latest release, 3.0a7, fixes this by including a “patched version of Medusa to allow Supervisor to run on Python 2.6.”

Note: I had to `wget http://dist.supervisord.org/supervisor-3.0a7.tar.gz` and easy_install that due to a network timeout[3]. I assume that’s because Supervisor is super popular and everyone’s upgrading.

[1] It did run under 2.6 but issued an error when starting up.
[2] This was due to changes in the Python 2.6 stdlib, not a problem with Supervisor itself.
[3] Suggestion: If possible, remove link from PyPI to http://supervisord.org/ so easy_install doesn’t get stuck there.

oTidyBrowser is not defined

If you’re tired of seeing this annoying error in Firebug, here’s the fix on Ubuntu (I stole this from here and condensed it to its Ubuntu specific essentials, though, of course, the procedure would be similar on other OSes):

  • Locate tidy.jar in your Firefox profile
    • Open $HOME/.mozilla in File Browser (starting at $HOME doesn’t work for some reason)
    • Click Search and type tidy.jar in the search bar
  • Right click and Open with “Archive Manager”
  • Go into content directory, right click tidyBrowser.js, and Open With… your favorite editor
  • Change line 220 from if( oTidyBrowser.bTopLoadBusy==false ) to if(oTidyBrowser && oTidyBrowser.bTopLoadBusy==false )
    • (Note: formatting left as I found it)
  • Save and close tidyBrowser.js
  • Click Update in Archive Manager dialog that pops up after save
  • Restart Firefox
  • Rejoice at having removed one small annoyance from your life

“phrase from nearest book” meme

Via

  • Grab the nearest book.
  • Open it to page 56.
  • Find the fifth sentence.
  • Post the text of the sentence in your journal along with these instructions.
  • Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.

Here’s mine, from Pragmatic Version Control Using Subversion 2nd Edition by Mike Mason:

“After creating our sandbox repository, we used a repository URL to tell Subversion  what we wanted to check out.”

Cool meme. Mine’s a little boring. Great book, though.

Photo Meme

Note: I would have posted this way back on the 19th, but iPhone 3G won’t mount on Ubuntu any more. Then there were permissions problems with my WordPress installation on WebFaction.

“”"Instructions: Take a picture of yourself right now. Don’t change your clothes, don’t fix your hair – just take a picture. Post that picture with NO editing. Post these instructions with the picture.”"”

Via

Implementation of Dijkstra’s Single-Source Shortest-Paths in JavaScript

I’m working on a project where the client wants a cool sliding navigation effect. We’re implementing this with JavaScript/AJAX/DHTML.

One of the constraints is that pages can only be reached via certain other pages. For example, if you’re on the /portland/contact page and want to go to the /seattle/contact page, you’ll first slide up to /portland, then over to /seattle, then finally down to /seattle/contact.

After a while, it occurred to me that there were some similarities with another project I’ve been working on off and on for the last few years, byCycle.org, which is a bicycle trip planner ala Google Maps.

I had written a Python version of Dijkstra’s Single-Source Shortest-Paths (SSSP) for byCycle.org. That’s available on PyPi as Dijkstar (so named because it also does has the potential to do A*). I figured it wouldn’t be too hard to port the Python version to JavaScript, and it wasn’t.

There were a few snags, though. Most of it was just syntactic and semantic differences between the two languages. The biggest issue was that I use “heapq“ in the Python version to maintain the costs to previously visited nodes in sorted order. JavaScript has no priority queue implementation that I could find, so I came up with a different solution that involves updating an Object (AKA “dict“) with costs to newly visited nodes and sorting the keys to pick the next node to visit. I’m assuming/hoping the underlying sort implementation is highly optimized.

Interestingly, I think I found at least one bug in the Python version, although I’ve been using that version for a couple years now with no known problems, so it must only be applicable in certain edge (no pun intended) cases (or maybe it’s due to some difference in the languages–need to take a closer look). I think the JS version came out cleaner, too.

If anyone’s interested, I’m releasing this under an MIT license. For now, you can get it from here. Note that it depends on the util module that you can get from here. The util module contains some other Python-inspired JavaScript, in particular a couple of functions for generating namespaces and classes. I might write another post about that at some point.

YUI TreeView with Ruby on Rails

Here’s some code I’m using to generate a dynamic tree view using an acts_as_tree model with slug and title fields, the TreeView widget from YUI, and a Rails helper. I chopped out some of the code for clarity, so all this does is create a menu with the titles from the model, but the basic idea is there to expand on.

Rails view/JavaScript

<script type="text/javascript">
  var page_tree;
  page_tree_init = function () {
    page_tree = new YAHOO.widget.TreeView('page_tree');
    var root = page_tree.getRoot();
    <% generate_page_nodes(@root) {} %>
    page_tree.draw();
  };
  page_tree_init();
</script>

Ruby

def generate_page_nodes(node, &block)
  parent = node.parent
  node_name = node.slug.gsub('-', '_')
  parent_node_name = parent.nil? ? 'root' : parent.slug.gsub('-', '_')
  js = <<-JS
    var #{node_name} = new YAHOO.widget.MenuNode('<span class="node_title">#{node.title}</span>',
                                                 #{parent_node_name});
  JS
  concat(js, block.binding)
  children = node.children
  children.each { |c| generate_page_nodes(c, &block) } unless children.empty?
end

Looking for a New Place to Live

I’m looking for a new place to live in Portland. I’ve been keeping an eye on craigslist, but thought I should try some other methods, so I’m posting this to see if anyone out there knows of anything. If anyone has other suggestions for finding an apartment in Portland, please let me know.

I’m looking for a place by myself that…

  • I can move into around June 1st,
  • I can stay for at least six months and preferably up to a year or more,
  • has one or more bedrooms,
  • is under $1,000 a month, including all utilities,
  • is in Southeast Portland within a mile of People’s,
  • is north of Powell and west of 39th,
  • has a yard for gardening,
  • allows cats (I have one).

This is what would be ideal, but I’m somewhat flexible. If you know of something that might be a good fit, please get in touch.

Forest Park