Michal Čihař - Blog Archives for Coding

Accepting patches in free software

Sometimes when I found problem in free software which tortures me too much, I try to fix it and submit patch to upstream. What riles me is how many authors ignore submitted patches.

I came to this idea when recently somebody complained that patch I submitted for Python 2.3 (in times when it even was not final) does not apply to current Python 2.5. What a suprise! I had to create several patches for Python when I worked for SUSE and most of them didn't receive even single comment. Same applies to several other patches I made, however I don't probably remember most of them.

Only SourceForge allows me to review what has not yet been accepted. There were several attempts to improve detection of search engines and browsers in AWStats, but author seem to prefer to add own list instead of using patches from tracker. There is support for non-latin languages in Klear, but even posting to mailing list didn't rise interest in this patch. And of coure few Python patches I mentioned at the start.

I try to do my best to integrate patches for my projects (mostly phpMyAdmin and Gammu related software) as soon as they arive as it saves time and energy of both sides. And contributor is then willing to provide more patches if he can see they will be most likely accepted.

But it's your choice how you want to develop your software! Either stay alone or accept patches from community.

New Google service

Maybe it's not that new, but I noticed it today :-). You can search source codes using it and it is called / Code search /.

I just tried to find functions from projects I know and it worked surprisingly well, only CodeConv doesn't seem to be indexed.

My Nanoblogger are getting merged

Good news everyone: most of my nanoblogger changes were accepted upstream, so next nanoblogger version will come with friendly links, RSS indexes and other tiny things I mentioned before.

PS: This post also serves for testing whether everything works as expected :-).

Multi language site with PHP and gettext

As announced yesterday, I started to translate my website to Czech. I take it mostly as experiment how to do such thing easily. I don't want ot maintain different pages for each language, so the logical step seemed to use gettext which I know for translating regullar applications.

Using gettext from PHP is quite easy. You can just follow documentation and you will get basic idea. Only tricky part was to set encoding so that messages are displayed correctly.

The whole magic that selects translation based on host name is few lines of PHP code:

$lang = 'en';
if (substr($_SERVER['HTTP_HOST'], 0, 3) == 'cz.') {
    $lang = 'cz';

    setlocale(LC_MESSAGES, 'cs_CZ.UTF-8');
    setlocale(LC_ALL, 'cs_CZ.UTF-8');
    bindtextdomain('website', 'locale');
    bind_textdomain_codeset('website', 'utf-8');
    textdomain('website');
    $_SERVER['HTTP_HOST'] = substr($_SERVER['HTTP_HOST'], 3);
}

You can see that is't just locales and gettext initialisation and cutting host name so that rest of code doesn't have to deal both possibilities.

The hardest work is to make all PHP pages use gettext instead of plain text constants and translate them. I will probably never convert whole site, but it is not needed and only parts can be translated using this approach without any additional effort.

Browser incompatibilities

Today I looked at menu on top of Wammu pages in MSIE and it was displayed completely differently than in Firefox. So another CSS hacking session had to begin to fix the menu look.

Fortunately I found ies4linux which easilly installed MSIE on my Linux computer so that I can test the beast without searching for some Windows installation.

Anyway now it looks almost same in both browsers (there are some minor glitches in MSIE which I'm going to ignore).

Nanoblogger customisations for next time

As time goes, I again needed to touch NanoBlogger code. I again saw there is bug with calendar alignment, for which I made simple patch, hopefully it will get soon into CVS.

Another thing I wanted to improve is displaying of feeds in web browser. This can be simply done by adding CSS style.

If you want to list all category feeds on main page, you can find it in my patch for generating this listing.

Next code is to allow inclusion of blog listings in other pages on my site such as phpMyAdmin demo. This is achieved by generating special pages which only list entries.

And last thing is enabling and fixing of title based permalinks, which was first thing I hacked for NanoBlogger :-).

Update: I filed NanoBloggers patch tracker with all those patches, let's see how much of them will get included.

Thanks for motivating me

This is a bad day. I'm bad guy because I don't have web pages about Wammu in my native language, I hacked absolutely useless CSV import code in phpMyAdmin. What comes next?

I would make bilingual pages if I'd have time for that, but I will rather write new feature in Wammu than spend time on this.

And I know export is not perfect, everything can be improved and you are welcome to do that!

Pinging blog indexing services

When I noticed that something like indexing services for blogs exists, I hacked simple dog command to download ping page. This worked more or less, but it didn't gave me any feedback. Today I decided it's time to switch to something more sophisticated.

As most (if not all) services are using XML-RPC with same functions, implementing this in python using xmlrpclib was quite easy. After few minutes reading documentation I had working code which can be attached to publish command in nanoblogger:

import xmlrpclib
import sys

def do_ping(url):
    print "Pinging %s ... " % url,
    sys.stdout.flush()
    try:
        s = xmlrpclib.ServerProxy(url)
        r = s.weblogUpdates.ping("Nijel's Weblog", "http://blog.cihar.com/")
        if r['flerror']:
            print "FAILED"
            print " error: %s" % r['message']
        else:
            print "ok"
        sys.stdout.flush()
    except Exception,v:
        print "FAILED"
        print " error: %s" % str(v)

do_ping("http://ping.blo.gs/")

I'm only affraid that ping services don't like me much now as during testing I produced lots of pings :-).