I had this really old site that I was asked to "upgrade". Net 1.1 to 3.5. So I had to change old ADO.Net SqlConnection to Linq-to-Sql. A lot of unforseen issues. Sometimes it is close to impossible to recreate a simple SQL query without changing the database, as in the case of updating tables or views without primary keys.

Anyway, I got stuck in a very simple issue: How to sort a Linq query based on the string returned by the GridView Sorting event. After a lot of tries and Googling I found it was easier to use third party software (although it's more of a 2.5rd party software, as it is made by Scott Guthrie from Microsoft). Here is the link to the blog entry: Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library) . You can find there a sample project to download, with the LINQ Dynamic Library inside.

With this library and the OrderBy extension methods the code becomes:
var somethings=from something in db.Somethings....;
var data = somethings.OrderBy(Sort + " asc");
gv.DataSource=data;
gv.DataBind();

I had this calendar extender thingie in my site and the client was Italian so I had to translate it into Italian. Nothing easier. Just enable EnableScriptGlobalization and EnableScriptLocalization and set either the Web.config or Page culture settings.

However, the footer of the calendar kept showing "Today" instead of "Oggi". I checked the source and I noticed that it used a AjaxControlToolkit.Resources.Calendar_Today javascript variable to create the footer. Step by step I narrowed it down to the AjaxControlToolkit resources! Funny thing is that they didn't work. I tried just about everything, including Googling, only to find people having the opposite problem: they would have all these resource dlls created in their Bin directory and couldn't get rid of them. I had none! I copied the directories from the ACTK and nothing happened.

After some research I realized that the Ajax Control Toolkit does NOT include the option for multi language UNLESS in Release mode. I was using everything in the solution, including the ACTK, in Debug mode. Changing the AjaxControlToolkit build to Release in the solution made this work.

A new (and old) buzzword: to reinvent. It is always a good thing to reinvent yourself, they say, with the effect of relieving boredom and living a "new" life. You may discard bad or useless things in favor of good things. It is also good to reinvent something somebody else did, like a movie. You take the idea, you remove the bad things, you add good things. But, as in the case of the benevolent tyrant, the definition of good and bad is always fuzzy.

Was it good to reinvent BattleStar Galactica? I say YES! It was (and still is, despite screenwriters efforts) the best sci-fi series out there. Of course, that is my opinion. Was it good to reinvent Terminator, incarnated into a teenage girl looking machine? Ahem. But I still watch it. Was it good to reinvent Superman as a troubled teenager? Puh-lease! Come... on! Nah-uh! (See, I address the younger demographic here).

Because, you see, the people that decide what is good and bad in movies are actually the money people. They look at superficial statistics that only show... money! They make abhorent remakes of decent films (like Indiana Jones 4 - The Rape of Indiana) or they turn every hero into man/woman/teenager/animated-character/doll versions that bring nothing new.

In the case of Star Trek, they made the first low budget series than achieved cult level regardless of bad production values and some ridiculous scripts, then they made a sequel (at that time reinvention was not invented yet) where Patrick Stewart redefined the space captain as a cerebral science oriented man, but with lots of guts, then they started the old routine: make the captain black, make him a woman, replace the ship with a station, then with another ship, but in some other place, etc. They even made a prequel, which, for almost a full season, was decent in both interpretation and scenarios. What was missing, of course, was a teenage Star Trek captain. Well, no more!

"Star Trek", the 2009 movie in the making (and no doubt, with a series looming if money are made), features a young Kirk and (what a fallacy) a young Spock! The director is none other than my least favourite person in the world: J.J.Abrams, the maker of such abismal stupidities (but well received by the general audience) like Alias, Lost and Fringe. The writers are Abramses old team, Roberto Orci and Alex Kurtzman, the brilliant creators of such idiocies like Alias, Fringe and Xena/Hercules!

I am trying to keep an open mind here, but I would venture to guess that the new Star Trek will have big booming sounds whenever something strange happends, will be filled with inexplicable things that will never be explained, except maybe in the movie (but I doubt it, they have to plant the hook for a series) and will have people calling the others by name obsessively, regardless if the need for it arises. So, it may be cool, but I expect to be baktag!

and has 0 comments
I've listened to this song for a long time now, it was only proper that it would appear on my blog sooner or later. Sandra Nasic sang for Guano Apes and after the band split she released a solo album in 2007 called The Signal which features some good songs, although a little mellow for my taste. You can listen to fragments of some of Sandra's songs on her MySpace site, visit her official site or just plain google for videos like I do :)

