Category Archives: computers

KGS bureaucracy

I have to deal with unreasonable KGS users all day long. They argue about totally insane things ad infinitum. I try to be patient and understanding, as far as it’s possible. I am even trying to be nice to people who complain about escapers.

I got used to KGS users being unreasonable, but I at least expected a bit reasonable behaviour from admins.

tasuki: if I say pretty please, will you move “Photography” room to social? (yes, I know I own way too many rooms, but there’s no photography-related room on KGS and I think it’s a pity)
anonymousadmin: ok, what other accounts do you have?
anonymousadmin: … gotta put you through the hoops
anonymousadmin: yikes… tasuki owns several rooms!
anonymousadmin: how did you get allowed so many??

Haha, good one (you know, admins like to tease each other a little bit). After some more discussion, I check the room and it’s still in “New rooms”. Well, turns out this wasn’t a joke after all.

To explain what’s going on: there are various arbitrary rules on KGS. My theory about these rules is that whoever invented them thought “our admins are pretty dumb so I have to create very concrete rules for the admins to be able to follow them and not to have to apply their common sense”. Unfortunately, the inventor probably wasn’t much mistaken.

One such rule is that for a room to be moved from “New” category to any other, it must have a description and the owner must not own any other rooms. Nice rule. Except that you can circumvent it by finding someone who has no room yet to create this one for you. Or you can simply stop being owner of your other rooms and only own this one.

In my humble opinion, these rules are being misused. For example, this particular rule was obviously designed to prevent certain individuals from creating many meaningless rooms. It was not created to prevent someone from creating a perfectly valid and useful room about something many people are actually interested in. But “we have to follow the rules”. Oh btw, the admin in question also owns several rooms. So sue me.

PS: Take this as an invitation to join the “Photography” room, under Social. :-)

Tone Mapping with GIMP

“Tone mapping reduces global contrast in images while increasing local contrast and shadow/highlight detail.” or so Gimp Addict’s Tone Mapper tutorial says. Go and read his tutorial, I will add few comments to it:
4) “radius of 100-500 is good” — yes, it usually is, but since we don’t know the size of the image, I’d rather say that 10% of image size (that is (width+height)/2) is a good starting point.
5) 75% is again a good starting point, but you might want to play around with the value.
7) It depends… if you want to increase the tonemapping effect, duplicating the “soft light” layer is the way to go (I’ve tried changing the layer mode and nothing else really worked at all).

So I wanted to create a script that would do this. After searching the GIMP Plugin Registry, I found Tone mapping script, which basically follows Gimp Addict’s guide. However, it only has two options – the amount of blur and the amount of layer transparency. That certainly isn’t enough for me. Luckily, the plugin is GPL…

(((GIMP’s Script-Fu) uses Scheme) (which is (a dialect) (of the (Lisp (programming language)))) ((Lisp is a (programming language)) (for people) (who (really (really (like parentheses))))))

And because I like parentheses almost half as much as an average Lisp programmer, I rewrote the Tone mapping script and created Advanced Tone Mapping script. Feel free to put it in your GIMP’s script directory (~/.gimp-2.4/scripts/ in my case).

There are four parameters for Advanced Tone Mapping script:

  • Gauss. Blur (% of img size) — is the amount saying how much the blurring should be used for the tone mapping. It is in percents of image size (where image size = (width+height)/2). Ten is a good default, but different values might be interesting too.
  • Opacity of blurred layer — this is the 75 default, which can be changed if you want stronger or weaker effect.
  • Opacity of merged layer — the default is 90. If 100 is not enough, consider increasing number of “copies of merged layer”.
  • Copies of merged layer — when one, it’s barely noticeable, you can deny any accusations of postprocessing easily. :) Three has a lot of “halo effect” and anything above five will completely mess all colours up.

The first set of pictures is simply a preview. The image on the left is the original image, and the image on the right is processed by Advanced Tone Mapping with Gaussian-blur set to 10, opacity of blurred layer equal 75, opacity of merged layer full 100, and finally three copies of the merged layer (note the way I use to show those values — it is also used for naming the layers, which can be handy if you later forget which layer is which or what you have done). The image on the right might be a bit over the top, but it shows nicely what can be done with Advanced Tone Mapping script:

