Comparing package versions in PostgreSQL

This weekend I’ve played a bit with PostgreSQL extensions written in C.

A while ago I wrote a Python C extension for Smart to compare Debian package versions. Now I was trying to do something similar inside PostgreSQL, and thus ported the original Python C extension code to a PostgreSQL C extension. It enables queries like the following:

# SELECT 'Matched' WHERE deb_version_match('1.2', '<=', '2.0');
  ?column?
----------
 Matched

The implementation of the PostgreSQL C extension was quite straightforward, but I'm a bit disappointed by the performance of PL/PGSQL.

I've made tests using two environments. One of them is a PL/Python function executed as a trigger, which calls the original Python C extension and executes SQL back in PostgreSQL using the plpy module. The other is a PL/PGSQL function which uses the implemented PostgreSQL C extension directly.

Considering that the function logic consisted of one loop over a SELECT statement, a few tests, and an INSERT statement, I was expecting that the overhead introduced by going back and forth between the PostgreSQL state and the Python interpreter state would be a lot more noticeable when compared with PL/PGSQL executing an internal PostgreSQL function. Tests have shown about 10% of improvement roughly, when doing a similar logic over about 5000 items.

I'm not yet sure if the speed improvement pays off the limited debugging feedback provided by the PL/PGSQL interpreter on errors.

Posted in C/C++, PostgreSQL, Project, Python | 1 Comment

Moved to a new place!

After a somewhat long effort, all posts were moved to the shiny new blog on labix.org, including comments!

The new blog is based on WordPress, and brings a few new features that I was missing in LiveJournal. I of course missed control over the environment, but most importantly, I was missing tag-specific RSS feeds, so that people can keep track of topic they have interest in, rather than every topic that interests me. For instance, to keep track of Python-specific posts, one may link to:

http://blog.labix.org/tag/python/feed

The new toy makes me feel motivated to post news about interesting things I’ve been working with lately (some cool stuff is coming, but some of it will unfortunately take a bit longer to become public), and perhaps even some past work I forgot to keep track of.

I’ve also installed a WordPress plugin to crosspost entries to LiveJournal, so that new entries are still seen there. Please, update your links or remind someone to do so if possible, as this will eventually be disabled.

Posted in Other | Leave a comment

Support for GPS TrackMaker file format on GPSBabel

Continuing my put-those-bits-out-of-your-hard-drive campaign, I’ve released a patched version of GPSBabel with support for input and output of waypoints, tracks and routes in the binary file format of GPS TrackMaker.

The patch was written six months ago (sorry :-) ). I just had to port it over to a recent version of GPSBabel.

The original reason for the patch is that there is quite a good amount of information under that format for Brazil, and GPSBabel is able to deliver information directly to some brands of GPS devices. Hopefully this will get applied upstream soon.

Posted in GPS, Patch, Project | Leave a comment

Mandelbrot Set

I’ve finally posted the Mandelbrot Set code snippet that was sitting on my disk for a while.

It computes and draws the Mandelbrot Set fractal using pygame, and also Python for Series 60.

Three different screenshots are provided. They show the snippet running under pygame, under pymaemo in a Nokia 770, and under Python for Series 60 in a Nokia N70 phone.

I was quite amazed to see the Nokia 770 running the pygame version without any changes in the code. Kudos to Osvaldo, Rodrigo and Ruda at INdT for the pymaemo port, and to Nokia for the great device.

Posted in Fractal, Python, Snippet | Leave a comment

Hey, nice float!

python-nicefloat is a Python module implementing an algorithm based on the paper “Printing Floating-Point Numbers Quickly and Accurately”, by Robert G. Burger and R. Kent Dybvig.

The implemented algorithm will find the shortest, correctly rounded output string representing a decimal number that converts to the same internal binary floating-point number when read.

Update: the download link is now fixed.

Have fun!

Posted in Math, Project, Python | 4 Comments

Labyrinth Solver

What about a labyrinth solver function in 16 lines of Python? :-)

Posted in Python, Snippet | 4 Comments

Several projects moved

In the last few weeks I’ve been gradually moving projects I maintain to Labix, which is using the Moin software as a CMS.

Projects like

and others are all being hosted there now. There’s also a brand new issue tracker using Roundup.

Posted in Project, Python | Leave a comment

Time to shake

I’d like to communicate that I’m shaking my life a bit, and even though I have a lot to say, I’ll try to be relatively short.

Continue reading

Posted in Other | 10 Comments

Python module for Constraint Solving Problems

The constraint module presented in PyCon Brasil and later on EuroPython 2005 is now available. Here is a trivial example, solving the classical rooks problem:

problem = Problem()
numpieces = 8
cols = range(numpieces)
rows = range(numpieces)
problem.addVariables(cols, rows)
for col1 in cols:
    for col2 in cols:
        if col1 < col2:
            problem.addConstraint(lambda row1, row2: row1 != row2,
                                  (col1, col2))
solutions = problem.getSolutions()

Have fun!

Update: It was also presented in FISL 2006.

Posted in Conference, Project, Puzzle, Python | 5 Comments

Credit where credit is due

From Progeny Componentized Linux page:

Our future development efforts will center around bridging
the gap between Debian APT and the APT variants that have
emerged in the RPM world, as well as adding support for
emerging efforts to standardize software repository formats.

There is only one APT “variant” which works with RPM. It’s named APT-RPM, and was developed at Conectiva. Of course Progeny knows that, since they certainly remember where their code came from.

It’s really sad to see a company like that, with Ian Murdock behind it, not giving credit to a project which was forked from a Debian software, and that gave back to the original project so much. Perhaps the only way to fight against that kind of behavior is working even harder to produce good software.

Hey, Progeny, want some new ideas to reinvent. ;-)

Posted in Other | 7 Comments