So listen to this symphonic Sandra Nasic sound. I wish she would have done more pieces like this.


and has 0 comments
Brisingr is the third book in the Inheritance cycle (now a cycle because the author could not end the story in only three books). While I enjoyed reading it and I know that Paolini had all the best intentions writing it, I would not recommend it.

I have too little recollection of the first two books, to tell you the truth, but I do remember I was captivated by the action in them, if nothing else. The "magical technology" also had a great lure for me. In the third installment, all of these are missing or of poor quality. Roran is far more interesting than Eragon in this book, while the bad characters have lost a few dimensions (from the few they already had) and have become pathetic. T'Pol (sorry... I meant Arya) is docile and closer to the human heart, making her completely uninteresting, while the elves in general (and Oromir and Glaedr in particular) act like Asgaard on pot.

Why use StarTrek and StarGate terms to describe a fantasy book? Because it seems that's the only real inspiration of the third book of the Inheritance cycle. I could have done without the Doctor Who references in it, as well.

You can see a little YouTube video of Christopher Paolini talking about Brinsgr here, where an "unofficial" fan club is trying to earn money from said YouTube by disabling the embedding option.

A few days ago a coworker asked me about implementing an autocomplete textbox with not only text items, but also images. I thought, how hard can it be? I am sure the guys that made the AutoCompleteExtender in the AjaxControlToolkit thought about it. Yeah, right!

So, I needed to tap into the list showing mechanism of the AutoCompleteExtender, then (maybe) into the item selected mechanism. The AutoCompleteExtender exposes the OnClientShowing and the OnClientItemSelected properties. They expect a function name that accepts a behaviour and an args parameters.

Ok, the extender creates an html element to contain the list completion items or gets one from the property CompletionListElementID (which is obsoleted anyway). It creates a LI element for each item (or a DIV in case of setting CompletionListElementID). So all I had to do was iterate through the childNodes of the container element and change their content.

Then, on item selected, unfortunately the AutoCompleteExtender tries to take the text value with firstChild.nodeValue, which pretty much fails if the first child of the item element is not a text node. So we will tap in OnClientItemSelected, which args object contains item, the text extracted as mentioned above (useless to us), and the object that was passed from the web service that provided the completion list. The last one we need, but keep reading on.

So the display is easy (after you get the hang of the Microsoft patterns). But now you have to return a list of objects, not mere strings, in order to get all the information we need, like the text and the image URL. Here is the piece of code that interprets the values received from the web service:
// Get the text/value for the item
try {
var pair = Sys.Serialization.JavaScriptSerializer.deserialize('(' + completionItems[i] + ')');
if (pair && pair.First) {
// Use the text and value pair returned from the web service
text = pair.First;
value = pair.Second;
} else {
// If the web service only returned a regular string, use it for
// both the text and the value
text = pair;
value = pair;
}
} catch (ex) {
text = completionItems[i];
value = completionItems[i];
}


In other words, it first tries to deserialize the string received, then it checks if it is a Pair object (if it has a First property) else it passes the object as value and text! If deserialization fails, the entire original string is considered. Bingo! So on the server side we need to serialize the array of strings we want to send to the client. And we do that by using System.Web.Script.Serialization.JavaScriptSerializer. You will see how it goes into the code.

So far we displayed what we wanted, we sent what we wanted, all we need is to set how we want the completion items to appear. And for that I could have used a simple string property, but I wanted all the goodness of the intellisense in Visual Studio and all the objects I want, without having to Render them manually into strings.

So, the final version of the AutoCompleteExtender with images is this: A class that inherits AutoCompleteExtender, but also INamingContainer. It has a property ItemTemplate of the type ITemplate which will hold the template we want in the item. You also need a web service that will use the JavascriptSerializer to construct the strings returned.

Here is the complete code:
AdvancedAutoComplete.cs