Tone mapping

The next example shows some pretty conservative tone mapping. The one on the left was created with almost none blur, while the one on the right has 10% blur. Note the difference: the one on the left has no halo but appears a bit flat, while the one on the right has a slight halo but also has higher level of detail.

careful Tone mapping

Oh my… the following example shows what can go wrong with tone mapping (I’m sorry for all the people who already gouged their eyes out). The reason why image on the left appears so flat and awful is that almost no blur was applied. The image on the right is a comparison with healthy blur applied. Five copies is still a bit too much, but hey, at least it has kind of action-like look.

Tone mapping gone wrong

The last image shows the difference between the default blur and maximum blur available. As you can see in the right side picture, the halo is so huge it’s almost impossible to see. The bad news is that with maximum blur we lose a lot of detail near the borders of light/dark areas.

Tone mapping different halo

Ok, that’s it — now go and experiment with my script on your own photos. 8-)

PS: Underexpose your images — the dark areas can still be lightened, while the burned out areas are usually completely white and can’t be darkened.

PPS: The more contrast there is, the more layers you apply, the more blur you will usually need.

PPPS: Any kind of noise in your picture will be greatly amplified.

PPPPS: No, this is not HDR, this is just tone mapping of a single image (just jpeg, in my case). Tone mapping is a part of HDR, but HDR is not a part of tone mapping. ;)

Hardy Heron

As my Ubuntu Edgy (6.10) was not quite cutting edge anymore, I decided to get Hardy Heron.

Upgrade over two skipped releases would be suicidal, so I decided to do a fresh install. I also wanted to preserve my old Edgy… you know — just in case. That involved cutting off half of my system partition to create a new partition. You might expect a horror story now, but in fact it all went flawlessly (I just used gparted, the ext3 got fscked, shrinked to a half without a single glitch, passed fsck again and voila).

Installation of Hardy was provided by a nice graphical installer that didn’t even bother asking questions about my hardware (it just asked me about country and language settings and stuff like that). It recognised my monitor resolution, I installed the proprietary nvidia-glx-legacy drivers with two clicks (yes, it’s not even necessary to touch xorg.conf anymore). I just had to set up the wifi connection manually, because the access point has a hidden ESSID (but all the drivers were already there).

I was amazed how everything works out of the box or almost out of the box. Need to play a movie and don’t have the codec? You get a pop-up asking if you would like to download the codec. You click yes and enter your password, you are all set.

Hardy Heron includes Firefox 3 (beta 5 as of now), which is great, because the speedup over Firefox 2 is rather significant (and it does have some nice new features too). The only sad thing is that Google Toolbar doesn’t work in FF3B5 (yet), but well, I don’t really need to see the pagerank of every page I visit.

With my old 32MB GeForce 2 I never bothered installing Compiz, but as it comes out of the box now, I just had to try it. And whooo it rocks. The cube is amazing and there is also this great “scale windows” thingy, that shows all open windows at once so that you can switch between them. And then there are hundreds of different visual effects…

Gnome now allows repositioning the window toolbar items by drag&drop’ing them. That is the feature I’ve always (secretely) wanted. It’s really useful (as opposed to grouping, which I always (not so secretly) hated).

All I can say is: “Wow“.

PS: I don’t say this often, but I have to say it now: In case you haven’t done so yet — with XP being obsolete and Vista near unusable — this is definitely the best time to switch to Linux. And if you encounter any problems, I’ll be happy to help you with troubleshooting.

Common sense and frustration

Do you know what common sense is?

