Wednesday, February 17, 2010

Scala "puzzler"

November 2008 I encountered Scala and started looking into it. Thinking that some of my friends, who are also in the IT business, would be interested in hearing about my experiences I started writing them a series of mails with some of the things I learned. Mu idea is to publish them on this blog, translating them to English at the same time so it can reach a broader public.


Yesterday I bought the book "Programming in Scala" and I'm reading it at my leisure. And only a moment ago I encountered a warning that made me think "argh, why did they do that?".

It turns out there are 2 ways to define a function/method in Scala, one goes like this:

def multiply(x : Int, y : Int) = { x * y }

and the other one like this:

def multiply(x : Int, y : Int) { x * y }

the first one has 2 integer arguments and because of Scala's "type inference" it will also return an integer. This is something you don't have to specify yourself (you could do so and it would look like this def multiply(x : Int, y : Int) : Int but that's not important right now). The 2nd form also has 2 integer arguments, but because we left out the =-sign the result of this method is always "Unit" (like "void" in Java). In other words, the result of the expression will be thrown away quietly.

I think this is one of those things that can really bug you for hours without being able to figure out what is going wrong exactly. It seems like an unnecessary "shortcut", I would have preferred to explicitly define the result as being of type Unit in the case I really wanted to throw away the result.

Monday, February 15, 2010

Notion Ink´s Adam tablet

I've just watched this video and I must say: color me impressed! When you read the comparison with Apple's iPad you'll see that Apple will have a difficult time convincing people that their product is really worth the price they're asking for it. I mean, this Adam thing actually has all that you would expect in a product like this: regular USB ports, HDMI output and even a swivel around camera. Overall a really nice job, let's see if they can pull it off. They're supposed to come out in june so Apple willl have a 2 month head start.

Linux sound problems

Original post date: Fri Sep 07 12:00:00 2007
Ok, just learned that having two sound cards in your system can lead to all kinds of trouble.
Some time ago I had bought some headphones from Altec Lansing that came with an USB adapter. Not expecting it to work in Linux I plugged it in, but lo and behold it actually worked and I had now two sound cards in my system according to Fedora's Soundcard Detection utility. So far so good.
Soon after I removed the USB module and just connected the headphones directly like I had always done and life was perfect.
Until quite some time later I had to reboot my machine and suddenly I was getting all these weird ALSA errors from all kinds of programs (see for example the image of the pop-up that appeared at KDE startup).


The strange thing was that the Soundcard Detection program reported everything okay, the right sound card was detected, I could hear the sample and on top of that several programs did actually produce sound. So what was going on here?
Finally today I got a hint trying to run alsamixer when it gave me the following error:
alsamixer: function snd_ctl_open failed for default: No such device
Now this was something I could google for. So I ended up with several leads of which two led to the final solution:
  • ALSA user list which didn't really have a direct solution for my problem, but it made me look at the modules where I foundsnd-usb-audio. So what was that doing there when I had removed that USB adapter ages ago? Of course/etc/modprobe.conf was the "culprit" here. Somehow plugging in the USB adapter had inserted some lines into the file but removing the adapter hadn't deleted them!
  • LinuxQuestions.org pointed me to some files I had never heard off: /etc/asound.state and /etc/asound.conf. The first didn't seem too interesting, but the second had things like card numbers which made me think that maybe they had gotten mixed up somehow because for a short time I had two sound cards in my system. So I removed both and restarted the Soundcard Detection program. And like I had imagined the numbers were different in the new asound.conf!
So everything seems to work again. Now to figure out why the microphone only picks up sounds very faintly.

Linus and Windows

Original post date: Mon May 07 12:00:00 2007
Well, at least we know now how Linus feels about Windows:

I'm not claiming that the current code cannot work. It clearly *does* work for a lot of people. But I'm claiming that it's STUPID. So don't argue that "it works". Windows works, kind of. That doesn't make it less stupid and badly designed!

Poetic Linus

Original post date: Thu Nov 30 12:00:00 2006
Linus must have been in one of his poetic moods again ;-)


It's one of those rare 'perfect' kernels. So if it doesn't happen to compile with your config (or it does compile, but then does unspeakable acts of perversion with your pet dachshund), you can rest easy knowing that it's all your own d*mn fault, and you should just fix your evil ways.

Sunday, February 14, 2010

Slow HD due to CD polling

Original post date: Sat Nov 04 12:00:00 2006
Yesterday I upgraded our Dell Latitude to FC6, it was running FC4 and it was getting difficult to encounter some of the packages that I use on the desktop system (like Twinkle for example).
Well I can tell you that the installation went a whole lot better compared to the problems I had with the desktop machine!
There was just one thing that bothered me. Where the desktop actually seemed faster (as it was supposed to according to this, see the Performance section) the latop felt sluggish somehow. Applications were taking too long to load. When I tried measuring the drive's performance I got this:

which is way too slow for that drive. Then I remembered that I had the same problem before with this laptop and it was because of the polling KDED did of the CD rom drive (to detect media changes and such). Stopping KDED (which you can do in the KDE Control Center -> KDE Components -> Service Manager) would solve the problem.But with FC6 this didn't seem to help. I found an option called Enable CD polling in the Peripherals -> Storage Media of the Control Center, but the option was grayed out so I couldn't change it.
I finally found out today that it is HAL which does the polling nowadays, specifically the hald-addon-storage module. Killing it restored the expected performance:

So now it was time to figure out if something could be done about it. According to to this forum message it is a known problem with Dell laptops but it seems that the blacklisting it talks about doesn't work (anymore) in FC6.In the end I found out that HAL uses a set of rules to determine what to do with certain hardware which are stored in/usr/share/hal/fdi. By doing a lshal I could get a list of all the detected devices and find the information about the particular CD drive used in the laptop:

Using the information above I created my own fdi file information/30private/10-crappy-dell-cddrive.fdi with the following rules:



service haldaemon restart) everything was back to normal. Of course the system won't automatically detect any CDs being inserted into the drive, but I can live with that. (And yes, of course I filed a bug report)

Switching between Java versions

Original post date: Fri Jun 01 12:00:00 2007
It was always possible of course to install several Java versions on the same system, but switching from one to another has always been a bit of a nuisance. In Windows I started using batch files that I wrote specifically for the purpose of setting PATH and JAVA_HOME variables while for Linux Fedora you can use the alternatives command.
But I just found out that newer Java versions actually support switching versions directly from the command line:

 java -version:1.5+ ...
  
will require that the code is run with a VM of at least version 1.5 while:

 java -version:1.6* ...
  
will use any version 1.6 VM (so it won't accept 1.5 nor 1.7, but it will accept 1.6u1). Requiring a specific version of the VM is supported but is not recommended because it would tie you to that very VM not even allowing the use of VMs that have important bug or security fixes.Specifying a VM that can not be found on the system will result in an error of course:

 > java -version:1.4* -version
 Unable to locate JRE meeting specification "1.4*"