using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;

namespace Siderite.Web.WebControls
{
/// <summary>
/// AutoCompleteExtender with templating
/// </summary>
public class AdvancedAutoComplete : AutoCompleteExtender, INamingContainer
{
private ITemplate _template;

[TemplateContainer(typeof(Content))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate ItemTemplate
{
get { return _template; }
set { _template = value; }
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
const string script = @"
function AdvancedItemDisplay(behaviour,args) {
var template=behaviour.get_element().getAttribute('_template');
//if (!template==null) template='${0}';
for (var i=0; i<behaviour._completionListElement.childNodes.length; i++) {
var item=behaviour._completionListElement.childNodes[i];
var vals = item._value;
var html=template;
for (var c=0; c<vals.length; c++)
html=html.replace(new RegExp('\\$\\{'+c+'\\}','g'),vals[c]);
item.innerHTML=html;
}
}

function AdvancedSetText(behaviour,args) {
var vals=args._value;
var element=behaviour.get_element();
var control = element.control;
if (control && control.set_text)
control.set_text(vals[0]);
else
element.value = vals[0];
}
"
;
ScriptManager.RegisterClientScriptBlock(this, GetType(), "AdvancedAutoComplete", script, true);

OnClientShowing = "AdvancedItemDisplay";
OnClientItemSelected = "AdvancedSetText";
}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string template = GetTemplate();
((TextBox)TargetControl).Attributes["_template"] = template;
}

private string GetTemplate()
{
Content ph=new Content();
ph.Page = Page;
_template.InstantiateIn(ph);
HtmlTextWriter htw = new HtmlTextWriter(new StringWriter());
ph.RenderControl(htw);
return htw.InnerWriter.ToString();
}
}
}


MainService.cs

using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;

/// <summary>
/// Web service to send auto complete items to the AdvancedAutoComplete extender
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class MainService : WebService
{
[WebMethod]
[ScriptMethod]
public string[] GetCompletionList(string prefixText, int count)
{
JavaScriptSerializer jss=new JavaScriptSerializer();
List<string> list=new List<string>();
for (int c = 0; (list.Count< count) && (c < 100000); c++)
{
string s = (c*c).ToString();
if (s.StartsWith(prefixText))
{
object[] item = new object[] {s, "images/demo.gif"};
list.Add(jss.Serialize(item));
}
}
return list.ToArray();
}
}



An example of the use

<asp:TextBox runat="server" ID="tbMain"></asp:TextBox>
<cc1:AdvancedAutoComplete ID="aceMain" runat="server" BehaviorID="mhMain" TargetControlID="tbMain"
ServiceMethod="GetCompletionList" ServicePath="~/MainService.asmx" MinimumPrefixLength="0"
CompletionInterval="0">
<ItemTemplate>
<asp:Image runat="server" ID="imgTest" ImageUrl="${1}" /><asp:Label runat="server"
ID="lbTest" Text="${0}"></asp:Label>
</ItemTemplate>
</cc1:AdvancedAutoComplete>


That's it! All you have to do is make sure the controls in the template render ${N} text that gets replaced with the first, second, Nth item in the list sent by the web service. The text that will be changed in the textbox is always the first item in the list (${0}).

Restrictions: if you want to use this a control in a library and THEN add some more functionality on the Showing and ItemSelected events, you need to take into account that those are not real events, but javascript functions, and the design of the autocompleteextender only accepts one function name. You could create your own function that also call on the one described here, but that's besides the point of this blog entry.

and has 0 comments
A nice song I found myself humming today. I guess I had a reason for it. Hmm.


and has 0 comments
Zodiac is an environmental eco-thriller. It's Stephenson's second novel and it started in a similar way to The Big U, which I couldn't really read through. But I had nothing else to read so I kept going until it got funny and good. If you read it, try to get over the bad start, because it is not a bad book at all.

The basic plot is that of a pragmatic environmentalist with a chemistry background working against the waste dumping industry. In the end he uncovers a plot of global implications and, of course, foils it. But the story itself is more important than the ending. This is not one of those books you read in half a day, driven by the need to know how it all turns out, but one of those you read waiting to see what the main character is going to do or say next, while going towards the predictable finish.

