Gödel, Escher, Bach by Douglas Hofstadter has won a Pulitzer Prize and I believe it is the only thing that ever made me want to read other Pulitzer Prize books. I have to thank Meaflux for pointing me to this book and if he ever writes anything in his blog, you can find it here. Anyway, here is my humble review:

I have just finished reading the book and, in its self-referential spirit, I am also starting reading it. A strange loop of sorts, when starting to read a book follows finishing it. It is not an easy read, but it is certainly worth it. I was instantly both in awe and full of envy on this Hofstadter guy that I have never even heard about before.

What is the book about? I believe the most basic answer is it is about the roots of consciousness, and before you run away thinking this is some sort of new age pseudo (or fully) religious crap, let me assure you it is not. The title itself shows the perspective one gains by reading it: look at the same thing from the viewpoints of a mathematician (meta-mathematician, at that), an abstract painter and a great music composer. It's a definition of abstract thought by intersecting the works of three great abstract thinkers. But it is more than that.

The most intriguing part of the book it is how self referential it is. There are portions in the book that are modeled after Bach fugues while paraphrasing Escher drawings in order to illustrate a mathematical idea of Gödel. It talks about artificial intelligence, consciousness, the workings of the brain, formal systems, computer programming, music, art, science, mathematics, quantum mechanics, biology, genetics and does so in a way that links all these things together in a reasonably easy to understand way. It does not feel like a book made out of separate chapters, but one master-single-piece linked to itself in the most imaginative and twisted ways.

I urge you to buy the book, if you find it. I have read a text OCR version of it and I know I missed a lot. If you can't afford it, there it a torrent on the net with the PDF scanned version as well as the music, paintings and other media the book talks about.

The bottom line is that it is an amazing book. For someone like me, a software programmer dreaming of AI, it was a shame I didn't read it before. I almost believe that you will see me in buses like those old ladies reading the Bible, only with GEB in hand. I can't imagine anyone over 15 years of age that shouldn't read this book. I doubt anyone under 15 can truly comprehend it and, as Frank Herbert's Dune, it must be read every 10 years or less, just to see how much more you can understand from it.

Update: I found on the Internet a full length movie based on Hofstadter's ideas. Interesting, in a geeky/goofy kind of way. Here it is: Victim of the Brain.

and has 1 comment
A while ago I bought this LaCie 500Gb external hard drive and I was rather satisfied with it. With the occasion of the horrible Easter holidays I finally turned off my computer (after weeks of it working continuously). So imagine my dismay when I came back home, turned the LaCie on, then the computer and all I had to show for it was an USB mass storage controller error in the Hardware Manager.

After trying a few things (and noticing that the hard drive would not actually turn on, instead a tick-tock sound was heard from inside) I decided to open up the drive box, proudly written on it "Designed by F. A. Porsche". Well, fuck you, Porsche! I had to almost destroy the box to open it, then the insides had so many "one installation, no after service" components that I felt like walking on broken glass.

Anyway, inside the LaCie there is a small USB controller and an SATA Seagate Barracuda 7200.10 hard drive. I installed the hard drive as an internal drive and... nothing! Windows XP blue screen 0x0000007B. The computer wouldn't even recognize the drive in the boot up screen.

Well, after looking for drivers and stuff like that, I was resolved that the hard drive was defective and all my music, movies and books were lost. But shutting the computer down I noticed that the drive was actually spinning in its internal setup configuration. So, desperately, I tried to use the power from the internal computer power source and the rest of the drive in its USB setup... and IT WORKED!

Now I am going to buy another drive and get all data from this one, but still, if you are desperate that your USB hard drive is lost, try to open it up and power the internal drive with a normal computer power chord.

As for why the internal drive did not work directly on the computer? I have almost no idea. The Seagate site says clearly that SATA drives do not require drivers, but the various SATA controllers do! Since I already have a SATA internal drive, I think that that is not the issue. Rather, the people at LaCie used another drive firmware! The Seagate drive also provides with some downloadable firmware so it is clearly possible. As a completely desperate option to recover your lost data, I guess trying to rewrite the hard drive firmware could work, but I don't recommend it and I wonder how it is possible, considering it wouldn't allow me to boot Windows.

I hope this helps somebody. And Happy Easter everybody!

Update September 2012: after three years and a half, the drive (powered by both USB and internal computer power) started to develop bad sectors. It still works, mind you, I just removed it because I didn't need it as much. Thus ends the saga of the mutant harddrive in the computer that never sleeps and never dies [creepy music in the background] :)

