The maybe most important coding project of myself which has impact on my private programming as well as on my work is thelib_icon16 TheLib. The basic idea is to collect all classes which we (two friends and myself) wrote and used several times in several different projects over and over again. These classes usually are wrappers for compatibility or convenience around API calls or library calls (e.g. STL, Boost, whatever). That’s where the name of our lib cames from: Totally Helpful Extensions. And, it is just cool to write: #include "the/exception.h".

However, I hear very often: “Why do you write a lib? There are plenty already for all tasks.”

If that would be true, none of us would write programs anymore and we would only “compose” programs from libs. Well, we don’t. Or, rather I don’t. Meaning: TheLib really is helpful. It is not a replacement for the other libs. It’s a complement, and extension.

On Example: Strings!

The string functionality in TheLib is not nearly as powerful as one would required to write a fully fledged text processor. This is not the goal of TheLib. We wrote these functions to provide somewhat beyond basic functionality. The idea is to enable simple applications or prototypical applications to easily implement nice-to-use interfaces for the user.

Especially unter Linux (but also unter Windows) there are usually a total of three different types of strings:

  1. char * or std::string which store ASCII or ANSI strings with locale dependent character sets
  2. char * or std::string which store multi-byte strings, e.g. using UTF-8 encoding
  3. wchar_t * or std::wstring which store unicode strings.

Depending on these types different API functions need to be called, e.g. for determining the length of the string:

  1. strlen
  2. multiple calls of mbrlen
  3. wcslen

On issue that arises between case 1 and 2 is that modern Linux often uses a locale which stores UTF-8 strings within the standard strings. As long as strings are only to be writte, stored, and displayed, this is a great way to maintain compatibility and gain the modern feature of special character availability. However, as soon as to perform a more complex operation (like creating a substring) this approach results in unexpected behaviour als the bytes of a single multi-byte character are threated like independent characters.

Example:

  • Your user is a geek and enters “あlptraum” as input string.
  • This string is stored in std::string using the utf8-en encoding.
  • Your application now wants to extract the first character for some reason (e.g. to produce typographic capitalization using a specialized font).
  • The normal way of doing this is accessing char* first_char = s[0]; and std::string remaining = s.substr(1);
  • Because the japanese “あ” uses two bytes, this results in: “0” + “Blptraum”

This not only applies to japanese characters, but obviously to almost all characters with diacritics. What is even more important: this issue also results in unexpected behaviour when using (or implementing) string operations which ignore case, e.g. comparisons.

Example of changing a string to lower case:

// we will do this the STL-way:
// http://notfaq.wordpress.com/2007/08/04/cc-convert-string-to-upperlower-case/

std::string data;
// contains 'data' is set to "あlptraum" encoded with utf8-en locale

std::transform(data.begin(), data.end(), data.begin(), ::tolower);
// well, content of 'data' is now: "0blptraum"
// ...

To avoid this problem, TheLib internally initializes the system locale for the application and detects if the locale uses UTF-8 encoding. If it does, all TheLib string functions will call the multi-byte API functions to work as expected. In addition TheLib provides some functions to explicitly convert from or to UTF-8 strings (e.g. for file io).

Of course, you don’t need TheLib to do this. You can use another lib (probably. I only know the IBM-Unicode-Lib, which seems like a huge hulk) or you can use your own workarounds or you can ignore such problems as “they will not occure in your application scenarios”. However, having TheLib doing the job is just handy. Nothing more.

Software should solve problems. Sometimes this is the case.

I had a problem:

I have a somewhat older convertible laptop, an ASUS Aspire 1820PT. A nice and cheap convertible of it’s time. With touch screen support for up to two fingers and with an acceptable computational power. I have upgraded it in the meantime with an SSD and I am now running Windows 8. So far so good. The problem, however, is that the tilt sensor is no longer supported by Windows 8. 🙁

So I needed a solution. Hacking drivers or even writing drivers myself is not up my alley. I am an application developer. But, if something does not work automatically (anymore), we just need to make the manual use as comfortable as possible. That’s why I wrote a tiny tool: the DisplayRotator.

The idea is simple: the tool is attached to the taskbar. As soon as it is started it shows DisplayRotatorScreena simple window with four buttons for the four possible display rotation settings. Press one of these buttons and the display settings are changed accordingly. With this, I can setup my desktop orientation of my convertible with two clicks, even two tapps with my finger, and rotate the desktop aynway I like.

DisplayRotator.zipDisplayRotator.zip Display Rotation Tool
[152 KB; MD5: 07c3efddd05a98bf4d02db595b87f2fe; More Info]

And, because I can, the zip also contains the source code of the tool. It is written in C# and naturally uses the Windows API to change the display settings. Nice and easy. With the same code basis all display settings can be changes, like screen resolution and refresh rate. Even detaching or attaching monitors to the desktop is possible. Ok, the code for these functions is not in the tool, but the API calls are the same.

