Lazy source code comment stunts

Double-Slash-Whole-Block-Commenting

Here is a simple way to disable or enable whole code blocks with just two slashes:

PHP / C++:

/*
  Block (commented block)
//*/
///*
  Block (active block)
//*/

Object Pascal/Delphi:

(*
  Block (commented block)
//*)
//(*
  Block (active block)
//*)

Alternatively you can use { and } in the Object Pascal/Delphi example.


Double-Slash-Whole-Block-Switching (Object Pascal/Delphi only)

The Object Pascal dialect used in Delphi supports three ways of commenting code, two for commenting whole blocks ( { } and (* *) ) and one for commenting lines ( // ).
We can exploit this feature to switch between two code blocks easily and fast:

Block 2 is in the enabled state:

{
  Block 1  (commented block)
(*}
  Block 2  (active block)
//*)

Note, I am just adding two slashes in front of the first comment block to activate it again – similar to Double-Slash-Whole-Block-Commenting trick above. This will also magically disable the second block due to the way the comment marks are arranged:

//{
  Block 1  (active block)
(*}
  Block 2  (commented block)
//*)

These tricks are probably applicable to other programming languages as well. Please let me know.

Q…/Free: Bug in QProcess writeToStdin

All right, this post is just to stop somebody else’s suffering in figuring out why writing to stdin in QProcess on Version 3.3.x-8 of Q…/Free doesn’t work on Windows. Well, actually it works but just for the first line you write to stdin. There is a bug in qprocess.cpp at line 730:

void QProcess::writeToStdin( const QString& buf )
{
    QByteArray tmp = buf.local8Bit();
    tmp.resize( tmp.size() - 1 ); // drop the implicit \0
    writeToStdin( tmp );
}

should be:

void QProcess::writeToStdin( const QString& buf )
{
    QByteArray tmp = buf.local8Bit();
    tmp.resize( buf.length() );
    writeToStdin( tmp );
}

Verision 3.3.7-7 includes the latter method, same as the latest Qt 4.3 sources. So, it’s actually a regression in 3.3.x-8. If you require the latest Qt 3 / Q…/Free for your open source application and need to write to some other processes’ stdin, you can just use a wrapper workaround that uses the latter method and directly uses writeToStdin( const QByteArray& buf ) instead of the QString variant.

rdesktop: Connect to Windows 7 and Vista with ClearType font smoothing enabled

So Windows Vista finally allows to enable ClearType font smoothing for Remote Desktop / Terminal Services sessions. Update: Windows XP SP3 does too!
If you try to connect to a machine running Windows XP SP 3 or later using rdesktop, you won’t get smoothed font typing since at the time of this writing rdesktop does not officially offer an option to control this feature. However, here is a workaround:
Continue reading “rdesktop: Connect to Windows 7 and Vista with ClearType font smoothing enabled”

Enhanced audio driver for Zaurus SL-C1000/C3x00 available

Today I’m officially releasing my extended driver and mixer for the Wolfson WM8750 CODEC / sound chip that comes included in the latest Zaurus models.
The driver exposes the following new features:

  • ability to set and control Treble, Bass and 3D stereo sound enhancement;
  • ability to set and control various cut-off frequencies supported by the sound chip;
  • output source selection (Autodetect, Internal Speaker, Headphone).

These features can be easily accessed via a Qt based mixer control app or directly via a /proc/driver/wm8750 kernel interface.

{wm8750mixer} WM8750 mixer control app running on pdaXii13 and X11.{wm8750mixer} WM8750 mixer control app running on Cacko ROM and Qtopia.

Both, the driver and the control app are available for Sharp ROM / Cacko ROM and pdaXrom beta 3 / pdaXii13.

Kernel patches are available for Sharp’s Linux kernel 2.4.20 and can be downloaded here:
http://www.katastrophos.net/zaurus/sources/wm8750mixer/
(No kernel 2.6.x support yet. Sorry folks.)

By default the audio driver is compiled into the kernel. Sharp didn’t compile it as module, so it can’t be easily replaced. Same goes for most third party ROMs. You’ll have to reflash your kernel to install the new driver.
In case you don’t want to roll your own kernel, I’ve made pre-compiled kernels available for all supported ROMs and models here:

http://www.katastrophos.net/zaurus/kernels/v55/

The control app and start up scripts are available as IPK here:

wm8750mixer_0.9_arm.ipk – WM8750 mixer for Sharp ROM / Cacko ROM
wm8750mixer_0.92_armv5tel.ipk – WM8750 mixer for pdaXrom beta 3 / pdaXii13

On a side note, we’ve been discussing the extended features of the WM8750 audio chip for quite some while in this thread over at the OESF forums. I have the feeling the driver and the Qt application have received a fair bit of testing. So, that’s why I am officially releasing it today.

SQLite simple timing profiler patch

Update: SQLite now features an integrated timer which can be activated via the .timer command in the console shell. Details here.

As a follow-up to my previous post “SQLite performance tuning and optimization on embedded systems” here is a very basic patch that introduces support for timing SQL queries in the sqlite3 console shell.

SQLite 3.3.8:
Patch against shell.c shell.c

SQLite 3.3.9 CVS – shell.c rev 1.157:
Patch against shell.c shell.c

Two new shell commands are introduced in sqlite3:

.profile ON|OFF        Turn profiling on or off
.timer start|show      Measure elapsed CPU time

.profile ON will turn off output to stdout. Instead it will display CPU execution time for every SQL command processed.
Here is an example output:

sqlite> .profile on
sqlite> .read test1.sql
Exec time  BEGIN;                                       :  0.000 s.
Exec time  DROP TABLE IF EXISTS playlist_view;          :  0.020 s.
Exec time  DROP TABLE IF EXISTS overview;               :  0.000 s.
Exec time  CREATE TEMPORARY TABLE playlist_view AS   ...  :  0.180 s.
Exec time  CREATE TEMPORARY TABLE overview AS        ...  :  0.140 s.
Exec time  SELECT DISTINCT genre, genre IN ("Progress...  :  0.030 s.
...

Note: You can still override the output setting with the .output command after an .profile ON has been issued.
.profile OFF will turn off time-based profiling and reenable output to stdout.

.timer start will start a timer. You can execute a sequence of queries and then print the required CPU time via .timer show.
Use .timer start again to reset the timer. This .timer patch is based on SQLite ticket #1227 by Bartosz Polednia.

Timing is currently done using clock() which provides only a 10 ms precision for CPU time on most systems. This might be inadequate depending on your requirements. If you know a more precise way, please let me know.

Installing OS X 10.4 Tiger (PowerPC) from a Firewire harddrive

Last weekend I had the pleasure (!) to install Tiger on an ancient PowerMac that doesn’t feature any DVD-ROM drive. I don’t happen to have the special CD-version of 10.4 and trying to boot from an external DVD drive somehow failed. However, this Mac already had Firewire, so here is a little hint on how to install Tiger using a spare Firewire drive:

First off, you’ll need psync. I’ve tried Carbon Copy Cloner, but for some reason that didn’t work.
So, if you have Fink installed, do this:

$ fink install psync

Format the Firewire drive with HFS Extended. You don’t need Journaling, so please disable it.
Now, assuming you’re Tiger Install DVD is mounted at /Volumes/Mac OS X Install DVD and your formatted volume is mounted at /Volumes/OSX, type this into your Terminal to clone the content of the DVD over to the harddrive.

$ sudo psync -d "/Volumes/Mac OS X Install DVD/" /Volumes/OSX

Finally make the whole copy bootable by blessing it:

$ sudo bless --folder "/Volumes/OSX/System/Library/CoreServices" --bootinfo

Now, you may unmount and install. Fin .

Apple Cube Biohazard graphics card mod

Since I’m in the mood to document various hardware modifications, here is a link for the archives:
http://www.katastrophos.net/macosx/9000pro-mod.html
This is a tutorial written in German for a mod I did way back. It describes how to modify the case of an Apple Cube to actually insert a better graphics card along with proper cooling of the components.
Much of the article deals with how to relocate the DC/DC board to the inside of the Cube to make way for the bigger graphics card. It goes on to describe how to modify the graphics card with a better heatsink. Finally, it shows how to cut the outer casing for proper cooling.

You might ask, why this is called Biohazard mod. Check out this and that.

The Mac Mini external SATA hack

So, finally as promised, here is my short picture walkthrough on how to do the Mac Mini external SATA hack.
I’ve added quite a few comments to the images.
And before you start complaining about the bad picture quality, I’ve shot the whole procedure with my non-HD DV cam, sorry. The pictures are from several takes, so they might differ at some stage.
Anyways, just click on the first image below to start the slide show – navigate by clicking the left or right side of the photo.
I hope you like it and please leave me a comment afterwards. Thanks!
Continue reading “The Mac Mini external SATA hack”