Common sense is:

  • NOT setting fixed height for elements whose actual height can change anytime, and especially not setting this particular height to three elements next to each other, to keep them with the same height (common sense solution is to wrap it all in another element)
  • NOT calling your database tables j_aidx_1, j_aidx_2 … j_aidx_n and calling the columns m_1, m_2, m_3, etc; which leads to people writing queries like SELECT a.m_85, a.m_167, b.m_17, b.m_56 FROM j_aidx_5 AS a LEFT JOIN j_aidx_8 AS b ON a.m_103 = b.m_42 WHERE b.m_58 = ‘1’ AND a.12 = ‘0’
  • invoking the live server settings as default instead of using testing environment settings as default, because when something goes wrong in the decision process, you don’t want the live server to get fucked up
  • NOT having the very same function copied to several different “modules” of the application so as to make it extremely inconvenient to change
  • NOT calling your backups “new”, “!new”, “_new”, “____new”, “!!!!!new” etc, especially when each person uses a different flavour of this method
  • using a version control system, and if you are unable to do so, calling your backups by date (preferrably in YYYY-MM-DD format, since it sorts itself naturally)
  • using either tabs or any amount of spaces for indentation, but keeping it consistent (or at least, for fuck’s sake, keeping it consistent within one file)
  • NOT internally calling files for inclusion 1.html, 2.html, 3.html etc., especially when you already went through the hassle of creating nice looking URL’s
  • NOT totally breaking your URL’s and titles by adding a lot of random keywords just to game search engines, when that makes your site either unusable or extremely confusing for humans
  • using one language (human language, like English or Czech) in your application, or at least avoiding mixing up several languages inside one particular variable or function name (findAllNovinky is just lame function name)

… do you know what frustration is?

Windows, Linux, Usability and Filemanagers

This is not going to be only about the systems themselves, rather about general (desktop) working environment. As I had to spend substantial amount of time working with Windows recently, I feel qualified enough to share some insights:

What I like in Windows:

  • Total Commander: it really rocks, it remembers my ftp connections with passwords, it allows me to use tabs, and it has many other nice features (I just don’t get it why I can’t rename files with F2)

What I don’t like in Windows (sorted by annoyingness):

  • Broken clipboard: When I select bloody text I want it in the bloody clipboard. This is just fucking annoying as I have to copy text between apps several hundred times a day.
  • No real terminal with real commands: Sure, I can use ALT+F7 <tab> <tab> <tab> <tab> <tab> <space> in Total Commander, but I find “grep” much more comfortable to use than ALT+F7 <tab> <tab> <tab> <tab> <tab> <space>, not only because grep is just four keystrokes and ALT+F7 <tab> <tab> <tab> <tab> <tab> <space> is eight, but also because grep has all sorts of things like -i or -x (those can probably be reached in Total Commander with something like <tab> <tab> <tab> <tab> <space>, but again, that’s not very comfortable). As for commands I miss, I mentioned grep, but there’s also bc, tcpdump, df, du, top, ps, and that’s just off the top of my head.
  • Moving windows with alt: when I hold alt, and press down mouse button, I want the window to move. Especially when the window jumps out on me with its title bar hidden above the top of my screen, as is usual in MS Windows (a colleague suggested a very useful ~5 key combination that helped, but I already forgot what it was).
  • Missing package management: want to update all the installed software to newest versions? Out of luck, I guess…
  • All those annoying messages that attack me from lower right part of screen everytime I log in.

What I don’t like in Linux:

  • General inconsistency in behaviour of different apps (one gets used to it occasionally, though).
  • Applications crash much more often (though the system itself stays stable). But it’s getting better (I haven’t experienced gaim crash ever since they started calling it pidgin ;-), and firefox 2 doesn’t crash anymore either).
  • No good filemanager for everyday work.

And now for something completely different:

Yeah, separating different topics into individual posts and all that… never been too good at that…
So, I’m searching for a good Linux filemanager… here are features of the ideal one (sorted by priority):

  • Two-panel layout
  • Find-as-you-type (without having to press alt key or something to enable it, I have a terminal in the other window, thank you)
  • Ability to remember ftp connections (w/ passwords is a big plus). Also, ability not to segfault when one tries to upload a file through an ftp connection that timed out (hello, mc?).
  • Lynx-like motion (left and right ascend/descend directories)
  • Tabs on each panel (that’s useful when working on many things at once)
  • Ability to run in a terminal (not too important, but it surely would be neat)

So far, mc is the best, but it’s still far from perfect (doesn’t remember passwords, segfaults on ftp timeout, no tabs support).

Weekly flickroutine

As we all know, Flickr is the best photo sharing site (if you haven’t heard it yet, Microsoft is buying Yahoo, who own Flickr… so there’s a very real possibility that Microsoft will kill Flickr, which would make me hate them even more). Almost unbelievably, the flickr source is only 60k lines of php and 60k lines of templates… I’ve seen 10k lines files that didn’t do anything useful. The fact that all of the Flickr’s functionality can fit in 60k lines is simply amazing.

