Archive for the ‘Tech’ Category

A Python Challenge. Better than rentacoder?

Monday, August 25th, 2008

Python programmers love a challenge, so I thought I would throw this one to the lazyweb.

I have an app that generates a large sequence of files, the nature of which is unimportant. What is important is generating a location to store them. To keep the directory structure manageable there should be no more than 100 files plus sub-directories in any given directory. For instance if there are 99 files in a directory, then there is only room for one more file or a directory — bringing the total to 100. There is an additional requirement that the directory structures should be as flat as possible, i.e. foo/bar for the nth item is preferable over foo/bar/baz. To summarize the requirements:

  • No more than a total of 100 files plus folders in any given directory.
  • Directory structure should be as flat as possible.
  • Algorithm should be theoretically unbounded, i.e work for any length of sequence.
  • Character length of the path is unimportant.
  • Entries should be in Python (but feel free to post solutions in other languages for comparison).

Entries should be a function called make_path, which takes a single parameter, n, which is the number of the file in the sequence (starting at 0). The return value should be a path to the file, such as foo/bar/baz (where baz is a file in directory foo/bar). Feel free to add any extension to the filename, to make it clearer that the path references a file. You can’t rely on the function being called in sequence, so don’t keep any kind of persistent state across calls to make_path (nor any kind of file access).

Wordpress comments tend to mess up formatting with Python code, so please post your entries on Pygments.org or a similar site and a comment to let me know the url.

The winner gets the respect of his/her peers and will be owed a favor by me, because I figured it would be more fun to write this blog entry than solve it myself! ;-) All entries grant the rights for anyone to freely use and modify the code.

Charting my progress

Sunday, August 10th, 2008

I spent another afternoon working on my pie chart project. I’m using PyCairo to render labels over the chart render. The tricky part was finding the position at the center of each pie segment to render the label over. There’s no way of retrieving that information from Povray, so I had to do the math myself and calculate the coordinates manually. Fortunately I had a 3D math module that I was intimately familiar with, having written it just last year (its always gratifying to re-use code for a new purpose)!

I won’t bore you with the gory details. Suffice to say that I generated a pretty animation so I could confirm that the label position code was working correctly. I’m not going to be generating videos with the finished product, this was just a diversion. The segments and labels don’t mean anything, it’s all just made up! Enjoy…

Image wrapping script

Sunday, August 3rd, 2008

After posting my latest pie chart image, it occurred to me that it would be pretty cool if the text flowed around the edge of the pie chart image rather than around a rectangle. This is not something that can be done simply with HTML / CSS, but it can be done by breaking the images up in to horizontal slices so that they extend only to the edge of the image, rather than to the absolute border.

Screenshot

If I googled for it, I suspect I could find tools to do this for me — but where is the fun in that? Instead, I wrote a Python script that uses the Python Image Library to scan an image and output HTML that will allow text to wrap smoothing around the image. No additional images are produced, because the ’slicing’ is done with CSS to select the part of the original image that is seen.

Here is the script: wrapimg.zip, and some examples of how to use it:

python wrapimg.py -o left.html sliceofpie.png
python wrapimg.py -o right.html -d right sliceofpie.png

These two lines produced left.html and right.html.

The code is completely free, do what you will with it!

