Yenya's World

Mon, 28 Jan 2008

FizzBuzz

Pete Zaitcev mentions an interesting programming challenge (read on only if you have several minutes of free time, so that you can try it yourself):

Write on paper, as fast as you can, a program, which prints out the numbers from 1 to 100, but instead of numbers divisible by three it prints "Fizz", instead of numbers divisible by five, it prints "Buzz", and instead of numbers divisible by both 3 and 5 it prints "FizzBuzz".

Pete mentions that even some comp.sci graduates cannot solve this problem. The difficulty of course varies with the programming language used. My own solution in C took me about 3.5 minutes, and the short part of this time I have not been busy writing I spent thinking about a clever way of doing it using conditional expressions in one command, instead of writing the obvious solution.

Anyway, here is the original FizzBuzz article, and there is also a Golf challenge: I am at 60 characters now (in Perl, of course), but they do not accept the command-line switches, so the actual solution has 63 chars instead.

Section: /computers (RSS feed) | Permanent link | 3 writebacks

3 replies for this story:

adelton wrote:

On paper about 30 seconds in Perl. In that Golf, 58 strokes after trying for about 20 minutes. That probably makes Perl my favorite language.

Milan Zamazal wrote:

I wonder when people will finally manage to understand the read/write essence of computer programming. What I miss in the challenge is to put the final code in front of other people and measure how long it takes them to understand what the code does and modify it for a different behavior. *Those* would be interesting results from my point of view.

Yenya wrote: Re: Milan Zamazal

I suppose you are talking about Golf. Well, nobody sane would try to write an information system or an OS kernel Golf style. However, Golf _is_ an important mental exercise, helping both thinking out unusual way of doing things (like factorizing numbers using the s/// command), and getting familiar with not-often-used parts of the language in question. Both writing _and_ reading Golf programs are enlightening (as any other non-trivial mental activity, such as learning Japanese :-). As for the challenge you suggest, there is no simple way of exactly measure the results, and because peoples opinion tend to differ on things like code formating, VariableNaming, etc., the code readability is pretty local in a given project with a given language, coding style, and even code structuring rules.

Reply to this story:

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Comments:
Key image: key image (valid for an hour only)
Key value: (to verify you are not a bot)

Wed, 23 Jan 2008

Port 87

In our cluster, we run various instances of Apache on different ports. When we need another instance, we just add it to all cluster nodes to the next free port. We have started at ports 80 and 443, respectively, and now we use ports up to 88 and 451. And this is where the problem starts:

The Apache instances are usually accessed at port 80 or 443 of the cluster IP address, which is then forwarded by IPVS to the appropriate cluster node and port. However, from time to time we need to access the Apache instance directly. To my big surprise, the URL http://some.cluster.node:87/ does not work in Galeon (altough wget can access it without problem). Galeon says that the server has dropped the connection. It is not true: tcpdump does not show any outgoing packet from my machine to the port 87.

The fix is simple, at least for Galeon: add the following line to your preferences (for my Galeon, it was the ~/.galeon/mozilla/galeon/prefs.js file):

user_pref("network.security.ports.banned.override", "87"); 

Apparently, all other browsers (not only Gecko-based ones) have this behaviour. They just refuse to talk to services running on port 87 (and some other ports like 21, 22, 25, etc.). I wonder how these ports have been chosen, because some other well-known ports like 136-138, and 445, are not on this list.

Section: /computers (RSS feed) | Permanent link | 0 writebacks

0 replies for this story:

Reply to this story:

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Comments:
Key image: key image (valid for an hour only)
Key value: (to verify you are not a bot)

Tue, 22 Jan 2008

Fingerprint Reader

I have got a cheap fingerprint reader (thanks Juraj!) and I have played a bit with it:

UPEK Fingerprint Reader

(image from this digitaltechnews.com article). It is an USB device, and it works surprisingly well with Linux. There is a comprehensive HOWTO available, but I will try to summarize steps needed for Fedora Linux:

So far I think this technology is interesting, even though it is not always 100 % reliable. It is however usable for local logins only. It would be nice if more local apps such as ssh-askpass or Revelation can use it.

Section: /computers (RSS feed) | Permanent link | 7 writebacks

7 replies for this story:

dan wrote: thinkfinger

I have the same fingerprint reader integrated in my notebook (or at least it uses the same driver). It is very addictive to just swipe the finger instead of writing the long password :-). Unfortunately it doesn't work with KDM (i.e. when unlocking the screen, I have to type the password), only with GDM. However I think I've read it will be (or is?) solved in KDE 4, so no big deal.