and has 0 comments
While working on RegexConverter I've started learning things about XML. I disliked it before, but now... I loathe it completely. It feels like the XML people are from another planet and I have to twist my brain at straight angles just to understand what they meant.

One of the problems I met was "how to declare in an XML schema a unique constraint/index on the entire document when there are nested elements of the same type". In other words, something like this:
<regex>
<group index="1">
<group index="2">
</group>
<group index="3">
</group>
</group>


Bottom line:
  1. Use the declared namespace
  2. Declare the index in the root element
  3. Use the name of the nested element (in my case group) in the selector
  4. Use the one or more levels deep selector (.//)
  5. Use the declared namespace AGAIN.
.

Concrete example:
<xs:element name="regex" type="regexType">
<xs:unique name="uniqueIndex">
<xs:selector xpath="mstns:group|.//mstns:group"></xs:selector>
<xs:field xpath="@index"></xs:field>
</xs:unique>
</xs:element>


I tried to solve this for two hours only to find the solution was this idiotic. Neither one of "group","mstns:group","mstns:group|.//group" work. The only one is "mstns:group|.//mstns:group".

Grrrr...

Update: two more days of work and a huge text file of regular expressions and I know a lot more about the syntax of .Net Regex than even MSDN :)
The third (Apr11) release of the library has a huge load of bug fixes and new features and it is now... [Tadaaaaa]... a stable version. At least I think of it that way :) Go download it.!

I've been working for two days on an idea. What can I do to make those long regular expressions that I always leave in my code more readable and easy to understand without having to compile automatons in your head?

I have first researched on Google regular expression converters. Nothing was even close to what I wanted. Also, on the more scientific side, people were talking a lot about BNFs, as a superset of regular expression syntax. I looked at BNF. Yes, it describes anything in a human readable form, it is used in RFCs but I hate it even more than XML! So XML it is. Most of the inspiration for the code came from this link: Regular expressions and regular grammars

I give you, RegexConverter. It is a library+demo that transforms a Regex into an XML and then back again. The demo application demonstrates (duh!) this by having two panes, one in which to write regex and the other in which to write XML. Changing one, also changes the other. It warns you of errors in both Regex, RegexConverter and then checks if what it got can be safely converted into your changed string!

Please tell me what you think. I believe it can be a real help in understanding regular expressions, some specific ones or regular expression syntax in general, whether one is a pro or a complete noob.

I've worked hard to design the library source in a way that is understandable, I also added comments everywhere. I tried to implement all the specifications of .NET regular expressions from the MSDN site so if you have a regex that is valid but can't be turned into XML or the conversion is not perfect, let me know.

The link is: RegexConverter on Github.

I will update this post with more science and links to my places of inspiration for this, so stay tuned.

Update: Ok, so I haven't updated this post much. Shame on me. I was reminded of this project when I got an email from the FamousWhy site which said RegexConverter "has been granted the Famous Software Award". I know it's probably an automatically generated message and went to many or all of the Codeplex people, but still: automated attention is still attention :)

and has 0 comments
Just a small mention of a thing I've learned today: what is the FullName of a Type of a class that is nested into another?

Usually, you would use it inside Visual Studio as ParentClass.ChildClass, but if you ever want to use the full name of the ChildClass Type (as when declaring it in web.config) you have to separate them with the + (plus) sign.

So let's assume you have this MyHandler class in the MyNamespace namespace which has a nested class Configuration in it. In the code you do a
var conf = new MyNamespace.MyHandler.Configuration();
while when using the handler type name to declare it in web.config you do it like this:
type="MyNamespace.MyHandler+Configuration"
.

First off, I have to say something about forums: stop copying content from one another, jerks!. I have been trying to find a solution for this problem and I found a zillion forum pages with the same "problems" and the same "solutions" again and again and again!

Much better! Now, I have been trying for an hour to understand why setting customErrors="Off" in the web.config of my ASP.Net application would not work. I tried just about anything, including the bloody forums. customErrors Off did not work!.

In the end I found one little comment for a StackOverflow question: set the retail setting in the machine.config file to "false"!! So, go to %WINDOWS%\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config and set retail to false!. Setting it to true means it will NEVER show you any useful debugging message.

A while ago I wrote a post detailing a fix for Very slow UpdatePanel refresh when containing big ListBoxes of DropDownLists. I have restructured the fix into a ControlAdapter and placed it on Github.

Enjoy!

