Tuesday, 12 December 2006

Gerrold, David - The Martian Child

Wee! I've received a PDA from my bestest of uncles (which will soon work for Google and I am so proud of him). Ok, back to adult mode. I've used the newly acquired PDA to read books! I've started Metamorphosis by Kafka, but the file was incomplete by accident, so I ended up reading The Martian Child.
It's a small text, 80KB in length, and it's not really sci-fi, but it's nice. It's the kind of warm, easy to read text suited for bus rides. It involves a sci-fi writer adopting a child who says he is a Martian. During the entire text, the author struggles with the eerie feeling that the child was actually right, even if there is no way to prove it.
It was nice enough.

Thursday, 7 December 2006

InvalidCastException error in an ASP.NET 2.0

Sometimes, when you use ASP.Net 2.0 with MasterPages, UserControls and dynamic loading like LoadControl, you get a silly error: Unable to cast object of type 'X' to type 'X' where X=X. Of course, it is a versioning problem. Some of these errors appear in the VS2005 designer, when the designer uses an older version of a library, but also when trying to open the web page in a browser.

Microsoft has released a fix for this: http://support.microsoft.com/kb/915782 , but, to quote the same source: "This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft .NET Framework 2.0 service pack that contains this hotfix.". So you risk screwing things up.

The issue seems to be mostly a developer problem. That means that during programming, you get this error when you keep changing stuff in the project. A client might get this error if an update of the site created this problem. The iisreset utility won't work. Recompiling locally and reupdating the site usually solves the issue.

Monday, 4 December 2006

The most efficient way of getting rid of security issues: jail hackers for ridiculous amounts of time!

Another suspected NASA hacker indicted tells the story of a Romanian hacker who entered 150 NASA computers, then made them display messages boasting the hack. Of course, the US government immediately took initiative and fixed all their computer security holes, suing the corporations that made the buggy software sued the Romanian hacker for "conspiracy and nine counts of computer intrusion", mounting up to 54 years in prison, if found guilty on all charges. I won't even go there. It is just ridiculous. A few years ago, an American soldier killed a man in a traffic accident and he was immediately flown back to the States, where they found him guilty of a misdemeanour and he didn't even do jail time. Read again he KILLED a man.

But there is also some justice in the world: U.S. marine sentenced to 40 years for rape in Philippines. Now, of course, the poor guy didn't do anything as serious as hacking into a computer and boasting that he did it, so he gets only 40 years.

Bush in Space, part 2.

A couple of weeks ago I posted this: Bush in Space. Now I come back with a few nice articles that show what the future of space is likely to be. Or not to be.

First of all, a news article from May 2006 US seeks laser to shoot down satellites talks about a "secret" U.S. project that uses lasers to shoot down "enemy" satellites. Considering the ability of most nations to put satellites in orbit, I can only conclude that they mean Chinese, Indian, Japanese, Russian or European satellites. Probably, the Chinese thought the same thing, and here is where this article: China Attempted To Blind U.S. Satellites With Laser comes in. It talks about the Chinese trying to shoot down (or at least blind them considerably) U.S. satellites spying on them. This story was "dug" here. You can see in the article that the US already plan for a "constellation" of satellites to replace the vulnerable spy satallites they already have in place.

Now, most comments on this are usually either moronically nationalistic, either uselessly anti-American. However, there are people that have actually put thought into this. How come the US is augmenting this "Cold War" with China, when they have such a lucrative economic bond. Is it because they see a more business oriented (read democratic) China as a more maleable one? A good consumer market just ripe for the US culture? Or is it because they actually fear a democratic China, as a very serious competitor. Most analysts observe that placing and defending stuff in space is way harder than destroying stuff in space. Even lasers work in space, but low tech solutions like plain old rubble would work just as well. This is described as asymmetric warfare. When even the little guy can fight back.

But what does all this mean? The US have all but openly dismissed the ISS. The only science projects that they do on the station are related to the human habitation of space, which leads me to believe they either plan on colonising the Moon or even Mars (a man can hope) or they just don't care about space any more than their precious spy satellites. How does the entire "teritory" concept work in space? How can you attack in space and not get into a ground war at the same time? These are questions about things one might think do not affect us, but they do. From weather to global positioning, from TV to the Internetand the telephone, they all come through space. You have to imagine a world where space wars are common and plan ahead against it. We cannot color the sky, we can't afford to.

Wednesday, 29 November 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, 28 November 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:
INTERESTING
INFORMATIVE

Step 1: remove all identical overlapping characters (sift)
TEESNG
FOMAVE

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
TEESNG
[]FOMAVE

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

Step 3: return result
MaxLength(TEESNG, FOMAVE)=6

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, 27 November 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

Details:
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
bw.RunWorkerAsync(obj);
The DoWork method should do something like
e.Result=BackgroundOperation(obj);
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.