Maybe the tool can be of use to someone else too.

The Windows Powershell is quite nice. Of course, now all the Linux users start bitching around, that they always has something like this and that it is nothing special. And no one claims otherwise. But still, the PowerShell is nice and I enjoy it. 🙂

Like today: I needed a simple hex dump of a file:

PS >  $str = ""; $cnt = 0; get-content -encoding byte C:\pfad\zur\Datei.txt | foreach-object { $str += (" {0:x2}" -f $_); if ($cnt++ -eq 7) { $cnt = 0; $str += "`n"; } }; write-host $str

It’s elegance is limited, that I will admit, however, I does it’s job. And, somehow, it is quite nice …

I believe there are many people out there, which did not think this day would come. To all of those, I like to kick you in your shins, at least virtually. If I say I am doing something, then I will do it!

BurnsTOK_3_0_49_0.zipBurnsTOK_3_0_49_0.zip Mr. Burns TOK
There is a newer Version of this File available
[129 KB; MD5: 7868fdb2a0f1c26d28cb88c618bf21e3; More Info]

Therefore, here it is: Mr. Burns TOK (Version 3.0)

Completely rewritten in C# for better maintainability and future bugfixing. Simply download and run (no Setup).
All you need is the Dotnet 2 Framework, which you most probably already have on your machine.

Just wanted to let you know I am still alive!

I am burried under my PhD thesis at the moment, so I got almost no time for my little programs …

But only almost 🙂 In fact, there is just ONE, SINGLE function to be implemented for Mr. Burns TOK 3. Everything else is already completed, tested, and working! So stay tuned!

 

While I was coding for Mr. Burns 3 config-dialog window I realised that I made a silly mistake in the GUI of Dib. Sometimes, reading or writing the desktop icon information takes several seconds and the Dib GUI did not show that the program was still busy. I mean, how stupid is that.

Dib.1.3.15.0.zipDib.1.3.15.0.zip Desktop Icon Backup
There is a newer Version of this File available
[377 KB; MD5: 82bb2c82aeaf070412c40192fbe3390e; More Info]

So I loaded the Dib project and made this little change (less than 30 minutes of work). Therefore, here it is: a mini update for Dib.

Last week I tried to use DIB to restore the icon positions on my computer at work. However DIB told me that he couldn’t find my desktop. … wut?

So, I debugged a little and checked what was happening. Actually, the desktop window was really detached from the desktop’s process main window. I have no idea what happend, but since this strange state survived even a reboot of my machine, I decided to update DIB to be able to work with this situation as well. Here it is:

Dib.1.4.16.0.zipDib.1.4.16.0.zip Desktop Icon Backup
Selected File Version not found, showing newest Version instead
[378 KB; MD5: 846a6d216e74ad0f09eae94f1f2279d7; More Info]

We can’t ignore the fact: the year 2010 is almost past. At such times I recognize how much I have not done of what I wanted to do. I am still not millionaire and all my projects are significantly less complete than they should be. There is absolutely no doubt that this will also happen next year. But, that is no reason not to try as much as I can (or more). 🙂 I want to show you a, for sure incomplete, list of my current projects and my projects planned for 2011. I sorted the list according to my personal priorities, which might change any minute.

  • MegaMol
    The only “commercial” project I will show here. Early 2011 I plan to get version 1.0 of MegaMol up and running.
  • Exoworlds
    It possibly is my oldest long-term project. But I love it and I will not let it die!
  • MILC
    A very young project, started this week because of personal needs. I don’t want to give too much information about it just now, but stay tuned.
  • Nameless Board Game
    A small board game I am planning for some time now (imagine a cross-over of “Risk&quot, “Chess”, and “Checkers”). Every now and then I had a name of the game, but I didn’t liked most of them. Currently I am still tweaking the rules, because I want to ensure that no player could force a tie. Although, there is some progress, it is much slower than I hoped it would be. Well, I believe creativity cannot be forced.
  • Working Title: NSB
    Behind the working title NSB stands an idea; a good idea! 🙂 More info to come…
  • Kanoneur 2
    In the week just before Christmas a good friend of my reminded me of the mini-game “Kanoneur” I have written a long time ago. For me it was a project to gain some practice in OpenGL. The gameplay was basically the one of Tank Wars. When my friend reminded me of all the “enhancements” we came up for the game, I wanted to re-start that project again. So “Kanoneur 2” will come, although it is probably the game with the most stupid name of all time.
  • My Websites
    There is still much to do at my websites; nothing visible, all optimizations and enhancements of the scripts.
  • Mr. Burns TOK
    I didn’t forget about it. It’s just that my motivation to work with this ancient source code is not that high. But I promise, I will do it “soon”.
  • All my little Helpers/Tools
    I got roughly a dozen small tools I am writing to ease my daily work. I would be nice if some of them would finally be completed. :-/

Because I know myself, and I am pretty sure I will not write another post this year:

I wish you all a Happy New Year 2011!