Here is a much better commentary than mine, what I can say is that the book was definitely not sci-fi, rather a thrill-fiction, but it was well written. It makes for a good train book.

and has 0 comments
In this day and age, being or getting fat is treated like a drug addiction, in all sense of the word treated. Fat people are marginalised, socially pushed to find a solution. Many solutions are provided, from pills that help you lose weight to food replacement things and "health food" so that they can slowly get rid of this addiction to food. And in many respects, fat people are behaving like addicts. They have cravings, they find reasons for eating "just a little bite", they show withdrawal symptoms, they try quitting and they fail. There are also "pushers", trying their best to hook you on chips, sugary drinks, fatty meats and fast foods as well as food suplements and slim drinks.

The funny thing is that the actual solution to extra weight is the same as in the case of hard drugs: you want to get rid of heroin addiction, stop taking heroin. There is this slightly annoying fact that you can live without heroin, but you can't without food. But there are people working on it.

Anyway, I started writing this because, as far as I am concerned, I know I have found the solution. And it is not so hard to do it, either. I've started from 116kg, lost 16 in 4 months, started drinking Coca-Cola like crazy while keeping the diet, didn't gain much weight, then started eating a lot of pasty, bready, pizzy and fatty food and gained 10 kg in about 1 month and a bit, then I started a custom (less strict) diet again and got to 104kg in 1 month. In other words, even if I stop the diet, I have to make an effort to gain weight. Even if I slip a little, it doesn't matter. And if I make my own food style, one that avoids too much fat and bread and sugar, I don't gain weight, even if I stop the diet completely. It is way easier to gain weight than to lose it, but that is not the point.

Bit by bit, though.

You have to consider that this is not a weight loss blog and that I am only describing my experience here, but hey, it worked. From what I could gather there are three points that need covering:
  1. Don't gain extra weight
  2. Eat the right stuff to maintain your weight
  3. Keep your metabolism running to lose weight
. Pretty easy.

In order to not gain extra weight, eat less. A normal sedentary human needs about 2000 calories per day. We eat a lot more than that and a lot of it just goes out in the toilet. A small part (but significant to this blog entry) is stored as fat. By eating 1500 calories you get to stop gaining weight and start losing it. But how does one know what 1500 calories mean? Very simple: you get a list of what you are supposed to eat every day at every meal and you don't stray from it.

In order to maintain your weight even after stopping the diet, you need to eat the right stuff. I don't know exactly what that means, but guessing by the food I am allowed to eat and what I am not and what I Googled on the net, I found out that there is a separation of food types into alkaline and acidic foods. Supposedly, you need 75% of the first category and 25% of the latter. A normal Western diet is the other way around, hence the weight gain and the accumulation of fat. Also, the division of foods in these two categories seems to have nothing to do with pH, as lemons are considered highly alkaline. Probably the terms refer to the body's response to them. Also, you need to stay off carbo-hydrates. This is called a "low-carb" diet. Carbo-hydrates is a fancy word for sugars, but there is the good sort (like in fruits and a bit honey) and the bad sort (like refined sugar and refined flour products).

And last, but not least, eat many times a day. That is counter intuitive, but if you think about it, it makes a lot of sense. The human body is very adaptive. If you eat once a day, it will remember to shut off functions that use energy the rest of the day. Not to mention that you'll probably get an ulcer anyway. So instead of losing weight, you will lose energy. Even worse, when you start eating again, the body will just store it, since it is running in energy-saving mode. Instead, if you eat many times a day, your body knows energy is freely available and the metabolic rate will go up instead of down, helping you to burn reserves (fat).

Ok, enough theory. I will give you a general 1500 calory diet to follow every (fucking) day. If you get bored, read the part about the routine. Don't stop. Remember, I lost 16 kilos in 4 months and then I had to make an effort to put 10 kilos back.