Flickr has the best features and — even more importantly — best photographers and best photos. Flickr Explore shows some of the most interesting, provoking and artistic photos.

And the best way to view any Flickr galleries (including Explore) is Flickriver. It’s currently my most favourite site on all the internets.

Why Flickriver rocks:

  • Infinite scrolling (aka river) enables you to get to see more photos simply by scrolling to the bottom. No more clicking “next” and “previous”! (I absolutely hate paging, having everything on one page is just perfect)
  • Black background just makes it look good. Show me a photo that looks better on white background and I’ll show you a hundred that look better on black background.
  • Larger image previews are much better than the small squares you usually see on flickr, you see the full uncropped picture, and you see it at a size which actually enables you to recognize what is displayed on the picture.

At least once a week, I visit Flickriver and go through at least top 50 explore photos from each day since my last visit. I’ve been doing this for several months yet I’m amazed over and over again how perfect photos there are.

Give Flickriver a try, I’m sure you won’t regret it!

Oh, and I can highly suggest viewing my favourite photos (mostly falling into at least one of these categories: hdr, landscapes, mist/fog, cities, conceptual).

Object-oriented or procedural?

As I mentioned in the previous post, I needed a CAPTCHA algorithm. As I couldn’t find anything simple and usable that would do what I want (ie follow the basic principles of captcha creation (readibility for humans, and hopefully unreadibility for machines)), I decided to write my own. The purpose of this was just to generate the image, I left generating the text, passing it in a secure way and all the other boring stuff for others. And as an exercise, I’ve done both procedural and object-oriented versions.

I’m not an expert on object oriented programming, so my little class could have probably been written in a better (read: longer and even more confusing) way. Anyway, here it is:

[code lang=”php”]/**
* @name TasuCaptcha
* @author Vit ‘tasuki’ Brunner
* @license GNU GPL
* @version 0.001
* remarks:
* you need php (duh)
* you need gd
* you need the font file, in the same directory as this
* (get it at )
* if you want to use antialiased line, you need function drawQSLine()
* get it from
* code_couturier at graffiti dot net
* # antialiased draw_line function 1.1 (faster)

class TasuCaptcha {
private $bg;
private $fg;

// picture
public $width; // width of the picture
public $height; // height of the picture

// letters
public $font; // font for the letters
public $fontHeight; // height of the letters
public $maxAngle; // maximum angle for the letters
public $top; // where the letters should start – y
public $left; // where the letters should start – x
public $letterWidth; // approximate width of each letter

// line
public $step; // the length of line between turns
public $stepDiff; // the max height difference for step
public $lineBorder; // borders for the middle line
public $thickness; // thickness of the line
public $antialiased; // if true, makes the line antialiased

function __construct($text) {
// picture
$this->width = 170;
$this->height = 50;
$bgColor = ‘113355’;
$fgColor = ‘CCCCCC’;

// letters
$this->text = $text;
$this->font = ‘./gentium.ttf’;
$this->fontHeight = 25;
$this->maxAngle = 15;
$this->top = 35;
$this->left = 10;
$this->letterWidth = 30;

// center line
$this->step = 5;
$this->stepDiff = 5;
$this->lineBorder = 15;
$this->thickness = 2;
$this->antialiased = false;


function setBgColor($color) {
if (strlen($color) != ‘6’) die(‘setBgColor needs 6 letter hex color’);
$this->bg[‘r’] = hexdec(substr($color, 0, 2));
$this->bg[‘g’] = hexdec(substr($color, 2, 2));
$this->bg[‘b’] = hexdec(substr($color, 4, 2));
function setFgColor($color) {
if (strlen($color) != ‘6’) die(‘setFgColor needs 6 letter hex color’);
$this->fg[‘r’] = hexdec(substr($color, 0, 2));
$this->fg[‘g’] = hexdec(substr($color, 2, 2));
$this->fg[‘b’] = hexdec(substr($color, 4, 2));

function drawImage() {
// create image and set colors
$im = imagecreatetruecolor($this->width, $this->height);
$background = imagecolorallocate($im,
$this->bg[‘r’], $this->bg[‘g’], $this->bg[‘b’]);
imagefill($im, 0, 0, $background);
$textcolor = imagecolorallocate($im,
$this->fg[‘r’], $this->fg[‘g’], $this->fg[‘b’]);

// draw letters
for ($i = 0; $i < strlen($this->text); $i++) {
$this->angle = rand(- $this->maxAngle, $this->maxAngle);
imagettftext($im, $this->fontHeight, $this->angle,
$this->left + $this->letterWidth * $i, $this->top,
$textcolor, $this->font, $this->text{$i});

// draw the line
$curheight = $this->height / 2;
for ($i = 0; $i < ($this->width / $this->step); $i++) {
$lastheight = $curheight;
$curheight = $curheight + rand(-$this->stepDiff, $this->stepDiff);
if ($curheight > $this->height – $this->lineBorder)
$curheight -= $this->stepDiff;
if ($curheight < $this->lineBorder)
$curheight += $this->stepDiff;

// this could be done better…
for ($j = 0; $j < $this->thickness; $j++) {
if ($this->antialiased) // draw antialiased line
drawQSLine($im, $this->step * $i, $lastheight – $j,
$this->step * $i + $this->step, $curheight – $j,
$this->fg[‘r’], $this->fg[‘g’], $this->fg[‘b’]);
else // draw aliased line
imageline($im, $this->step * $i, $lastheight – $j,
$this->step * $i + $this->step, $curheight – $j,

// output the image
header(‘Content-type: image/png’);

// maybe someone could find this useful
return $this->text;

// now we can try to use it:
$captcha = new TasuCaptcha($cnum);
$captcha->antialiased = true;

Well, that was long, wasn’t it? And most of the time we were just moving values around… $this->shit = $shit;

Now the procedural version:

[code lang=”php”]/**
* @name tasucaptcha
* @author Vit ‘tasuki’ Brunner
* @license GNU GPL
* @version 0.001
* remarks:
* you need php (duh)
* you need gd
* you need the font file, in the same directory as this
* (get it at )
* if you want to use antialiased line, you need function drawQSLine()
* get it from
* code_couturier at graffiti dot net
* # antialiased draw_line function 1.1 (faster)

function tasucaptcha($text) {
// picture
$width = 170; // width of the picture
$height = 50; // height of the picture
$bgcolor = ‘113355’; // please keep this 6 letters long
$fgcolor = ‘CCCCCC’; // please keep this 6 letters long

// letters
$font = ‘./gentium.ttf’; // font for the letters
$fontHeight = 25; // height of the letters
$maxAngle = 15; // maximum angle for the letters
$top = 35; // where the letters should start – y
$left = 10; // where the letters should start – x
$letterWidth = 30; // approximate width of each letter

// center line
$step = 5; // the length of line between turns
$stepdiff = 5; // the max height difference for step
$lineBorder = 15; // borders for the middle line
$thickness = 2; // thickness of the line
$antialiased = false; // if true, makes the line antialiased


// get colors
$bg[‘r’] = hexdec(substr($bgcolor, 0, 2));
$bg[‘g’] = hexdec(substr($bgcolor, 2, 2));
$bg[‘b’] = hexdec(substr($bgcolor, 4, 2));
$color[‘r’] = hexdec(substr($fgcolor, 0, 2));
$color[‘g’] = hexdec(substr($fgcolor, 2, 2));
$color[‘b’] = hexdec(substr($fgcolor, 4, 2));

// set up the image
$im = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($im, $bg[‘r’], $bg[‘g’], $bg[‘b’]);
imagefill($im, 0, 0, $background);
$textcolor = imagecolorallocate($im, $color[‘r’], $color[‘g’], $color[‘b’]);

// draw letters
for ($i = 0; $i < strlen($text); $i++) { $angle = rand(-$maxAngle, $maxAngle); imagettftext($im, $fontHeight, $angle, $left + $letterWidth*$i, $top, $textcolor, $font, $text{$i}); } // draw the line $curheight = $height/2; for ($i = 0; $i < ($width / $step); $i++) { $lastheight = $curheight; $curheight = $curheight + rand(-$stepdiff, $stepdiff); if ($curheight > $height – $lineBorder) $curheight -= $stepdiff;
if ($curheight < $lineBorder) $curheight += $stepdiff; // for ($j = 0; $j < $thickness; $j++) { if ($antialiased) // create antialiased line drawQSLine($im, $step * $i, $lastheight - $j, $step * $i + $step, $curheight - $j, $color['r'], $color['g'], $color['b']); else // draw aliased line imageline($im, $step * $i, $lastheight - $j, $step * $i + $step, $curheight - $j, $textcolor); } } // draw the image header('Content-type: image/png'); imagepng($im); imagedestroy($im); return $text; } tasucaptcha($cnum);[/code] Unless one is paid by lines of code, one must conclude that the second version is much better. It's half as long and twice as readable. As for the captcha itself -- I can't guarantee that the results are machine-unreadable, but at least they are human readable. :-)

Few WordPress-related improvements

In wordpress database, column comment_status is of type enum(‘open’, ‘closed’, ‘registered_only’). But for some reason, ‘registered_only’ is never used anywhere…

I use disable comments plugin, which is excellent because it is very simple. Here is the relevant part:
[code lang=”php”]$wpdb->query(‘UPDATE wp_posts
SET comment_status = “closed”, ping_status = “closed”
WHERE DATEDIFF(NOW(), post_date) > ‘ . $days);[/code]

And if you want it to set the comments to registered_only, you only need to change it to:
[code lang=”php”]$wpdb->query(‘UPDATE wp_posts
SET comment_status = “registered_only”, ping_status = “closed”
WHERE DATEDIFF(NOW(), post_date) > ‘ . $days);[/code]

Well… now if only ‘registered only’ did what it was supposed to, you’d be done with it. But as it doesn’t, we need to change some things. They are dependent on the theme you’re using, I’ll use the default theme to illustrate what needs to be changed. First, look into comments.php file for something this:
[code lang=”php”]if (‘open’ == $post->comment_status)[/code]
and change it to:
[code lang=”php”]if (‘open’ == $post->comment_status
|| ‘registered_only’ == $post->comment_status)[/code]
In the default theme, this needed to be changed at two places.

Then there’s one more thing:
[code lang=”php”]if (get_option(‘comment_registration’) && !$user_ID)[/code]
should be changed to:
[code lang=”php”]if ((get_option(‘comment_registration’)
|| (‘registered_only’ == $post->comment_status)) && !$user_ID)[/code]

After that, it pretty much works. You need to have user registration enabled in wordpress, though. Also, while I was at it, I decided to prevent against bots registering. So I installed Sabre. Sabre is nice, but its CAPTCHA rather sucks… well, anyway — more on that in the next post. 8-)

New design again

I didn’t plan it. I just woke up today and knew I’d have a new blog in the evening.

As for colours, a great deal of thinking went into that. Yesterday I read a lot about readability on the web. I think it’s something very important that many people completely miss. First, Verdana and Georgia, that’s a no-brainer. Almost everyone has them and they were designed for screen, are very readable, and also look good.

Then I read some controversial posts about white on black versus black on white. Well, I personally strongly prefer dark background and light text (it’s simply less tiring on the eyes). But somehow my experience from “green is cheesy” with #999 text on #000 background wasn’t good – at least on my system, the fonts didn’t get hinted properly. The “silhouette’s” #CC9 text on #443 background is a completely different story. The contrast is good enough (should be good enough even for people with crappy monitors) and hinting works great (ymmv, though).

As for the picture at the top – the right guy’s back looks kinda weird, I might have to change that. And the curly thingy is stupid, I know. I might change that, too (if anything it should curl outwards, but that would be much harder to do).

And finally: a competishun! Who are the guys in the picture? When was the game played? First to write the correct answer into comments gets a beer. :)


It all started about a year ago, at a go tournament in Blansko, where I played a game called “fujtajblíci”. I enjoyed it a lot, so I thought I could create online version. But as you might know, it is quite a huge leap from thinking about doing something to actually doing it.

Anyway, now I really couldn’t resist anymore… And I thought “fujtajblíci” might be a bit difficult for a lot of people to pronounce or remember, so I rewrote the name as “fuytayblees” (insert fanfares here).

There’s much more info (including the rules, for real) at the fuytayblees site itself, so just visit it, register and start playing. ;-)