and has 0 comments
Today Internet Explorer 8 appeared to me in the Automatic Updates list. I have been using IE8 for months now and so I was glad that the official release finally came out. So I downloaded and installed IE8.

The installation process has several steps. First is the removal of any previous version of IE, then a reboot, then several small steps of the setup program: Downloading IE8, Downloading IE8 updates, Installing IE8, Installing updates, Finishing installation. Well, for me, at the Installing updates step it threw an error that said the installation cannot complete because the station is shutting down, then my computer restarted.

I did have Internet Explorer available, though, so I tried a few pages. After the pages loaded, I was invariably getting an error and IE closed. "Internet Explorer has encountered a problem and needs to close. We are sorry for the inconvenience.". Well, so was I!

I was trying the installation of IE the third time now and suddenly a Java update traybar icon appeared. I updated Java, then I was amazed to see that IE was no longer crashing! So, my solution for Microsoft IE errors: update Sun Java! :)

Well, the Java update probably completed some steps that the installer failed to. But still :)

And interesting link I found regarding any IE error that causes the browser to excuse itself and leave is on Sandi's Site

I've gathered the strength to defeat my laziness and put another of my projects on Github. I am talking about the Sift3 algorithm, described here.

The URL for the project is https://github.com/Siderite/Sift3/ where you can download the library and sources in .Net 3.5 C#. A class that also implements Levenstein and Length string distance algorithms is provided.

Please let me know if you are interested in the project, have any suggestions or are even using the algorithm in your projects.

This error can happen in several situations. One of them is when you are trying to access a web service, another is when trying to call a classic asp page. Most of the time, this happens in situations related to URL rewriting. It may happen in Windows XP or Windows 2000, on IIS 5.0 or IIS 5.1.

Well, first of all, in order to do URL rewriting you need to make ASP.Net process ALL URLs, not only .aspx pages. To do that in IIS5, you need to go to the ISAPI extensions and add a new one for '*' that maps to the ASP.Net dll (aspnet_isapi.dll). This process is detailed in this Microsoft page: HOW TO: Use ASP.NET to Protect File Types. What that means is that when you see a GIF image, it will pass through the ASP.Net engine, firing all the usual events.

However, after you do that, you see that web services start behaving strangely. Why is that? One explanation says that "405 mostly comes about when you try to POST against a URL that is not considered dynamic by IIS". It doesn't much makes sense to me.

I have searched a lot for an elegant solution. The only one that actually applied was using a piece of code in the BeginRequest event in Global.asax (or maybe in a HttpModule that one has to register in web.config). It came from this forum: HTTP verb POST not allowed. Here is the code:

//The BeginRequest event is fired for every hit to every page in the site
void Application_BeginRequest(Object Sender, EventArgs e)
{
var extensions = new[] {".asmx", ".svc"};
foreach (var ext in extensions)
{
var index = Context.Request.Path.IndexOf(ext, StringComparison.CurrentCultureIgnoreCase);
if (index <0) continue;

var path = Context.Request.Path.Substring(0, index + ext.Length);
var pathInfo = Context.Request.Path.Substring(index + ext.Length);
var query = Context.Request.Url.Query ?? "";
if (query.StartsWith("?")) query = query.Substring(1);
Context.RewritePath(path, pathInfo, query);
break;
}
}

I needed a dynamic menu control for my site. So, of course, I tried to use the ASP.Net Menu control (with its many failings when following CSS standards). It was a painful failure. It didn't work in either Internet Explorer 8 or FireFox 3! That was especially strange since I had used the control in a bunch of sites and it worked back then!

Long story short:
<DynamicMenuStyle CssClass=adjustedCssIndex />
where adjustedCssIndex is a CSS class that specifies the z-index property:
.adjustedCssIndex { z-index:100; }


Long story, it seems that the control assumes there is a default z-index value set by the browsers; Bertrand Le Roy from Microsoft says as much in his blog, and discloses a patch fix.

However, as you can see in that post's comments, there is also a very simple CSS fix to all of this, by specifying the z-index.

The finale of what seemed to become my favourite sci-fi series ever (at its beginning) left me with a bitter taste in my mouth. Not only it makes no sense, but it is overall incredibly idiotic. If you haven't watched the end of the series, don't read further, because this is the mother of all ranty spoilers ever.

What makes it so emotional for me is not only that I really liked the show, but that this was not a show that was ended because of lack of planning or budget or the economical crisis, so nothing was rushed or changed. This was "meant to happen". And it sucked! Sucked worse that a vampire caught in the event horizon of a black hole that is falling into another black hole!

