Saturday, August 22, 2009

Count Zero by William Gibson

Book coverCount Zero is the middle volume of the Sprawl trilogy written by William Gibson, which includes Neuromancer, Count Zero, and Mona Lisa Overdrive, all of them very good books and set in the same universe as the short stories Johnny Mnemonic, New Rose Hotel and Burning Chrome.

I had read this book when I was a child and I loved it a lot. Circumstances moved me towards reading it again and I am glad they did. In my youth I had barely understood it and I can't say I did a lot better now either; that's because Gibson is one of the mature writers, writing for the mind and heart of adults.

Count Zero in particular, it felt like something one must feel through bones, must sip the content like a good coffee and digest the content with one's soul. Alas, I am not that kind of a guy, so I read it fast in the subway while going to work, in big gulps, like the glutton I am. I highly recommend the former approach ;)

The plot itself is like a high tech detective story, but it is almost irrelevant. Gibson has such a clear and powerful vision of the future, that it subjugates all of its characters to it and makes it, the future, the main character. Many things are not said, but left to be understood, like the reasons while the world is the way it is and why people act the way they do. Read Count Zero, even if you are not a sci-fi reader, because beyond the storyline there are layers upon layers of worldliness and it is a great book.

Monday, August 17, 2009

jQuery slideUp flickers in Internet Explorer quirks mode

I had this expand/collapse div on which I was using slideToggle to make it look good. However, in quirks mode (HTML Transitional 4.01 DocType) and on IE7 the div would briefly pop up after collapsing, showing an annoying flicker. It seems that Internet Explorer has a problem rendering stuff with height 0px.

The solution I found: replace target.slideUp(speed,callBack) with
var h = target.height();
var cssHeight=target.css('height');
target.animate(
{ height: '1px' }, speed, function() {
target.hide();
target.height(h);
target.css('height',cssHeight);
callBack();
}
);
I have also created a jQuery ticket to suggest they use the same method in the library itself.

Update 1 Sep 2009: I have added the cssHeight variable to restore the actual css height settings, not just the height.

Update 21 May 2011: commenter Mads shared a more elegant solution in the form of this script:
(function(){
// Define overriding method.
jQuery.fx.prototype.hide = function(){

// Remember where we started, so that we can go back to it later
this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
this.options.hide = true;

// Begin the animation
this.custom(this.cur(), 1);
}
})();
used anywhere after the jQuery include. Thanks, man!

Trip to Veliko Tarnovo and Arbanasi

It wasn't a very memorable trip, but I had to write this because of the Bohemi hotel in Arbanasi, which must most certainly be avoided. And it was, overall, a nice holiday. But let me take it from the beginning.

We took the car starting up from Bucharest and went towards Veliko Tarnovo. We passed through Basarbovo, to visit the rock monastery there. Very nice place, if you like churches. They have these small rock dug rooms where priests used to live and pray and then the monastery which was in renovation when we came there, but had a very lovely garden.

Cherven fortress We then moved towards Cherven, where we visited the castle dig which is archaeologically active. It is a large XIV century Christian fortress, where one can see how people lived in the day: small one room living quarters and then a gazillion churches, large and small, then some administrative buildings and some defence walls and watch towers. There are about 200 stair steps to reach the castle from where the car road ends.

Next was Ivanovo. Some other rock monasteries, but everything set inside a natural reserve, a very beautiful place.

Then we went towards Arbanasi, a touristic area where there are a lot of hotels and where we arranged for accomodations. The hotel we chose was a three star hotel called Bohemi, boasting internet, minibars, outdoor oven, breakfast, etc, depending on the tourist site you search for it. Let me tell you how it really is: it's a two star hotel with smelly rooms, no parking, invaded by insects and spiders (and a scorpion which scared the craop out of my wife), no internet, no minibars, with a breakfast as the ones from the communist era: some bread and butter and jam and some salami/cheese slices. The hotel itself is one of many owned by the same people, so the person serving there is only an employee, put there to mind the place. In the room, after we got used with the stale odor of moist walls, we noticed that we has not enough sheets and two out of four light bulbs were not functioning. Really, I can't stress enough: 35 euros per night?! In times of economic crisis and with this kind of service? Avoid!

Arbanasi itself is not a bad place to stay, eat, sleep, and then back again. It would have killed me with boredom if I didn't have a car. They have a monastery there, but by then I got tired of any type of religious building. The restaurants where very nice, but service was consistently bad. I haven't seen dumber waiters in quite a while.

Veliko Tarnovo from outside Veliko Tarnovo is a large city, once the capital of the second Bulgarian empire.