So, there are 5 meals a day! breakfast, brunch, lunch, lupper (sorry, couldn't help it :) ), supper. You are allowed to drink water and green tea with no sugar only. Maybe coffee in the morning, but that's frowned upon :D.

Breakfast (7:00-8:00): 100g of low fat meat (like grilled chicken breast, fish, cremwurst (the thing in the hot dog), etc.) and/or low fat cheese (like mozarella or any low fat cheese). 100g in total. That means like 3 (slim) cremwurst sausages. Also a tomato and a cucumber (a normal cucumber, like the ones that are the total size of a tomato :) not the huge ones). You are allowed two slices of bread, not white, but wheat bread.

Brunch (10:00-11:00): 250g of fruit. Any fruit. Or 4-5 dried fruits.

Lunch (13:00-14:00): 150g of low fat meat (preferably grilled, else you start dreaming of warm meals) and a salad (tomato salad, green salad, boiled vegetables whatever. Use olive oil and as little salt as possible. Use lemon juice, not winegar). For example if you want to make yourself a tomato salad, you use 2 tomatos and a cucumber, some olive oil and lemon juice and a little salt. That's the size of a salad, not 4 kilos of tomatoes with mayo salad dressing. Two slices of wheat bread.

Meal between lunch and supper (16:00): 250g of fruit. Any fruit. Or 4-5 dried fruits.

Supper (18:30-19:30): 400g of yoghurt and/or low fat meat or salad. 400g in total, use at least 200g of yoghurt, though, it has enzimes that will help you during the night. Maybe replace the yoghurt with a less fatty soup. One slice of wheat bread.

That is it! You eat nothing else. You drink nothing else than water and grean tea. You avoid sugar as much as possible, onions and carrots and peas are sweet, too. No diet drinks or sugar-free chewing gum, they don't really help. Chocolate is a no no. Icecream is a crime. Alcohol deserves capital punishment. (well at least that's what the nutritionist told me).

My opinion of it? Well, things are not so bad. Remember that you cannot put more weight than what you eat. Even if you live by breathing air and you store everything you ingurgitate, you cannot gain 10 kilos if you only eat 1. Does your body store the Coca Cola drink you crave? No. But it uses that sugary goodness as energy and stores anything else you eat. Will you inflate like a balloon if you go to someone's birthday party and you eat a little cake and drink some champagne? Not really, unless people start looking at you funny while you are the only one eating the cake and there is not much left. This doesn't apply if you go to birthday parties every day!

And, remember, this is for a person that makes no physical effort whatsoever other than getting up each morning and going to work. Riding your bike at work or jogging or doing physical exercises will make this go even faster. They don't have to be difficult or complex. Finding your food in restaurants or shops is difficult, therefore you should prepare your lunch at home. That might look strange, to carry your own food, but weigh it (pun intended) against the purpose of your diet and the benefits of not being fat.

The thing is that after you reach your desired weight, you still have to keep up with this kind of eating. It keeps you fit. You can eat normal food, go to restaurants, drink sugary drinks and alcohol, but remember to balance it with the diet you just went through. Sugar and alcohol is somewhat like a really unhealthy fruit, fat is like a lot of meat, not eating vegetables is just not good. Your body is the result of evolution working on people who ate mostly plants and sometimes a little meat. Consider that when you order your double cheese hamburger and a diet Coke. Anyway, speaking of diet soft drinks, it doesn't really work. Drink the regular ones (unless you like the taste of the diet ones) just don't overdo it. It's the same with the food. Eat it rationally, even if you like to eat.

I felt no real feeling of hunger during this diet. The 5 meals a day thing keeps you full of energy and always with something in your stomach. You might feel hungry in the evening and then, if you reeeeeally find it hard to resist, drink a small glass of milk. Not regularly, just when you are really hungry. The milk makes your hunger go away, but also keep your body from losing weight.

The Routine

Well, you noticed it. The whole diet is based on daily routine. It might drive you crazy for a while, but consider that you have been doing it anyway. You wake up in the morning, wash, piss, drink the ritual coffee or whatever, get dressed, go to work, do the same thing you do every fucking day, return home and watch TV or spend "quality time" with the wife or play some silly game on the computer or even work part jobs. Then you go to sleep. It's a routine.

All you need to do is alter it a little to suit your needs.