Update: I wanted to display an example in this blog-post, but Wordpress insists on re-writing my code and ruining the effect! :-( I should find a blogging system that is more techy-friendly!

More Pie?

Saturday, August 2nd, 2008

sliceofpie I’ve been doing a little more work on my 3D pie-chart renderer. I’ve added beveling and tweaked colors to a point where I can render charts that — in my opinion — are a better quality than those produced from Apple’s Numbers. Next step is to add labels over the main image. Povray does support rendering of True Type Fonts, but it is a 2D overlay that I’m looking for (not 3D text), so I plan to use PyCairo to render the labels. Once I’ve perfected the chart renderer I can build a polished web interface, and a web service for the render queue. All in Python, of course!

I know that 3D pie charts aren’t as clear as their 2D counterparts, but I still think there is a place (and hopefully a market) for pretty charts like this. Even if it isn’t a money-spinner, its still an interesting project, with some fun problems to solve!

Food File on Ubuntu

Saturday, July 12th, 2008

Since I’ve moved to Linux as my primary desktop (I know, about time), I’ve been motivated in porting some of my old software. This shouldn’t be too difficult, since I try to work in as platform agnostic manner as possible, and when I do use a platform specific API I keep it nice and modular. Food File is probably the most popular app I ever created, although only since I made it free. As a commercial app, it didn’t do to well, probably because it didn’t get noticed amongst all the diet / food applications for Windows out there, or possibly because I am lousy at marketing.

Food File on linux seems like a good fit, because it is a free wxPython interface to a publicly available data source (USDA Nutrient Database). I was hoping it would run without modification, but it failed on a line that used Windows-style back-slashes in paths rather than forward slashses — as prefered by linux. After changing 4 such lines, it ran. I was surprised that the fancy OpenGL graphics didn’t cause any problems, but it did segfault on the About box, the simplest dialog in the entire app (go figure). I haven’t got to the bottom of that yet, but when I do, I will release a Linux version. Here’s a screenshot of Food File running under Ubuntu:

Screenshot

I don’t have any experience building a Linux package. If the lazyweb would like to help me with that, it would be appreciated!

I think it was this project that started my pie chart fetish. I wonder if there is a support group or something…

Pretty as Pie

Sunday, June 29th, 2008

I’ve just spend a couple of hours dusting off an old project of mine, that involved generating pretty 3D pie charts by combining Mako templates with the Povray scene description language. I improved the image quality by enabling radiosity, and the end result is quite appealing (see below).

prettypie

Now I’m thinking that there may be some people out there who would be prepared to pay to generate such images for websites or for print, and it wouldn’t be too hard to extend the idea to other forms of chart, such as bar graphs. So, dear lazyweb, is there a big enough market in such a thing to warrant sinking my valuable spare time into?

New Postmarkup on the block

Tuesday, June 24th, 2008

I’ve released version 1.1.0 of Postmarkup. The main improvements are that it generates cleaner html, that doesn’t include invisible div sections, and that it should also generate XHTML that validates (previous versionsĀ  could put block tags inside inline tags for some bbcode).

The basic interface is the same, so it should be a drop in replacement for most people. TheĀ  base class for tags has changed (but not significantly), so if you have any custom tags, it will require a little work to get them functional again. See postmarkup.py for example tags.

I actually quite like bbcode as a light-weight markup. Possibly I’m rationalising, as I’ve spent a couple of days polishing it when I should be job-hunting! Its great for its original purpose, of letting forum users format text, but it could be used as a more friendly alternative to XML. It’s also higher level than (X)HTML in that a tag can generate intelligent content rather that simply applying a style.

Now I have to find some other project to keep me entertained before I re-join the rat race!

BBCode Ajax test server

Monday, June 23rd, 2008

Since I have some time on my hands, I’ve been doing a little work on Postmarkup - my BBCode module. I’ve made some significant improvements to the design which fixes a few issues and makes it easier to create new tags. To test it, I hacked together a simple web-app using CherryPy, which allows you to edit bbcode in the browser and see the resulting html update live — with a little Ajax magic.

Postmarkup test server

Please give it a try, and let me know if you can break it.

In building this, I’ve created a very rudimentary web service. I’m wondering if there is any practical use for such a thing…

My CV / Resume

Thursday, June 19th, 2008

It seems it is a good time to be a Python developer, after my last post I received a number of good leads. All before I had finished my CV.

Looking for a Python Role In London

Monday, June 16th, 2008

Its seems I’m on the job-market again.

I’m a software developer with over 10 years experience. I’m looking for a role working with Python, which has been the focus of my career for the last 18 months. Prior to that I worked with a mixture of C/C++ and Python. Ideally I’m looking for something in web development as I enjoy working with HTML / CSS and Javascript, but I’m open to other fields that may interest me. I have experience working with Turbogears and Django, as well as many other Python modules and technology.

I enjoy developing software outside of a work environment, and have created several games, applications, web sites, and open source Python modules. My blog is probably the best place to find out more about my spare time projects, see my Python articles for more information.

I’m also an author, having written a book about game development with Python. So I like to think I am a good communicator.

I’d like a full-time position, but I would consider contract work. I’m based in London, so anything in central London would be ideal. Please get in touch if you have a suitable role or would like to know more. I’m available for immediate start.

my email

Mobile: 07722 531972

No recruiters please. And by no recruiters, I mean no recruiters.

Update: I have updated my CV (willmcgugancv.pdf)


Close
E-mail It
Socialized through Gregarious 42