Wednesday, 17 September 2008

The Cobweb by Neal Stephenson and J.Frederick George

The Cobweb is not a sci-fi story, just a fiction thriller. It happends in modern day America, where a small town cop slowly unravels a plot of international proportions and implications. He has to foil it with no help from (or rather against) the corrupted systems of university academia and government security and diplomatic agencies.

Actually, this is the main subject of the book, if I can say so: Throat cutting internal politics inside the CIA, the rule that CIA operations cannot take place inside the borders of the USA, and they ways to bend that rule, university scholarship stewards that live off foreign student exchanges (real or not) and bogus grants, etc. It was a bleak picture, the one painted of the CIA employees who cannot exceed their assigned duty, even if they have plenty of reason to, else face career stop or even dismissal.

In the end, of course, Deputy Sheriff Clyde Banks saves the day, but I can't help noticing that I knew this would happen from the very start. The real information is in the path to the end result and that is what I've appreciated in this book. The reader is taken away to discover the filthy world Stephenson and George expose.

It starts a little slow. It also provides plenty of information for would be terrorists :) So I recommend it to everyone, even if it is not a sci-fi book, it's a solid well made story.

Tuesday, 16 September 2008

offsetParent null in FireFox. Absolute position in FireFox yields 0,0

I've spent about a day on a thing that I can only consider a FireFox bug. As a complete reverse from what I would expect from a javascript script, it worked anywhere but in FireFox! And FireFox 2.1, I haven't even installed 3.0 yet.

It concerned a simple javascript function from a third party that was supposed to get the absolute positioning of an element when clicked. I've written one myself a while ago, but it didn't work either! Here is the function that I was trying to fix:
function getPos(n) {
var t = this, x = 0, y = 0, e, d = t.doc, r;

n = t.get(n);

// Use getBoundingClientRect on IE, Opera has it but it's not perfect
if (n && isIE) {
n = n.getBoundingClientRect();
e = t.boxModel ? d.documentElement : d.body;
x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border
x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x;
n.top += t.win.self != t.win.top ? 2 : 0; // IE adds some strange extra cord if used in a frameset

return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x};
}

r = n;
while (r) {
x += r.offsetLeft || 0;
y += r.offsetTop || 0;
r = r.offsetParent;
}

r = n;
while (r) {
// Opera 9.25 bug fix, fixed in 9.50
if (!/^table-row|inline.*/i.test(t.getStyle(r, "display", 1))) {
x -= r.scrollLeft || 0;
y -= r.scrollTop || 0;
}

r = r.parentNode;

if (r == d.body)
break;
}

return {x : x, y : y};
}


As you see, it is a little more complex than my own, although I don't know if it works better or not.

Anyway, I found that the problem was simple enough: the element I was clicking did not have an offsetParent! Here is a forum which discusses a possible cause for it. Apparently the Gecko rendering engine that FireFox uses does not compute offsetParent, offsetTop or offsetLeft until the page has finished loading. I didn't find anything more detailed and there were just a few pages that seemed to report a problem with offsetParent null in FireFox.

I tried to solve it, but in the end I gave up. My only improvement to the script was this line:
while (r&&!r.offsetParent) {
x+=r.offsetLeft||0;
y+=r.offsetTop||0;
r=r.parentNode;
};
which resulted in a more localised position, i.e. the position of the closest parent to which I could calculate a position.

In the end the problem was solved by restructuring the way the dynamic elements on the page were created, but I still couldn't find either an official cause or a way to replicate the issue in a simple, separate project. My guess is that some types of DOM manipulations while the page is loading (in other words, scripts that are just dropped on the page and not loaded in the window 'load' event which change stuff in the page element tree) lead to FireFox forgetting to compute the offset values or just even assuming that the page is never loaded.

Monday, 15 September 2008

Installing WinXP on a Laptop with SATA drives, but no floppy

The problem is that Windows XP only accepts serial-ATA drivers from the floppy diskette. You don't have one. What are you to do?

Google gave me a few ideas, but I had to piece them together. So, here is what you need:
  1. download the SATA drivers for your laptop
  2. download Virtual Floppy Drive by Ken Kato - at this time it is at version 2.1 - if your SATA drivers are in the form of a floppy disk image generator (a single exe that asks for a disk in the floppy drive)
  3. download nLite - at this time 1.4.9.1
  4. get a windows XP installation disk
  5. have a writable CD and a CD writer ready
.