People worst than you have done it. People incarcerated and tortured every day found solace in the real life inside their heads while living the reality in a state of trance brought on by routine. Routine is the basis of one's comfort. You only explore when you leave your comfort zone. You can do it "in your free time", if this mythical thing even exists, or just in your head, while your body is running the automated program you set up. Now I am not really talking about losing weight here, I am going general. The thing that keeps everyone content and not going crazy is not the quality of life, but the routine of it. We train ourselves to function in the given conditions.

Talking about drugs you cannot not talk about Trainspotting. The film that old people took as a drug promoting movie while for all the people that actually watched it, it was a powerful anti-drug statement. There is this part of the movie where Renton tries to quit heroin and he just hates his life. It's not because of the withdrawal symptomps, but because of the sheer boredom of it. When something that defines your pleasure is taken away, when the excitement is gone, your life feels like a slow death. It's easy to just go back to the pleasure you know. Even if it is just as boring, it feels good. But routine is what saves your ass.

The same applies to food. You dream of all the possible combinations of taste and texture and what you would do if you weren't on the diet. You don't feel hungry, you see, you don't need food, you need the pleasure of it. You want to fuck that food with your mouth and make it cum saliva. But it's all fake. When you slip and try to eat that food you realise that the fat you craved makes you feel sick, the food you want may be not on the diet sheet, but you can just about make it with those ingredients. You don't need junk food to eat good. And that is what this is all about after all. You get healthier by adjusting some parameters, not by losing something. Even if you can't lose all the weight you wanted, who gives a damn if you are still a little fat? You are a healthy fat guy! Not a morbidly obese piece of blubber that just waits miserably for their coronary.

So stick to the routine. Experiment with food while keeping to the principles of the diet when you get out of it. Stay in the comfort zone and leave it for short periods of time when you feel good about yourself. Choose your next stage of development and get to it when you feel like it.

Now I sound like those people trying to sell you stuff. I wanted to write this for a long time, mostly because I had to explain all of this to a lot of people over and over again. Now I have this post, you can read it here. I guess the bottom line is that your body as well as your brain is always in training mode. Whenever you do something that feels good, you train it to want more, whenever you do something that feels bad, you train it to want less. So it is your responsability, after all, to choose the things that make you feel good.

Usually when I blog something I am writing the problem and the solution I have found. In this case, based also on the lack of pages describing the same problem, I have decided to blog about the problem only. If you guys find the solution, please let me know. I will post it here as soon as I find it myself. So here it is:

We started creating some tests for one of our web applications. My colleague created the tests, amongst them one that does a simple file upload. She used the following code:
var fu = ie.FileUpload(Find.ByName("ctl00$ContentPlaceHolder1$tcContent$tpAddItem$uplGalleryItem$fuGalleryItem"));
fu.Set(UploadImageFile);

and it worked perfectly. She was using WatiN 1.2.4 and MBUnit 2.4.

I had Watin 2.0 installed and MBUnit 3.0. Downloaded the tests, removed the ApartmentState thing that seems not to be necessary in MBUnit 3.0, ran them.
On my computer the FileUpload Set method opens a file upload dialog and stops. I've tried a lot of code variants, to no avail; I've uninstalled both MBUnit and WatiN and installed the 1.2.4 and 2.4 versions. Tried all possible combinations actually, using .NET 1.1 and 2.0 libraries and changing the code. Nothing helped. On my computer the setting of the file name doesn't work.

I've examined the WatiN source and I've noticed that it used a FileUploadDialogHandler that determines if a window is a file upload window or not by checking a Style property. I have no idea if that is the correct solution, but just to be sure I inherited my own class from FileUploadDialogHandler and I've instructed it to throw an exception with a message containing the style of the first window it handles. The exception never fired, so I am inclined to believe that the handler mechanism somehow fails on my computer!

I have no idea what to do. I have a Windows XP SP3 with the latest updates and I am running these tests in Visual Studio 2008 Professional.

Update:
The only possible explanation left to me is that Internet Explorer 8 is the culprit, since my colleagues all have IE7. The maker of WatiN himself declared that identifying the windows by style is not the most elegant method possible, but he had no other way of doing it. My suspicion is that the window handling doesn't work at all in IE8, but I have no proof for it and so far I have found no solution for this problem.

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.

and has 0 comments
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.

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.

and has 1 comment
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.

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.