Monday, 22 September 2008

Very Slow USB Memory Stick in Windows XP

I finally bought myself a laptop and I had to figure out how to transfer files from my computer to the new device. I'll spare you the details, the thing is that I finally decided to use a 4Gb flash stick that my wife had from work.

I wanted to copy about four episodes from a tv series (that's less than 1.5Gb) and it said it needed to do it in 30 minutes. I thought, well, maybe the stick is slow. I was in no hurry, so I let it copy. I noticed that it worked in great bursts of data. First copy fast, then wait, then copy again, then wait again. When I moved it to the laptop, the file system was corrupt. What the.. ? So I formatted the stick. Apparently, I had only the FAT32 option, not NTFS. Then started copying again.

I Googled for it and found out that Windows XP does not enable write caching for removable drives. Me being me, I immediately went to the hardware properties of the stick and changed the way it worked from 'Optimize for quick removal' to 'Optimize for performance' (which specified that it enabled write caching). Wow! I am so smart. But I continued Googling anyway and I've learned that the setting doesn't really change anything, other than giving you the option of formatting with NTFS, which then would allow write caching.

But there was also another option, even with 'Optimize for quick removal' on: use the Windows XP command line utility Convert which is used to convert a FAT drive to an NTFS drive. I stopped the copying, only to notice that the file system was corrupt again. I deleted the files, ran chkdsk K: and then convert K: /fs:ntfs /v /NoSecurity. While the copying went a lot smoother, it still took 15 minutes to copy the damn thing. At least I could read it at the other end, anyway.

I don't exclude the possibility that drivers or stick hardware were at fault (since it is the first time this is happening to me), but be aware that you can always have this option of using NTFS instead of FAT32.

Disadvantages of using NTFS and write caching:
  1. You need to use the software option of removing the USB stick and wait until it says it is safe to remove it, otherwise you might have write errors
  2. NTFS has this ugly write last access time option that you can only remove it through a registry hack.
  3. NTFS sticks cannot be used for some devices like mp3 players and such, since they only know FAT32 access. Windows 98 is also oblivious to NTFS, although there are third party NTFS drivers for it


Almost all information here can be found in more detail at this link: Tips for USB pen drives.

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