And here is what you do on another computer (one that is working :)) :
  1. (if you already have the SATA driver files, skip this)Go to My Computer, Properties, Hardware, Device Manager and disable your floppy drive, if you have any
  2. (if you already have the SATA driver files, skip this)Install and run Virtual Floppy Drive and create an empty image on A:
  3. (if you already have the SATA driver files, skip this)Run the stupid SATA drivers you downloaded - that only want a diskette to format with their files, they can't simply unzip them somewhere - and you will get the drivers in file form on the virtual diskette
  4. Start nLite and select the Drivers and the Bootable ISO options then Insert multiple drivers and give it the drive A: as a source
  5. Create the ISO image, then write it on a blank CD - writing CDs from images is different from just dragging and dropping files in the CD writer window, BTW


That should do it! Use the newly created CD as the XP installation disk without pressing F6 for loading SCSI drivers.

Clone Detective for Visual Studio 2008

I've stumbled upon a little VS2008 addon that I think could prove very useful. It's called Clone Detective. Here is how you use it:
  • Make sure VS2008 is closed
  • Download and install the setup file
  • Additionally the source is freely available!
  • Open VS2008 and load a solution up
  • Go to View -> Other Windows -> Clone Explorer
  • Click the Run Clone Detective button


Now you should be able to see the percentage of cloned code in each file and also see the cloned code as vertical lines on the right vertical border next to the code.

Karishma - a very nice Indian restaurant in Bucharest

really flashy, isn't it? We intended to go to Thang Long, the Vietnamese restaurant, but so it happends that it was closed. On the same street there was this large, Indian looking (elephants and all), restaurant: Karishma. It looked too flashy, that being the reason why I usually suppressed my curiosity of going in there, but that day I felt curious enough.

As it turns out, it is the real deal: good food at reasonably high prices, real Indians running the shop, even serving the food, and nice people (at least with their customers), beautiful interior. Four people ate enough with 215 lei, that is about 60 euros or 84 USD. We tried the lassi drinks (yoghurt with mango or with cumin and salt), the masala tea (black tea, ginger and cardammon with lots of milk and sugar) and saucy meat foods. We could choose the level of spicyness, I asked for very spicy and it was heaven. My table mates called it poison and stuck to their own meals.

All in all, I highly recommend it. Here is the address and contact information:

Karishma restaurant
Address: Iancu Capitan 36, Bucharest,
Phone: 0040-21-252.51.57

Sunday, 14 September 2008

My Holiday in Greece - Part 3

Ok, what's done is done, Maria wanted to spend more time with her sister and we both got tired of Kyparissi, so we went back to Sparti. This time we went alone, having gotten directions on how to get there. The GPS was useless, since it had no maps of that area whatsoever. I did pin the house on the map, though, so I knew the general direction.

Back towards Sparti, Greece (5)

Of course, we got a little lost. We entered a town we did not know the name of and we found ourselves on a road to Monevasia. We have been to Monevasia, it was in the south, we wanted to go a little north. What should we do? I pointed out to Maria that the road to Monevasia probably meets another one that comes from Sparti, using her own words from the experience with Kulata and Sofia. Of course, now that the same words of wisdom came from my mouth, she decided to turn back. We again entered the nameless village and we noticed a sign towards Sparti (fixed on a wall, so you can only see it when coming from the other direction) so we took that road. We've had the inspiration to stop next to a guy and ask if that was the road to Sparti. No, of course not, it's the other one! (the one from which we came from).

back towards Sparti
back towards Sparti
goats on the rocky sides of the road: take me! no, take me! :)

Sparti, Greece (6)

Finally we got back on track and reached Sparti and the small village next to it where Maria's sister lived. We stayed there a few days, during which the girls either spent talking to each other (and dragging me into it as much as they could, while I was trying to read the boring books I brought with me) or my sister in law spent at work and me and Maria sight seeing.

We first went in the city of Sparti to visit "Ancient Sparti". It was a big sign that directed us to it. It was a bloody park, a small one at that. Just a few stone looking modern roads, olive trees (of course), and some ruins, partly escavated and surrounded by do-not-cross tape. There were people that had parked their cars there, even their RVs! There was a modern contraption in the middle of it, something like a concrete electrical thing or maybe a janitor house, I don't know, full of graffiti. The only good thing that came out of this was a great view from above of the town of Sparti.

much of it look like this
you can see the crappy building behind these ruins
ancient ruins and modern Sparti
Sparti from above
I have better pictures of Sparti, but I liked the sun rays

When we came back we took the car through the orange orchard from the back of the house and we found a goblin tree! Heh, just look at the picture, you will see what I mean.

