Older blog entries for gdvieira (starting at number 25)

Emacs And Cedilla

This one is for the "unlikely bugs" section. If you use the magic combination of Emacs 22, a US keyboard and dead keys in a UTF-8 locale, the combination ' + c will give you ć instead of ç. Of course, this is a bug only if you want ç and not ć, so please forgive my ç-centrism. No offense intended to ć-using languages, whatever they may be. :)

GTK2 had this same bug about 5 years ago, and they solved it by creating the "cedilla" input method, and selecting it according to locale. Guess the Emacs guys will have to go the same route. Meanwhile, a simple workaround is to fire up Emacs in a ISO-8859-1 locale: "$ LC_ALL=pt_BR emacs" and as soon as the program opens up, select "Options|Mule|Set Language Environment|UTF-8". It isn't pretty, but as I use the US keyboard only rarely this works for me.

Syndicated 2007-10-03 17:04:44 from Gustavo M. D. Vieira

DSPAM Hash Driver Patches

I use the fantastic DSPAM SPAM filter in my mail server. I like it very much, specially when using the built-in hash-based storage, making it very fast and really easy to setup. That is, if the documentation and administration tools weren't so lacking. On the plus side, I got to know a little better the tool that keeps my email sanity and respect the developers that make it happen.

If you are an user of the hash driver, you can't rely on the provided tools to maintain your installation. The recommended way of cleaning old messages signatures doesn't work for this driver. Also, the hash-based database has to be cleaned from time to time or it will grow too big, but the tool to do it (cssclean) just doesn't work. To handle these problems, I first had to patch DSPAM so I could get a working cssclean. The main patch was created by Frank Cusack and you can get it in his aptly named message "cssclean is a redheaded stepchild" to the dspam-dev mailing list.

The second patch isn't strictly necessary (and I fear it might violate some design principle of DSPAM), but it keeps cssclean from resetting the statistics of the database. I really can't remember where I found it, so I post it here:

diff -ru dspam-3.8.0.orig/src/tools.hash_drv/cssclean.c dspam-3.8.0/src/tools.hash_drv/cssclean.c
--- dspam-3.8.0.orig/src/tools.hash_drv/cssclean.c      2006-05-27 18:00:36.000000000 -0300
+++ dspam-3.8.0/src/tools.hash_drv/cssclean.c   2007-06-27 19:18:51.000000000 -0300
@@ -167,7 +167,7 @@
     header = offset;
     filepos += sizeof(struct _hash_drv_header);
   }
-
+  bcopy (old.header, new.header, sizeof(struct _hash_drv_header));
   _hash_drv_close(&new);
   _hash_drv_close(&old);
   rename(newfile, filename);

Finally, I run the following script monthly using cron:

# Clean hashes and signatures.
for u in /var/lib/dspam/data/*/*.css; do
    /usr/bin/cssclean $u
done
find /var/lib/dspam/data -name *sig -type f -mtime +30 -exec rm -f {} \;

Probably you will have to adapt it to the file locations of your DSPAM installation.

Syndicated 2007-10-02 20:19:26 from Gustavo M. D. Vieira

K9Copy 1.1.3 RPM

I've updated my RPM package for K9Copy to the 1.1.3 release. Get it here.

Syndicated 2007-08-29 14:46:47 from Gustavo M. D. Vieira

High Resolution Timer in Java 5

Last week I needed to generate (somewhat) high-frequency recurring events in Java for my thesis work. Nothing like real time, just call a method from 10 to 1000 times per second, but I want to able to tune it so it can run at a precise frequency in this interval. Should be easy, right? In theory it is: discover the period of recurrence, do the action, sleep the remaining time until the next occurrence. For example: if I want to generate 500 events per second and my action takes 200µs, then my period is 2ms and I must sleep 1800µs between executions.

So, I need microsecond precision for the sleep. It is widely known that this is impossible in Java 1.4 without some native code. Fortunately, in Java 5 it's pretty easy to get nanosecond precision and this blog entry is very, very informative. Briefly, if you want to measure a time delta with nanosecond precision use System.nanoTime(), if you want to schedule a (possibly recurring) event with the same precision use the ScheduledThreadPoolExecutor class. I ended up using the former for my code.

But now, the weird part. Along with System.nanoTime(), Java 5 introduced the Object.wait(millis, nanos) and Thread.sleep(millis, nanos) methods for high resolution sleeps. Take a look at the source code for the implementation of these methods here (gotta love free software!). See. These methods just round up or down the millisecond argument using the nanosecond argument and call the millisecond only version of the methods. It took me some time and a bit of frustration to notice this. Annoying. You might be wondering: how the heck is ScheduledThreadPoolExecutor implemented then? The answer is another sleep method introduced in Java 5: LockSupport.parkNanos. This one actually works, as it uses a different native implementation.

Syndicated 2007-08-28 14:47:33 from Gustavo M. D. Vieira

Jaitime.org Fedora Core 6 Image Fix

My VPS provider uses Xen and the distro images from Jailtime.org. Recently I installed a fresh Fedora Core 6 image (as they don't have a Fedora 7 image) and found a very subtle bug.

In the tweaks section of the FC6 image at Jailtime.org it is said:

To resolve tls issues, issued the following commands (*):
  # cp /lib/i686/nosegneg/lib* /lib/i686/
  # ldconfig

The problem with this hack is that when you upgrade your glibc, the copied files will remain and will conflict with the new updated files. This is not theoretical, right now if you download and run the image, then execute yum upgrade your VM is hosed. End result, segmentation faults all around and you VM won't boot anymore.

To avoid the problem, remove all files copied into /lib/i686:

# rm -f /lib/i686/libpthread* /lib/i686/libc* /lib/i686/libm* \
        /lib/i686/librt* /lib/i686/libthread_db*

The alternative to fix TLS problems is proposed on the Jailtime.org site itself:

An alternative to the tweak above is to use the following commands:
  # echo "hwcap 0 nosegneg" > /etc/ld.so.conf.d/libc6-xen.conf
  # ldconfig

But it came with the cryptic warning that "This alternative did not work in the jailtime image however". Well, it does work with the Jailtime.org image.

By the way, after this issue was solved, I was able not only to update FC6, but to upgrade to F7 using Yum. The only extra step necessary is to make sure in the newly installed /etc/rc.d/rc.sysinit has the /sbin/start_udev line is commented out. Also, for some strange reason, the libgcc and libstdc++ packages have a higher version number in FC6 than in F7, so you will have to update these two by hand. Besides that, just follow this procedure.

Syndicated 2007-07-24 16:47:33 from Gustavo M. D. Vieira

Philips MCM108 Remote Bug

Recently I bought a Philips MCM108 compact stereo. It's a simple device, that works really well as an alarm clock. But it got a UI bug that's really annoying. The remote, for some bizarre reason, operates in a mode oriented fashion. That is, it only sends CD commands when you are in "CD mode". Problem is, you can enter "CD mode" from the main device itself, obviously without authorization from the remote. The end result is that you believe you remote is broken because you can't change albums, stop or start CD play. The solution? Every time the remote becomes catatonic, press the CD button to remember it of its sole purpose in life.

Syndicated 2007-07-02 22:13:22 from Gustavo M. D. Vieira

My Pyblosxom Setup

I'm running this site using Pyblosxom running on Fedora. Pyblosxom (as the original Blosxom) is very simple and uses only the file system to store blog entries, configuration, etc. Think of it as server side includes on steroids. As I know a bit of HTML, CSS and Python, and really hate big complex web applications it seemed like the perfect match for me.

I setup Pyblosxom as a non-root user, serving it from my public_html. To do this in Fedora you have to uncomment in the httpd.conf files the lines controlling UserDir directories and add the following to enable CGI from the public_html:

<Directory /home/*/public_html/cgi-bin/>
    Options ExecCGI SymLinksIfOwnerMatch
    SetHandler cgi-script