Veliko Tarnovo Tsarevetz stronghold The stronghold there is a very nice place, where they don't allow sale people and where people can see theater and sound/light shows in the evening. Very large, beautiful and accomodating. Then there are some monuments and some nice streets.
The city itself is pretty cool. Lots of churches, of course :) I am sure that, being with my parents, I missed a lot of the hidden beauty of the town, but it was nice nonetheless.

Veliko Tarnovo has some nice streets

Veliko Tarnovo monument

That was about it. Take the links to get more information. My general opinion of Bulgaria is that it is a nice country, beatiful and wild, but rather poor. All the small towns and villages we passed through looked half abandoned, with many disaffected buildings and very few people. The economic crisis must have hit them pretty hard, too.

Sunday, August 16, 2009

Redemption Ark by Alastair Reynolds

Book coverAs I was saying in the last posts about the Revelation Space books by Alastair Reynolds, the guy has a problem with his own personality bleeding into the one of his characters. However, as the second book was better than the first, so the third one, Redemption Ark, seemed to be better than the second. It may be because now the main focus is on the Conjoiners, the fabled human faction that gave the star drives, facing the threat of the Inhibitors. Also, a very promising explanation of where they got the idea from in the first place.

We are seeing a lot of old characters from the previous books in this third installment, which bothered me a little because they weren't really needed, but it's not too annoying. Also, some of the awesome technological feats in the book are only partially explained and sometimes even completely ignored and left to a vague description, like "distant lights" when referring to a Hell weapons vs Inhibitors battle. But the focus, as always, was more on the human interaction than on the technical part, although there was blessingly more tech than in the first two books.

Since I've finished the book while away from home, I started reading another book, not the fourth in the series, so you will probably have to wait a while longer before I review that, but rest assured, I fully intend to read the entire saga.

Monday, August 10, 2009

Visual Studio problem with abstract classes in the designer

The problem: you create an abstract class that inherits from something that can be designed in Visual Studio, like Form. Then you inherit another class from this abstract one. And when you get into the Visual Studio designer you see a nice colorful error message: The designer must create an instance of type 'bla bla bla' but it cannot because the type is declared as abstract.

The solution is detailed in a post of Brian Pepin: use the TypeDescriptionProviderAttribute decoration on the abstract class in order to tell .Net (thus to Visual Studio) what concrete type to declare and instantiate should the need arise.

Update: Brian's article is no longer available. I will update the link as soon as possible. Meanwhile, try this article from Microsoft.

Update: I have found the original article somewhere else and relinked it. Also, check out the fourth comment on this entry, where TrevDev links to a Microsoft Connect bug on the TypeDescriptorAttribute which suggests the attribute is not used correctly. That probably explains why people on VS2008 have problems, while the solution works on VS2005.

Now, all you have to do is read the post in question, with one reserve. The blog entry (and some other pages I have found on the net) say that this only works for Whidbey (VS2005), but I am using VS2008 and it worked just as well. However, for a second opinion try this CodeProject article that uses a little conditional compiling trick to switch from abstract classes with abstract methods and properties to normal classes with not implemented classes and methods based on debug/release modes. I kind of dislike the approach, mostly because it needs more effort to implement it, but it could help people that have this problem and maybe use some other IDE other than VS2005 or VS2008.

Sunday, August 09, 2009

Avatar: The Last Airbender

Aang, the airbender Avatar Avatar is one of those animation series that you read about and think they're crap. I mean, first of all they are not Japanese :), they are actually US. And then they are shown on Nickelodeon and then they are about and for kids. I must be honest when I tell you that I accidentally heard about the series and I had no great hopes for it. However, as it turned out, it is a great show, one to be watched and enjoyed.

The show is mostly inspired from Chinese mythology, with Western and Indian bits thrown in when required. The world is separated into four nations. The people of each nation can control in various degrees a specific element magic: air, water, earth or fire. Unlike say, Naruto, there are no people that can control or mix more than one magic type, except a special and unique person, the Avatar. The Avatar has the job of protecting the world and, if killed, reincarnates into another person. The last Avatar, though, dissapeared a century before the show starts and no one has heard of him or any of its reincarnations. Meanwhile, the evil Fire Lord has started a war to conquer the world and he is about to succeed.

Well, you can see where this is going, right? The Avatar comes back, he is a goofy kid, and in the end he saves the world together with his friends. However, the animation, the stories and the teachings in this show are all high value and, for once, something a kid can see, enjoy, understand and USE in the real world. Well, all except the magic part :)

