Archive for the 'planet python' Category

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.

Updated 5 March 2010 for Eclipse 3.5.2 and Subversion 1.6.

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, 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.

  • Start here: eclipse project downloads.
  • Find the Latest Release under Build Type in the Latest Downloads section and click the 3.5.2 link under Build Name.
  • Click Platform Runtime Binary in the left hand menu.
  • Choose for your OS by clicking one of the (http) links in the Download column; I chose Linux (x86/GTK 2), which I’m guessing is the most common for Linux.
  • You still need to pick a mirror! I use the OSU Open Source Lab link because it’s close to me and fast.
  • And finally, the download begins…

Install Eclipse

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

Configure Eclipse

Edit ~/.local/eclipse-3.5.2/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.6.x (Subclipse 1.6 supports Subversion 1.6, which is what’s installed on Ubuntu 9.10)
  • Click OK, expand the Subclipse entry, select all the required 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.

Decluttering the Desk

Today I read a post about decluttering your desk. Right now, I can’t find that post, but this page links to a bunch of similar and related articles. Those links are on the Zen Habits site, which I’ve started reading lately. Lots of interesting food for thought there.

So, I’m pretty tidy already, and my desk wasn’t that much of mess to begin with, but there were still quite a few unnecessary items accumulated there, like a printer I’m never going to use, a stapler I use maybe once a month, etc. I only spent about ten minutes decluttering, but the benefits were huge. So huge that I had to write it again in bold AND italics.

Along with office type stuff, I cleared off some knick knacks–little bits of art and what have you.

Did I mention the huge effect all this had? Wow. There’s a sense of openness and space. There’s more room to work and breathe. There’s also less distracting visual clutter.

This is only an anecdote, but I was more productive today than I’ve been in a while.

I recommend giving this a try. What do you really need on your desk and in your immediate working environment? What I’ve found, at least for myself, is that it’s actually not much. I’m guessing everyone’s got at least a couple items that can be tossed or sold or given away. Things that only get used once in a while can be put out of sight in an easy to reach place. Things that are visually interesting (photos, say) eventually become visually distracting, especially when there’s too much of it.

Of course, there’s no precise recipe, and everyone’s got their personal preferences. For me, just thinking about this, or anything, consciously is what’s important. The “right” changes naturally precipitate from awareness.

Ruby on Rails… Revisited

Updated with links and a couple typo corrections.

I’ve been working on a fairly big Web site project lately. My partner and I initially decided to use Django to build the site, mainly because I’m a Python “expert” and Django is (apparently) the #1 Python Web framework. We were also lured by the easy admin interface.

After trying to use Django and not really enjoying it, I tried switching to Pylons because I’ve had a good amount of experience with it in the building of byCycle.org. It’s gone through two fairly major releases since then, and so have a bunch of the libraries that tend to get used with it, like SQLAlchemy, Elixir, etc.

I was having a hard time with the Pylons docs, and so I ended screwing around with Grok (which actually looks fairly interesting) and even took a look at the Zope 3 site. I’m sure Zope is really awesome or whatever, but it might as well suck. Every time I look at that site, I’m just like “WTF! This shit has been around for like five years!” Anyway, I might just not be smart enough for Zope.

This led us back toward Rails (even if it is a ghetto). I used Rails a bit last year but never did anything too serious with it. Diving into it today was quite a pleasure. There are issues to be sure, but overall I’m enjoying it by far over any of the other options we had tried. I’m also enjoying learning/relearning Ruby.

If Pylons had good docs, we’d probably be using that.

So, I don’t know if this is a particularly useful post, since I didn’t get into much in the way of reasons (what, i have back this up?!). This subject’s been hashed and rehashed, but I just wanted (needed) to make a qualitative statement about my/our experience, which, of course, is purely personal.

Taxes

I heard just yesterday about the so-called “economic stimulus payment.” I figure if I hadn’t heard about it, maybe there are others out there that also haven’t.

The simple version is that anyone who made over $3,000 in 2007, has a valid SSN, and files a federal tax return this year will receive between $300 and $1200 (individual -> married) from Uncle Scam. Sounds like free money to me, as it only takes a few minutes to fill out a 1040EZ.

Of course, it’s actually more complicated than that. See this and this for more info.