I recently wanted to get the usage of my CPU in C#. After searching the internet I found a way of doing it using the PerfomanceCounter class. I made a couple of changes and I created the following class, which seems to work.

Using the statement: SystemUtils.getCpuUsage() you should be able to get an integer number showing the CPU usage.

Update: The method described in the following proved to be useless in the summer, when the laptop became too slow (almost unresponsive). I guess setting the CPU Fan Control level to quiet does not work well when the environment temperature is relatively high. So, I removed the fan cover (all you need to do is remove 6 screws on my laptop) and injected some sewing machine oil on the fan! Now the laptop is TOTALLY silent again! Hurrah!

The noise level of the CPU Fan of my Sony Vaio VGN-SZ71E laptop was driving me crazy for the past few days. When the laptop was on, you could hear the fan operating even in the room next door. The fan was also producing vibrations, which I could feel when I had my arms on the keyboard palmrest! It’s needless to say you can’t work properly (i.e. concentrate on your work) under these circumstances.

I tried removing the chassis to see if I can replace the fan, but in order to have access to the CPU fan on this laptop model you need to disassemble pretty much everything! Luckily there is a workaround.

I had installed the Sony VAIO Power Management utilities, which allow me to manage the CPU Fan speed (Control Panel -> Power Options->VAIO Power Managent -> CPU Fan Control ). I set it to level  “1-quiet” and I have to say it is much better now.  Probably this has some impact on the performance, but this comes second to the peace of mind when working 🙂

I recently wanted to redirect the output of Log4j to a JTextPane, so as to output messages to the JTextPane using a different color depending on the severity.

I spent some time searching for information and I quickly put together a small example. The following screenshot shows the output.


The source code is available here.

Kaspersky antivirus and comondo firewall have rendered my windows 2000 laptop to be very slow. So I decided to give it a try with linux.

My set-up: A Toshiba 2450-S203 laptop (P4@2.8), an nvidia video card (don’t remember the details of the chip) and a wireless pcmcia linksys WPC11 version 4.

My experiences:

Mepis 6.5

First I tried Mepis 6.5. It worked very well out of the box and the wireless card connected to our router without a problem. However since Mepis 6.5 is based on an older version of ubuntu its repository has reaaaaly old versions of software. This was a problem and since Mepis 7.0 is coming out, I decided to try version 7.0 RC2.

Mepis 7.0RC2

Installed well, but I couldn’t make the wireless card work. I sent a post to the mepislovers forum and received a number of useful answers. It could be the version ndiswrapper that comes with Mepis 7, or the driver. So I had to either download the latest source code of ndiswrapper and compile it, or try different version… Too much work for a RC version.

Kubuntu 7.1

As I have been a windows user, I decide to go for another kde distribution, kubuntu. The installation went smoothly. However I couldn’t connect the wireless card to our router. Kubuntu would recognise it, but as soon as I tried to connect to the router… kernel panic! The caps lock light flashed and the system was unresponsive. I tried to blacklist the native drivers and use ndiswrapper with my windows drivers… but to install ndiswrapper it asked for the installation cd! (Even though I was already connected to the internet with my ethernet cable).

I managed to make it word with ndiswrapper and the system was quite stable. So, now let’s try ubuntu for a change…

Ubuntu 7.1

As expected I had the same problem with the wireless card and  resolved it using ndiswrapper again. I have to confess that I liked the interface better than KDE. It was quite fast and stable. The problem is that I need windows anyway (some .NET development, software which don’t have a linux version) . I can use virtualization (vmware) to run windows from within linux, but to do that I need more hard disk space and probably I will need again the firewall and antivirus installed.

The verdict?? I might try to switch to linux after I finish writing up, but right now I don’t have the time, resources (i.e. hard disk space) to do it properly. However there are some things I didn’t like. First of all in (k)ubuntu, when the native wireless card drivers crashed, NOTHING was logged in the log files, no warning, no nothing (at least a windows blue screen gives you a message with the address/module that caused the crash.).  The other annoying thing… why do you need the installation cd if you are already on the internet and the package manager can find the binaries on the internet?

I mean ok… you blaim windows for the blue screens of death, you blaim them for asking the installation cd all the time… so people say switch to linux (or get a mac).. you switch to linux and see things are not much better there.

Having said that I hope that some day I will have the time to be actively involved in a linux distro.

As I was searching for something on google, I saw an ad at the bottom of the page. The ad was about the Davinci code new movie that is coming out. I clicked and found a sudoku like puzzle, related to the movie. The puzzle is explained in the following two pictures (description can also be found on: http://student-rant.blogspot.com/2006/04/googles-da-vinci-code-quest-1.html)

Well… it is clearly a very simple problem for a constraint solver, like Alloy Analyzer! I created the following model (took me half an hour, so no comments or too much thought about it).

Alloy Analyzer came up with a solution in 3 seconds, on the dual core 2GB RAM opteron server running linux!

The solution is the following one:

symbol= { (Cell_0 Blade_0) (Cell_1 Blade_0) (Cell_2 Blade_0) (Cell_3 Blade_0) (Cell_4 Fi_0) (Cell_5 Fi_0) (Cell_6 Fi_0) (Cell_7 Fi_0) (Cell_8 Cross_0) (Cell_9 Cross_0) (Cell_10 Cross_0) (Cell_11 Cross_0) (Cell_12 Star_0) (Cell_13 Star_0) (Cell_14 Star_0) (Cell_15 Star_0) }

rowIndex = { (Cell_0 One_0) (Cell_1 Two_0) (Cell_2 Three_0) (Cell_3 Four_0) (Cell_4 One_0) (Cell_5 Two_0) (Cell_6 Three_0) (Cell_7 Four_0) (Cell_8 One_0) (Cell_9 Two_0) (Cell_10 Three_0) (Cell_11 Four_0) (Cell_12 One_0) (Cell_13 Two_0) (Cell_14 Three_0) (Cell_15 Four_0) }

columnIndex = { (Cell_0 One_0) (Cell_1 Four_0) (Cell_2 Three_0) (Cell_3 Two_0) (Cell_4 Four_0) (Cell_5 Three_0) (Cell_6 Two_0) (Cell_7 One_0) (Cell_8 Three_0) (Cell_9 Two_0) (Cell_10 One_0) (Cell_11 Four_0) (Cell_12 Two_0) (Cell_13 One_0) (Cell_14 Four_0) (Cell_15 Three_0) }

It is quite straightforward! The symbol of Cell_0 is Blade, its row is One and column One. The symbol of Cell_1 is Blade again, he row is Two and Column Four etc.

The symbol names are not related to the movie or book symbol names. In my model Blade is the pyramid like shape, Fi is the Greek letter fi, Cross is the symbol that looks like a cross and Star is the symbol that looks like a star. I know that I spent half an hour to solve a problem that would have taken me around 10 minutes to solve manually, but as a proper nerd I prefer to use my (few) grey cells to think how to use a computer to solve a problem for me, instead of solving the problem myself.

Well.. that’s it! I don’t want to spend more than 1 hour on this!

There are a couple of blogs with solutions to the puzzles.
Links to solutions:

UPDATE: I used the model on my P4 running @ 2.8G with 712 MB ram and took AA 23 seconds to solve the problem. Not bad at all! But for bigger problems the state space will be increased by too much. Looks like an AI technique should be used to find a solution.