Vasek Stodulka wrote:

Interesting. With this I should type "su" and use some finger on my leg to login as root. :-)

Honza wrote: IBM TP R60 fingerprint reader

I'm using fingerprint reader integrated to my notebook for more than a year now. Works great with KDM (KDE) and local logins. It took me a couple of days to get used to (position of finger, the length of swipe etc.), but I'm so close to 100% reliability that it is a surprise when it fails. I did not thoroughly tested the other type of error (somebody else being able to log in), but I tested a couple of other people (and other fingers) without any error.

Milan Zamazal wrote:

If I understand it well, such devices don't store the passwords, so they are indeed useful only for local logins in office environments or so. This is not of any benefit to me. What I'd like to have is a password manager (preferably a hardware device) for tons of my remote passwords. I looked recently at several software password managers and unless I've missed something they are all enough inconvenient to use that it is actually easier to remember (and especially to type in) the passwords. Do you know about any tool that can be used for handling remote passwords reasonably?

wrote:

I think it could theoretically be possible to use it for unlocking a local keyring (GNOME Revelation), GPG key, SSH passphrase, etc. Which is close enough to your "remote passwords" requirement, I think.

Spes wrote:

Wow, I tried the Revelation and I like it.

Milan Zamazal wrote:

I can't see any benefit in using a simple fingerprint reader for unlocking local keyrings storing remote passwords. As my fingerprint is not a secret information, I could simply use passwordless keyrings instead.

Reply to this story:

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Comments:
Key image: key image (valid for an hour only)
Key value: (to verify you are not a bot)

Mon, 21 Jan 2008

What Is Luminance?

I have recently enhanced my scanned form recognition software in IS MU to handle not only greyscale scans, but also color ones. It is quite simple - the software converts the image to greyscale in the input phase. During tests, we have found a problematic input file - it has been recognized differently when scanned greyscale than when scanned in full colors. Before reading on, look at the image below and try to decide what number should the software see there:

scanned form

I think the correct output should be the digit "3", with the previous digit being recognized as rubbed out. Now look at the color version. There are three variants there: the first one is the output of the scanner in the color mode, the second one is the color scan converted to greyscale (using GIMP, but convert(1) and ppmtopgm(1) give similar results), and the last variant is the scanner output in the greyscale mode (as seen in the image in this page).

Apparently the conversion to greyscale is not as simple as, for example, averaging the three color channels: (R+G+B)/3. In the ppmtopgm(1) source code they refer to the ITU-R BT.601.5 standard, which states that the luminance value (essentially the grey level of the greyscale version of the image) should be computed using the following formula:

0.2989*R + 0.5866*G + 0.1145*B

I guess the scanner does something simpler than using this formula, which leads to suboptimal results. When the requirements to the recognition software are "it should recognize what human would see in the scanned image", I think it correctly recognizes the greyscale scan as "3", and the color scan as "23".

Section: /computers (RSS feed) | Permanent link | 1 writebacks

1 replies for this story:

dan wrote:

Well, I my guess on the grepscale scan was 23 ;-).

Reply to this story:

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Comments:
Key image: key image (valid for an hour only)
Key value: (to verify you are not a bot)

Thu, 17 Jan 2008

Roomba?

Yesterday's Hyena writes about the robotic vacuum cleaner. I have looked into this (having the flat cleaned when you are away looks tempting :-), but I think I need more references.

So far I have found Roomba robots (they even have a user-programmable version designed for hackers!), and I have read some reviews. There seem to be some problems:

So, my dear lazyweb - do you have Roomba or some other vacuum cleaning robot? Where did you buy it? And would you recommend it?

Section: /personal (RSS feed) | Permanent link | 5 writebacks

5 replies for this story:

Stepan wrote:

I have seen two of those pretty machines in colleague's house in US. As far as I can remember: they're useful on "plain" floors (carpet is in whole room or nowhere). Will try to find out more info..

Vasek Stodulka wrote:

You can currenty buy Electrolux Trilobyte in CZ, but I have no experience with it.

Ondra Krajicek wrote:

Well, I have it :-). My experience is that if you want to perform once-in-a-while cleaning up, this is not the best tool to use. However, for regular use, it's working pretty well. I purchased via irobot.cz without problems. With it, I usually have to use "ordinary" vacuum cleaner once a month or two. PS: Yenya bloguje, husty ;-)).

Yenya wrote: Re: Ondra Krajíček

What frequency do you mean by a "regular use"? Re: PS - welcome in the real world, I am blogging for ~2.5 years now.

Ondra Krajicek wrote: Regular Use

Depends primarily on the kind of floor. I strongly prefer wooden floor to carpets which accumulates dust quite quicky, so Roomba is needed approx. once or twice a week. I have never used it extensively on carpets though.

Reply to this story:

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Comments:
Key image: key image (valid for an hour only)
Key value: (to verify you are not a bot)

Thu, 10 Jan 2008

From PalmOS to Maemo

After Vlasta has left, I have got his Nokia 770 to play with. I am even thinking about replacing my Palm T5 with it eventually, as the synchronization with my desktop has ceased to work in the last few months (the Palm is not visible as an USB device anymore except when in the Drive mode). So far my experience is mixed:

The good thing is that it is has a real OS (Linux). Things like xterm, openssh, screen etc. work, as well as reading plain text files, etc. It also has WiFi and a real WWW browser.

Unlike PalmOS, it has two power-saving modes: in one it has the display and keyboard switched off, but the OS is working. This mode can be entered or left almost instantly. However, in this mode, the battery lasts only for two days or so, even when not doing anything with the device. The other mode is full Linux shutdown, but this takes about 20 seconds to boot the device again.

It is slow. The apps start much longer than in PalmOS. However, it is a true multitasking OS, so the audio playback works even when another CPU-intensive task is running.

It has a RS-MMC slot, which supports 1 GB cards only (2 GB with firmware upgrade), but the device itself has only a 64 MB card, while my Palm has 2 GB SD-card). I use my Palm as an audio player as well, so the available filesystem space is important.

It has a huge repository of software at maemo.org. However, the system userland is not nice - they have several versions of the system image (OS 2005, OS 2006, OS 2007, etc.), and only 2005 and 2006 versions are production-stable on 770. Some apps work only on later systems.

I miss some PalmOS apps, especially PAdict (an excellent Japanese dictionary), and AutoBase (a vehicle usage tracking database). Fortunately, there seems to be a closed-source PalmOS virtual environment for Maemo, which I want to try.

I have yet to find a good PIM application suite with working and easy to use desktop counterpart (as jpilot was for PalmOS PIM). I ahso have to find out how to export the existing PIM data from PalmOS and import it to Maemo.

Overall I think n770 is not a bad device, but has a slightly different purpose than Palm. I will probably try to buy a 2 GB flash card and replace the T5 with it.

Section: /computers (RSS feed) | Permanent link | 2 writebacks

2 replies for this story:

Vasek Sodulka wrote:

I have been running pocket Linux for several years on iPaq, but eventually I switched to back to PalmOS on Zire 72. Palm is faster, smaller, battery lasts longer, the applications are less complicated and it can do everything I want from a pocket device. But Maemo is something completely different from Opie, which I have used, so it may be usable.

Bulik wrote: SD cards

I have had quite big problems with 2GB SD card in my N800, it seems that it has been HW corrupted (maybe it was caused by heavy usage of it as the root filesystem). There is a big number of similar experience on the web therefore I recommend to first read some of them ...

Reply to this story:

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Comments:
Key image: key image (valid for an hour only)
Key value: (to verify you are not a bot)

About:

Yenya's World: Linux and beyond - Yenya's blog.

Links:

RSS feed

Jan "Yenya" Kasprzak

The main page of this blog

Categories:

Archive:

Blog roll:

alphabetically :-)