Not only did it not explain anything in a manner that would make sense to me, but instead it went completely overboard on all the things that I hated in the show. God exists, he somehow planned all this (oh, yeah, real modesty here, mr. Moore!), the model 6 in Gaiuses head was an angel, so was Kara Thrace, in the end they all reach Earth (this Earth) and decide to leave all technology behind (they throw the ships in the sun!!!) in the hope that starting anew would make them "break the cycle" and Hera became the chromosomal mother of all future humans. I guess leaving all that technology behind wasn't a good survival strategy for the rest of the 38000 people left alive, was it?!

If everything was God's plan, then there was no cycle except in its brain!! Forgetting mistakes is NOT a step towards not repeating them. Leaving behind technology is just as stupid! And ending the show with a couple of angels walking on Earth now and making bets on if we repeat the mistakes again or not, with background videos of the latest developments in robotics was.... there is no word in the English language for it. It is dumber than creationist! And the last half of the last episode was all about people saying goodbye to one another then going to live alone (read DIE!!) somewhere!

There is a glimmer of hope left though. The centurions were given their freedom and the last baseship. I will be looking at the sky hoping for them to return, nuke Moore and then air an all Cylon TV show about how they didn't repeat any mistake and just carried on!! Gods, this was frakking retarded!

And, of course, there is one more good thing in the series, and that is the Bear McCreary's remix of Bob Dylan's/Jimmi Hendrix's All Along the Watchtower. I am embedding the video with the cool transition from simple piano to all the instruments. Pretty cool!.

Guess what? F***ing YouTube removed the video because of a copyright infringement. What? One minute and a half of a movie scene? Geez! Couldn't find the same scene, so I am embedding All Along The Watchtower.

[youtube:qMo7WybtTWI]

The sound bit of the scene, sans the scene, can be found here. You can also see the live performance of the song here. You might also want to try Bob Dylan's original song.

Update: check out this Google event with McCreary playing the BSG theme with Raya Yarbrough as the vocalist.

and has 0 comments
This is how Dexter, the animated character in Dexter's Laboratory, begins his days. His enthusiasm for his work is amazing and inspirational, but real people rarely feel this way. Today is one of those great days for me! I woke up late, I took a long shower, I've eaten some good food, I've watched one of my favourite anime shows while getting dressed and I came to work in a beautiful sunny spring morning.

What amazing energy and how great a feeling! I feel I can do anything! Throw your legacy ASP applications at me, make me do stupid changes in even dumber web CRMs, give me the most menial degrading tasks you can think of, I will eat them whole and spit out gold! I am unstoppable!

and has 4 comments
Ok, you first must know that Microsoft added a specific namespace for working with ActiveDirectory in .NET 3.5. It is called System.DirectoryServices.AccountManagement. The principal objects in the Account Management API include computer, group and user objects and it provides a means for applications to extend the object model to include custom schema object types.

Now that this is out of the way, I want to take my simple Authenticate, ListUser and ReadUser methods (working fine with the old DirectoryEntry method) and translate them into this new way of doing things.

I did some code and I got this error message: "80075000". That is the actual error Message property! Even more remarkable, a google for 80075000 resulted in only 246 results!! none of them explaining what I did wrong. Apparently, I had sent a string in the format "LDAP://ComputerName" as the computer name. Maybe it helps someone.

But this didn't solve it. I changed it with just the computer name, with or without a "\\" prefix, and I got a more clear text, but just as vague UnauthorizedAccessException: "General access denied error".

I am still working on it, but damn, how can a programmer not think about the error message he passes to other programmers?!

Ok, made it work, here is the code for the user authentication in an Active Directory domain.
Classic DirectoryEntry:

bool authentic = false;
try
{
var entry = new DirectoryEntry("LDAP://ComputerName",
"Domain\\username", "password");
object nativeObject = entry.NativeObject;
authentic = true;
}
catch (DirectoryServicesCOMException ex){}
return authentic;
As you can see, not the most elegant approach.

The .NET 3.5 way:

using (var context = new PrincipalContext(ContextType.Domain,"ComputerName"))
{
return context.ValidateCredentials("username","password");
}
Much better, isn't it? Pay attention that in the first case you need the domain in the username and in the second you need it not to be part of the username!

There is a third way (System.DirectoryServices.Protocols.LdapConnection), but seems too complicated to address right now.

and has 0 comments
The new spring heat seems to have brought not only flies out of hibernation, but also some cats! Their behaviour is strangely similar to that of the flies, though, hmm :)