Posts tagged: PYTHON

New Year's programming resolutions

It’s that time of year. In no particular order, here’s a quick list of goals for Paul-as-developer in 2007.

  • Convert my remaining legacy PHP code (side projects and regular work both) to Django.
  • Write a useful PyObjC application.
  • Make some kind of contribution to Python itself, if possible.
  • Continue to add revision control and deployment automation to existing projects, as well as using it on new projects.
  • Continue to add unit tests to existing projects, as well as using them on new projects.
  • Learn a new language well enough to write a useful (small) application. Current candidates (all of which I’ve done at least enough reading on to have specific reasons for my interest, and some of which I’ve written toy programs in) are Haskell, Common Lisp, Io, Objective-C, and Ruby.

So, what about you? What are your coding goals for 2007?

99-byte Python quicksort

Update: Browsing through my Python Cookbook this evening I discovered entry 5.11, “Showing off quicksort in Three Lines”, which includes some code very much like mine below. The entry does a good job of emphasizing that these bits of code are perhaps to be savored but not to be actually used. It also includes an insanely (impressively?) convoluted version that uses three lambdas in a single line and weighs in at 105 bytes. I thought this might be the best possible in Python 2.4 and earlier, but in fact a simpler version can be constructed using the old short-circuit logic trick, and at 94 bytes it’s even smaller than my original. Here it is: q=lambda s:len(s)and q([x for x in s[1:]if x<s[0]])+[s[0]]+q([x for x in s[1:]if x>=s[0]])or s

Enticed by the lovely Haskell quicksort example, and sullied by the code-crunching ways of Codegolf, I decided to see how small a Python quicksort function I could write. I stopped at 99 bytes.

One Laptop Per Child -- with Python

The OLPC wiki says:

If you are able to program in Python then you can start building OLPC applications right now. The core tools, Python and GTK, are available on Windows, Macintosh and UNIX. It is not necessary to get Sugar up and running right away unless you want to do something complex using dbus. For most educational applications, you only need to have Sugar for the final testing phases.

That first sentence seems a bit ambitious, but it all does look pretty simple, and I like the list of guidelines:

dpaste.com

I’ve re-launched my little Django-powered pastebin (formerly paste.e-scribe.com) under its own shiny new $8 domain name: dpaste.com. Not that the world really needs another pastebin, but people have been using it daily and it’s a fun side project. From the about page:

Philosophy: Simplicity and usability. The grayscale look makes the colorized source code stand out. Cookie-based personal defaults eliminate lots of extra form widgetry. Automatic expiry means the database never fills up. Auto-focus on the Code field means mouse-free operation. No required fields means you can paste, tab, return, and go. No running list of recent items means the spammers remain invisible. And Django makes nice clean URLs the path of least resistance.

TextMate command for paste.e-scribe.com

After seeing a similar offering from the Web 2.0 pastebin Attachr I couldn’t resist. So here’s a simple TextMate command that submits selected text to paste.e-scribe.com, opening the new URL in your default web browser. Bonus features: the filename is used as the title, and the language syntax is guessed from the file extension.

This is a very crude little script, but too much fun not to share. Download paste.tmCommand.zip and double-click the resulting .tmCommand file, that should be all there is to it.

Pastebin update: Pygments

This past spring I posted about a simple pastebin app I wrote using Django. This week I updated it to use the excellent Pygments syntax-coloring library (formerly known as Pykleur).

Pygments has support for a healthy number of languages/syntaxes, offers a great deal of flexibility, ships with several different color schemes, and can produce output in HTML/CSS, LaTEX, or ANSI terminal colors. I created a “pcat” alias to take advantage of that last one when working in the shell.

Python MySQL junk pointer not making sense

(There’s got to be a name for blog posts that you make just so you’ll be able to remember something later – or so somebody who is banging their head against a problem you just solved can find your solution via Google magic. This is one of those posts.)

A while back I started getting bizarre errors when using Python with MySQL. They looked like this:

python in free(): warning: junk pointer, too high to make sense

It didn’t make sense to me either! Tech support for my VPS and copious Google searching didn’t turn up anything I could use.