What is also great about the series is that it is not a work in progress. It did not end because the ratings went down or the economic crisis hit or whatever and it has very few filler episodes. It was a long consistent script that span three seasons of 20 episodes each and then ended with no significant loose ends.

In other words, this is one of those rare American shows that can rival the best Japanese anime series. Even my wife enjoyed watching it (well, most of the time).

Wednesday, August 05, 2009

Chasm City by Alastair Reynolds

Book coverChasm City is the second book from the Revelation Space series written by Alastair Reynolds. It is set in the same universe, give a few hundred years, and it felt to me as a better, more mature book than Revelation Space. However, truth be told, the ending had the same flaw: the personality of the author bled through all the characters, transforming them into a do-good Scooby Doo gang, eager to solve mysteries and help people. Sorry, Mr. Reynolds, you're just too nice of a person! :)

Anyway, this time the plot revolves around issues of personal goals and identity, the very definition of a persona and of quality of life. While the story is intricate enough to make it a great book, I thought many of the concepts in it were very interesting, but insufficiently explored. Then again, explore any concept long enough and you never get to the other end, so at least having a complete coherent story that spans the entire plot is a big plus.

I just started Redemption Ark, the third book, which (finally! :) ) deals with the Conjoiners and a technologically advanced alien race. Or at least it starts that way. Happy reading!

Tuesday, August 04, 2009

The rounded corners from hell and VML

I have this very precise requirement I am working on: a collapsable panel that has rounded corners of fixed size and a background image or a gradient, both needed to stretch with the panel, which would be vertically resizable by javascript. Also, the HTML 4.01 Transitional DocType will be used on pages. The only respite given is that the solution should work only on Internet Explorer.

I have first tried some jQuery alternatives, but I am not happy with them. Even if the rounded corners would have been what I was looking for (and they were not), the background stretching is a difficult feat to master in HTML. Even so I have cropped up something that takes the entire content of the panel and relatively positions it over an absolutely positioned image that is then stretched by javascript to its needed dimensions. However, all this relative and absolute positioning requires a lot of event driven javascript (when the events themselves are not really there, so I must also create new browser events!) and it has been shown to break either layout or functionality like the one for collapse.

Enter VML, an obscure web technology from Microsoft that has a RoundRect object that can have a fill of an image OR a gradient, stretched to the full size of the element. Can you see it? I was already planning the blog entry, detailing the masterful ASP.Net control that would change the world of web development forever.

Back to real life now. First of all, the RoundRect element does have an arcSize property that determines the percentual size of the rounded rectangle. By percentual, I mean that resizing the element would lead to larger corners. I don't need that. Another nice surprize was that I can't either read or write the arcSize property from Javascript, it throws an error. People have complained about it before and their solution was to disconnect the element from the DOM, change the arcSize, then add it back into the DOM. It didn't work for me.

After wasting about half a day with this, I concluded that the RoundRect was a lost cause. Enter Shape! A Shape is a VML element that can take any shape determined by a path. The path has interesting primitives like qx and qy which mean "draw an arc to this position". It appears that a Shape can easily take the place of the RoundRect. What was even nicer, the path attribute could be changed at will by javascript.
<v:shape strokecolor="blue" strokeweight="1" coordorigin="0 0" coordsize="203 103" style="width:200px;height:100px"
path="m 2,0 l 198,0 qx 200,2 l 200,98 qy 198,100 l 2,100 qx 0,98 l 0,2 qy 2,0 e"></v:shape>
The code above is a 2 pixel rounded corner rectangle of size 200 by 100. To add a stretched background image or gradient, a v:fill element must be added as a child of the shape and you are done!

I was extatic, finally having solved the problem that had haunted me for days, until I noticed that, unless I specify the width in pixels, the shape would behave really strange. I was commited not only to a panel that needed to be defined as percentual or expanding with the content, but also to HTML 4.01 Transitional DOCTYPE. In this particular situation, placing two shapes in a table, let's say, even if the table size was specified or, indeed, the sizes of the TD elements, in percentages or pixels, the shape would just expand to its maximum possible width.

I got stuck here. The control worked perfectly when the width was specified in pixels. Anything else just throws a big wrench into the works and makes it wanna go boom. In a fit of anger, I just replaced the obsolete doctype with the modern XHTML 1.1 one. And it worked, but only on Internet Explorer 8, not any of the previous versions of the browser.

Therefore my only option now is to either abandon the technology completely or to convince people to change the DocType for all their legacy pages. How fun is that?!

And before you write the usual crappy "Microsoft sucks! Internet Explorer sucks!", try giving me a solution for my request that would at least work in another browser. Was it so difficult to recognize the need for a stretched background image and custom shaped containers ?!