Wednesday, November 29, 2006

Kafka on the Shore, by Harumi Murakami

I've just finished reading this book, in Romanian translation, and I found it nicely written, but not exactly my type of book. For me, art needs to draw you into atmosphere and conclusions, not to be understood only if you make the effort to draw the conclusions yourself. Yes, I am lazy, but don't get me wrong, I like art. It's just that art is supposed to communicate. I may recite a beautiful poem in Romanian, but if my audience is English, it wouldn't do any good.
So my review on this book is as follows: it is well written, freely written (I can sense throughout the book that Murakami has an open mind, not clogged by clichees and prejudice), it draws you into the atmosphere. But there is where it stops. I know there are deeper meanings in the things that happen throughout the book, but they are not properly explained. I can draw beautiful conclusions and see very deep things, but it would be my merit for making the effort and looking deep, not the writer's. And I wouldn't be sure that it's what the writer intended telling in the first place.
Read it if you are into atmospheric books :D and if you like dark, philosophical discussions.

Tuesday, November 28, 2006

Fast String Distance (SIFT) Algorithm

This article is obsolete, a better version of the algorithm has been published: Sift3

While researching different ways of measuring the distance between two strings, or how different they are, I've found of course the Levenstein algorithm. The problem with it is that it is slow. Searching more, I've seen some algorithms that seemed fast, but I didn't have the time or brain power to understand them. So I've devised my own algorithm, called SIFT. You might think the name comes from Siderite's Intelligent and Fast Technique, but it comes from the English word 'sift'. :)
How does it work? Well, the common scenario in comparing strings is that someone made a mistake, a typo. So in principle, the two strings should be very similar in order to be worth comparing them. So what I do is this:

foreach phase
remove identical overlapping characters
shake strings
return number of shakes + the length of the longest string between the two.

There is an optimisation towards the safe side: if the sift similarity is big enough, perform the constly Levenstein distance.

Ok, it might not be so clear, let's take an example:

Step 1: remove all identical overlapping characters (sift)

Now we have smaller words to check, let's suppose there was a typo, that means that part of the one word is offset with one or maybe two characters from the other. So we move them a bit, that's a 'shake'.

Step 2: shake

Oops, no overlapping characters. We do this one or two times more and there is no result, so...

Step 3: return result

There you have it. The sifting algorithm, because it resembles sifting grain.

Not satisfied with such a simple example? Let's take another:
Click here

Tests have shown it to be pretty close to Levenstein, at least in the cases that matter, while being substantially faster.

Monday, November 27, 2006

Running processes in background

Long story short: the BackgroundWorker object. Available in .NET 2.0
This is a Microsoft tutorial on using BackgroundWorker:
How to: Run an Operation in the Background
This is an older and more Windows Forms basic tutorial on multithreading:
Safe, Simple Multithreading in Windows Forms, Part 1
Safe, Simple Multithreading in Windows Forms, Part 2

BackgroundWorker has the DoWork, ProgressChanged, RunWorkerCompleted, and Disposed events. You need to assign at least one method for DoWork and one for RunWorkerCompleted, then run
The DoWork method should do something like
while the RunWorkerCompleted method should do anything related to the GUI. There is also a CancelAsync() method, to try to stop a background operation.

Also, here is an article about a possible bug in BackgroundWorker, but I haven't replicated it on my computer.

Thursday, November 23, 2006

I'm a dink!

According to Wikipedia, dink, can mean a lot of things, ranging from small boats to small penises. A dink is also a creature in the SpaceBalls parody of Star Wars. But is seems that the main use of this word right now is for "Double Income No Kids". That's me! Well, I have a cat, but he doesn't generate any income. You can also find this particular demographic group called DINKY, which is a more dynamic acronym that takes into the consideration the future possibility of offspring(Y=yet). The Americans seem to prefer Dink, while the UK and their former colonies Dinky.

Apparently being a dink means that one is part of a high-earning couple who choose not to have children and are therefore able to afford a more expensive consumer lifestyle. A dink is considered a lot of times as being also a yuppie, or Young Urban Professional, with pejorative connotations of selfishness, materialism, and superficiality.

So, apparently, I should :

  • generate an income (checked)

  • have a mate (checked)

  • the mate should also generate income (checked)

  • both generated incomes should be high (yeah, right)

  • selfish (checked)

  • materialist (not really)

  • superficial (yes!)

So, I have demonstrated creating by oneself a Cosmopolitan test by using Wikipedia. Are you a dink? How dinky are you? Take the test! :D

Wednesday, November 22, 2006

Building a GridView, DataGrid or Table with THEAD, TBODY or TFOOT sections

There are 726 articles on Google when you search "gridview thead". Most of them, and certainly all the first ones, talk about not being able to render thead, tbody and tfoot elements for NET 2.0 table based controls. But it's not so!

Each table row has a property called TableSection. If you set it to TableRowSection.TableHeader, TableBody or TableFooter, the specific tags will be created. Let me show a quick example of creating a THEAD element in a gridview:

And that's it. This kind of behaviour works for the Table WebControl and everything that derives from it or uses it to render itself.
However, the rendering of these elements inside the Table control is done simply with writer.RenderBeginTag(HtmlTextWriterTag.Thead), which gives no one the ability to change from .NET code the attributes of those sections. You can't have it all! You can use CSS, though. ex:
.tableClass thead {

The Marsians are attacking!

In 2001, July, a strange phenomenon in the form of red rain occured in southern India. While the official explanation of this is that desert dust has been brought by winds and brought down by rain, Dr. Godfrey Louis, a proffesor of physics for the Cochin University of Science and Technology thinks otherwise: it's all about alien microbes that arrived here by riding a comet.

The story might seem a bit far fetched, but even BBC News wrote about it. And this guy released a science paper about it after what appears to be five years of study. Take a minute to read it, it's only 18 pages long. What seems odd to me is that, even if he maintains that the red rain particles are biological in nature, he doesn't mention anything about reproduction, nor of any attempt to revive them.

Anyway, it seemed interesting enough to blog about it. There is a more down to Earth and detailed article about it in Wikipedia. You can also find here is the transcript of a news report together with animations that talks about Cardiff University scientists confirming the presence of some sort of DNA in the seemlessly devoid of nucleus cells.

Monday, November 20, 2006

Multiple IE versions on the same computer

Usually, when I decide to blog on something, I do the testing and researching and installing first, then blog about it. But now I intend to use this cool site:
which boasts with installing all IE versions since 3.0 (oh, beloved 3.0) on the same computer without any problems. Since I am not a trusty guy, I blog about it before, then, if no one ever hears from me again, it means that no browser on any computer worked anymore after this :)

Well, without further due, let me proceed :-SS
Extra info:

Step 1: Installing IE7.
Of course I had to validate my copy of Windows to download it, then I had to download all updates (even if I went to Windows Update right before installing IE7), then wait until it searched my computer for malicious software, then installing everything. You can't imagine a smoother installer. It just tells you to wait and does everything in the background, showing you meaningless text labels, a cool progress bar and, of course, asking you to close everything before and restart Windows after the installation.
But it worked, and I am not writing this from Firefox :)

Step 2: Installing multiple-ie-setup.exe
Wow! It took around 1 minute to install everything. Of course, not everything is going as smoothly as planned. First of all, I can't see Blogger (and suposedly not any other cookie using site) in IE6.0. Then, it redirects me to a nocookies.html files that doesn't exist :-/ But that's a Blogger issue. The Options menu in IE6.0 is actually the IE7.0 menu and the settings for cookies cannot be overriden. Actually, you can, but the settings won't save.
After looking at the TrendoSoft site, I've noticed that this bug is considered solved, even if some of the people seem to continue to have problems. So I've tested more throughly. Session variables seems to be saved, but Blogger continues to take me to the nocookies page. Also, AjaxPro, the ajax library I am using, doesn't seem to work with IE 6.0.

All in all it seems a pretty functional program. However, the type of sites that I am building have certain characteristics that seem not to work with it. I will try to log on TrendoSoft and get the problem fixed, but I guess Yousif did the best he could so far and resolving every issue I have will be hard if not impossible.

Tuesday, November 07, 2006

TransactionScope in .NET

Amirthalingam Prasanna's article about the transactional model in NET 2.0.

As far as I understand, the old declarative ADO.NET Begin/RollBack/CommitTransaction model has become obsolete and a new TransactionScope model is used in NET 2.0. You have to add the System.Transactions.dll file to your references.

Basically, the C# code is like this:

using (TransactionScope scope=new TransactionScope
(scopeOption,transactionOptions,interopOption)) {
// do database ops

// if everything is alright

scopeOption is an enum of type TransactionScopeOption, with the options Required (requires a transaction and uses if there is already on open), RequiresNew (always opens a new transaction), Suppress (don't use a transaction, even if one is open)

transactionOptions is of type TransactionOptions which has two interesting properties: IsolationLevel and Timeout.

interopOption is an enum of type EnterpriseServicesInteropOption and specifies how distributed transactions interact with COM+ transactions.

But what about the old NET1.1 framework? Doesn't it have something like that? Here comes Alexander Shirshov with help:
TransactionScope in .NET 1.1

.NET Framework 3.0 has been released!

Release announcement

NET 3.0 is NOT working on dotNET 3.0 or C# 3.0. It's just the old Windows Communication Foundation, Windows Presentation Foundation, Windows Workflow Foundation and Windows Cardspace into one package.

It is optimised and designed mostly for Windows Vista though and be sure you uninstall any CTP versions before installing this one.

The online documentation for the Windows SDK for Vista RC1 and the .NET Framework 3.0 is also now available.Here are the direct links to the documentation for the .NET Framework 3.0 technologies:

Thursday, November 02, 2006