</Directory>
If SELinux is active you have to ensure that the files in ~/public_html and ~/public_html/cgi-bin have the right context (more info here).

With that out of the way, just install Pyblosxom as described by its documentation. The only twist in my setup is that I hide the name of Pyblosxom CGI script from my URLs and make the root of my page redirect to the blog root. This is accomplished with a bit of Apache rewrite magic. Put this .htaccess file in your public_html:

RewriteEngine on
RewriteBase /~replace-with-your-user-name
RewriteRule ^$ blog/ [R=permanent]
RewriteRule ^index.htm.*$ blog/ [R=permanent]
RewriteRule ^blog$ cgi-bin/pyblosxom.cgi
RewriteRule ^blog/(.*) cgi-bin/pyblosxom.cgi/$1

Configuration of Pyblosxom is best covered in its manual, but here is a tip I missed the first time. When customizing a flavour (and that's exactly like maintaining some server side includes), you can just copy the default html.flav dir to your local flavour dir; Pyblosxom will always pick the locally defined one overriding the default, so you don't have to call it anything different than "html".

Besides Pyblosxom, some HTML and CSS, I use the following Pyblosxom plug-ins:

  • pystaticfile.py: To have some non-blog entry, non-dated pages rendered with the same layout.
  • pagetitle.py: To have the entry title display at the page title (be sure to read the documentation in the source file).
  • wbgarchives.py: For compact archive links.

There are many other plug-ins available, and it doesn't seem to be really hard to code a new one in Python.

Syndicated 2007-06-30 12:39:04 from Gustavo M. D. Vieira

OpenMSX Rocks!

If you are a Brazilian (or Russian) geek in your thirties you must have spend a lot of your teen years in front of a MSX computer.

For a long time I have kept copies of fMSX lying around in my hard disk, in case I want to play some of the memorable games of my childhood. Problem is, I was having a hard time compiling it in recent systems. When looking for a alternative, I investigated OpenMSX and instantly recognized I had found the holy grail of MSX emulation. OpenMSX does not emulate one MSX implementation, it implements all of them. It isn't just a matter of playing the games, you can really relive the hardware with it.

For example, I was able to boot a Gradiente Expert 1.1, with the DDX-3.0 floppy controller and a MegaRAM cartridge just like it was 1988. I'm really sorry now that I haven't managed to make images of all my floppies.

As an extra bonus, OpenMSX is very Linux friendly and very easy to build. So I created a RPM package of it for Fedora, instead of just installing in my home dir. I don't know if I will be able to properly maintain it, but if you are interested check the OpenMSX RPM link in the nav bar.

Syndicated 2007-06-19 19:45:08 from Gustavo M. D. Vieira

Copying Dual Layer DVDs on Fedora

If you want to copy a dual layer DVD to a single layer one in Linux, you will very pleased to know K9Copy. This is a nice utility that removes unwanted extras and/or requantizes the main title while preserving the menu structure.

As it isn't available in the Livna repository, I created a RPM of it for Fedora. Check the K9Copy RPM link in the nav bar.

Syndicated 2007-06-19 19:42:43 from Gustavo M. D. Vieira

Hello, World!

After almost a decade in planning, I've got my new web page on-line.

Going with the zeitgeist, it was created using blog software: PyBlosxom. Problem is, I'm not the guy who have that drive to blog. For example, I should blog about my PyBlosxom setup, but it will have to wait. :)

Syndicated 2007-06-19 18:38:15 from Gustavo M. D. Vieira

16 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!