if I stay still maybe they will think it's an olive tree!

Trip to Kalamata, Greece (7)

After that we decided to go to Kalamata, which is a rather large city in the south, taking first a mountain road that would take us directly, then return on a path that would follow the seaside and go around the mountain. It was a very nice trip. The mountain road felt like normal country for once, with actual green, non olive, trees and even rain! The towns on the edge of the sea were all nice, even if we only saw them from afar. In Kalamata, for example, we got lost trying to find the center of the city. There were signs for the center, but after following them, we would always get to the same spot, which was obviously not the center. On this trip we actually noticed vast regions covered with black ash. We theorised it was related to the extended fires that had plagued Greece the previous summer. But it could have been just as well new fires or even some weird agricultural system.

this in southern Greece, can you believe it?
after the rain
some church in Kalamata
seaside towns as seen from the road
small settlement as seen from the road

After the few days in Sparti we decided to go back to Bucharest. Again a night trip through Greece that would let us do Bulgaria during the day and reach home in the afternoon. This is were it got interesting. I told the GPS to take me home. Not only did I specify Bucharest, but the exact address. I then trusted it to take us there, without (as Maria would soon point out) actually checking the path. My only defence is that I am a software developer and I instinctively trust the electronics more than any paper map.

So, in the middle of the night, we found ourselves on a twisting road, dark and full of poorly signaled curves. Maria got upset immediately and asked me to look at the GPS. I did and I found out that the highway would take a large curved path and that the road that the GPS put us on was cutting that path. I did remember a setting on the GPS that involved road tolls. I thought the machine wanted us to avoid the tolls so it took us away from the highway. So I checked the setting off.

The road now went on another path. I could see that both previous and current path were taking european roads, but it didn't specify which was a highway and which was not. Maria was angry as hell and I was slowly losing my patience. I can stand hysterical shouting just as any guy, maybe a little better, but I do have my limits. I proposed to stop the car and look at the paper map and decide together on the path we want to take. Maria refused. So we went on.

At one moment I was actually reasoning that impulsive reactions (like swerving the car at high speed off the curve and killing us both) were usually an effect of low levels of serotonin, the comfort hormone. Both in animals and humans, serotonin is produces when the subject is caressed. So I actually caressed my wife, cooing her to close to normal levels of serotonin, when I almost felt like ripping her head off. Of course, that would solve nothing, since I can't drive (not to mention I am a rookie at ripping heads as well).

We passed through the town of Thiba, then we continued on a road that was nothing close to a highway. It was a good road, but not what we expected. The darn GPS took us from the highway because I checked that road toll setting off. Maria finally decided to stop and look at the map. The map showed us that the highway was 2 km from Thiba. We were already 20km away from it. But the small town where we stopped had two clear (albeit very thin) roads taking us directly to the highway. We inquired of the way to the highway to a gas station lady. She said that no, the only way is back to Thiba. So we went 20km back to Thiba, 2 km to the highway, 20km on the highway, where we noticed an exit to the small city we just left from.

At least everything went cool from that. It was good that we looked more attentively on the path home, since the GPS had prepared another surprise for us: it wanted to cross the border to Macedonia, then Bulgaria. I think that it would have been a more interesting road, but Maria insisted we take the known path through Kulata. Remember Kulata? Anyway, we got to Sofia, where the ring road around it was still under contruction!

Bulgaria (8)

After following a long queue of cars going at 4m per minute on dusty unmarked unpaved roads in the middle of Sofia, we got to the ring road again. It was under contruction there as well. So we stopped at a gas station and asked for directions. Bulgarians are different from Greeks. When they say they know a little English, they actually mean they don't know some of the words, not they just know a few. They were nice, showed me where I was on the map, where I should go to exit Sofia and reach the road to Ruse (the border town to Romania) and they even gave me a Bulgarian map. I told them I have no money to pay for it and they gave it to me anyway! I gathered that the map costs less that 5 euros + the repairs to the cracked lateral mirror, but still it was amazingly nice of them.

Then we got to the road to Ruse. This time, the GPS took us on another road that had no more 40 and 60km speed limit signs. I was glad to see it, especially since Maria had exclaimed "oh, now we get on that boring road" only minutes before. I was thus surprised to hear her complain the entire way to Ruse that it was NOT the way we came on when going towards Greece.

And that's about it. We got home, I started writing all this, I enjoyed my last 4days of freedom before going to work, answered my emails, I couldn't believe the people leaving spam and messages on the blog DEMANDING work done for them, etc.