Tuesday, September 26, 2006

MSN messenger random picture issue

For as long as I can remember, the MSN messenger changed my picture in a random fashion. I was setting it, then at the next restart, another was there. The last version I am using is 7.5.
Today, I finally found out what caused it: Tools → Options → Security → "This is a shared computer, so don't store my address book, display picture or background on it".
It is nice to know that if I want to keep the same picture on the messenger I have to also store my address book on the computer. Microsoft seems to think they are of similar importance :-/

Monday, September 25, 2006

Sunday, September 24, 2006

Osama bin Laden, a modern Hannibal?

Spurred by two TV shows about two famous people, I came to the conclusion that Osama bin Laden's history has a lot in common with the one of Hannibal Barca, the Carthaginian general, just as the history and technological development of the US has a lot in common with the Roman Empire.
Think about it!
Hannibal was born in Carthage, but he left it when he was nine years old. He hated the Romans with all his being and when he attacked their empire (which then span the Italian peninsula) he did it by hitting targets deep within their teritory. Using innovative strategy, he defeated the strong Roman army by using its flaws: size, but no coordination; force, but not precision. With a small mercenary army that also used elephants, he surrounded the huge Roman army and destroyed it. He then demanded support from Carthage, in order to siege and capture Rome, but the politicians of that state decided that it would be safer to not antagonize the Roman Empire and didn't sent support. Powerless to set siege to Rome, Hannibal could do nothing but watch how the Romans build another army which will then defeat him. In order to avoid capture, after years of exile, he commited suicide.
Osama didn't leave Saudi Arabia from childhood, but he was exposed to the teachings of returned exiled teachers, who brought different ideas. He came to hate the Americans and when he attacked them, he struck deep within their teritory. Using innovative strategy he defeated the US antiterrorism machine by using their flaws: size, but no coordination; force, but bureaucracy. With the smallest of terrorist groups that also used air elephants (heh, I stretched it out a bit, but it holds), he struck a major blow to the confidence of the US. He then demanded support from the Arabic nations, which decided to not antagonize the American Empire. We all know what happened to the ones that did. Powerless to continue his campaign, Osama watched as the US machine learned from its mistakes, rebuilt it's antiterror army and then defeated him. After years of exile, he dies, avoiding capture through death.
Now, what it even more interesting is that Hannibal's actions led to the expansion of the Roman Empire into Iberia and Carthage and the refining of their army and war strategy. This eventually led to the Roman Empire conquering so much and becomnig the most famous and technologically advanced civilisation of its time. Carthage was completely raised from the surface of earth, destroyed by Romans and plowed clean. If we were to continue these parallels, the American Empire should now have a more powerful and precise war machine, it should conquer or at least neutralize any threat from the Arab nations, then proceed on conquering the world. Some poor country should take the blame, as Carthage did for Hannibal, and be completely ravaged by war. Does it sound familiar? Brrrr...

Other related links from people that had similar ideas:

There are even more links, in total Google showed 573 links that contained Osama bin Laden, Hannibal and not L*ecter. But since people spell Osama differently, others make it clear that it's not the guy from the movie, thus causing false positives and there are a lot of sites that just enumerate famous people, the count cound be completely different.
Happy thinking!

Tuesday, September 19, 2006

God is a brand

It was one of those moments when you think of nothing and suddenly something distillates into conscience. It sounded too good and too important not to find it on the net so I googled for "God is a brand" and I found 17 entries out of 98.200 (yes, Google is getting weirder and weirder).
Now, when it hit me, it seemed like something really smart, but now I understand it is just obvious; I was the dumb one for not getting it sooner. People don't have holly wars on Linux vs Microsoft, they are having brand wars on Jesus vs Mohamed.

What started me is looking for furniture for my new rented apartment (expect a huge blog in a few days) and I found the same models in two different places, but with two different prices. My wife said that it was because the more expensive ones were better made, but they really weren't.
Then I realised that most commerce is run on brands, it's nothing new, it goes on from the beginning of trade. You buy from where you know it's good, or from where stuff makes you look or feel good. People are attached to the spirit of the thing, not the thing itself (well, most people). The Stradivarius violin can be made better and cheaper using modern computer modelling and automated manufacturing, but people care about the original Stradivarius, made by a human, a human that represents something. The enormous price of Stradivarius violins is not due to their utility, but the faith of the people in the original builder, the artist. Ring a bell? Original artist? The Creator? Yes! God!
The epiphany came when I explored the idea in my mind. People doing idiotic things because of their faith, the experiment where people were given to wear a t-shirt for 10$ and refused to do it when they heard it belonged to a serial killer or the one with the children that were given a "perfect replica" of an object that they loved and they prefered the original or the simple superstitions like avoiding number 13. Movies, as well, usually portray clones as imprefect, evil, empty of true purpose or life. People remain married for decades, respecting and even loving the other person, when all rational motives to stay together have withered in time. Of course, this is also linked to the way human instincts work, but nevertheless, there are people who do it and people who don't.
Somehow, the intricate mechanism of the brain puts values on associations rather that on the objects. I think this is important. It is obvious that people have inner representations of different things and people, but I've always assumed that the inner value is put on the thing not on the associations. I now believe to have been wrong. It makes sense: there is no absolute value, only when you put something into context it reveals its value.

Therefore, returning to the God is a brand issue, it seems to me that the branding is made on oneself. You don't buy the product, you become the product. You brand yourself with a god, then act in accordance with its meaning. Then losing one's faith would be like becoming an clone of yourself, empty of meaning. It could explain the feeling of loss of a person, when "there are other fish in the sea". It makes old people be grumpy, since no one truly understand the different deep meanings that they've attached to objects and people and behaviours.

I can't even ask myself "Do brands suck?". It would attack a defining feature of humans AND animals alike. This warrants a look into the idea of religious feeling in animals. It is not possible for everything to suck. Religion sucks, though.

Monday, September 18, 2006

ASP.NET 2.0 Parser Error Message: Access to the path '[something.cs]' is denied

I was stunned today to see that a site that I was working on was not starting because of this idiotic error:
ASP.NET 2.0 Parser Error Message: Access to the path '[something.cs]' is denied.
And further down:
No relevant source lines

The only thing I remembered doing was close the project in Visual Studio and work on another. I tried starting the site with the URL, without loading it into Visual Studio and the error occured. If you search on the net this error, you will see that there are a lot of articles that talk about the ind*exing ser*vice, but I stopped it a long time ago. So what was going on?

  • The file was accessible

  • The file was not opened by another application

  • I could freely delete/remove/modify the file



In desperation I compared the Security settings for this file with other files in the directory. To my surprise, there was a major difference. The files that were accessible had a lot of users with access rights to them, the file that gave the error had around three.

I have no idea what caused this. I just copied the same rights from the other files to the problematic one and it worked. I am using Visual Studio 2005, Resharper and SourceSafe. Do you also hear the Twilight Zone soundtrack?

Friday, September 15, 2006

Programatically trigger event in Javascript

It's is done in two different ways: the IE way and the DOM way.
IE way) really simple, use element.fireEvent(eventName,[eventObject]), where element is a HTML element and eventName is something like "onclick";
DOM way) really complicated. A short example:

function simulateClick() {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var cb = document.getElementById("checkbox");
var canceled = !cb.dispatchEvent(evt);
if(canceled) {
// A handler called preventDefault
alert("canceled");
} else {
// None of the handlers called preventDefault
alert("not canceled");
}
}

As you can see, you need to create the event, then initialize it, then dispatch it.

    Things you need to take care with:
  • in the DOM model the event name is not prefixed with "on". In the IE way, the event is prefixed with "on". ex: DOM:click IE:onclick.

  • in the DOM model the event triggering does everything the event would have done, like setting a value, in IE it does not. ex: triggering onclick in the above example would check or uncheck the box. In IE you need to change the value yourself.



This is code I did to programatically click a checkbox and also trigger the onclick event:

if (box.onclick)
{
if (box.dispatchEvent) {
var clickevent=document.createEvent("MouseEvents")
clickevent.initEvent("click", true, true)
box.dispatchEvent(clickevent)
} else
if (box.fireEvent) {
box.checked=!box.checked;
box.fireEvent('onclick');
} else
box.onclick();
} else box.checked=!box.checked;

Wednesday, September 13, 2006

Tuesday, September 12, 2006

Debugging Javascript with Visual Studio or other tools

Yes, you've read right. You can debug Javascript with Visual Studio. Here is a blog entry that blew my mind when I've read it: JavaScript Debugging.

Basically, what needs to be done is first go to Internet Explorer Options and disable Disable Script Debugging (Internet Explorer) (No, I didn't mistype, there is a checkbox that needs disabling and it's called Disable...) in the Advanced section. Be careful not to disable the other script debugging box, only the Internet Explorer one. Then, when an error occurs, the system asks you what debugger to use. You can choose Visual Studio 2003 or 2005 from the list (provided you have them installed :) ), trace, put breakpoints, etc.

There is also the javascript debugger keyword, which fires a debugging window at the specific location, so it's like a breakpoint.

Googling the net I've found that there are both free and commercial Javascript debuggers. There is even a free one provided by Microsoft: Script Debugger for Windows. One, unfortunately shareware, product that I saw recommended on the forums is 1st JavaScript Editor.

The only disadvantage to this, that I've seen, is that any javascript error will result in opening the debuggers window, without the ability to check "ignore errors on this page" or anything like that. It could be annoying while browsing. Yet I am surprised that I've heard of this method of Javascript debugging only now.

Update:

If it seems the list of debuggers does not appear anymore (or never did), go to Visual Studio Tools -> Options -> Debugging -> Just-In-Time and check the "Script" checkbox.

If it seems Visual Studio doesn't correctly find the right Javascript line to debug when entering debug mode, start the web site without debugging and then choose Microsoft Script Debugger. It gets the current line right, but has a difficult to use interface (Hint: use the Command Window). Of course, you have to download and install it first :).

CSS Friendly ASP.NET 2.0 Control Adapters

CSS Friendly ASP.NET 2.0 Control Adapters is a little project run by Brian Goldfarb and what it does is use the power of the ControlAdapter object to change the way ASP.NET controls get rendered. They use CSS layout to control the way things look and try to remove the old table based format.

While this could be a good thing in some situations, it could be harmful in others like low resources or weird changes in the CSS laws. I let you decide for yourselves. And while the ControlAdapter approach is very elegant, I've used this concept in creating my own controls when needed by overriding ASP.NET classes and using simpler code. Also, these Control Adapters are in Beta 2 stage. Major changes are still in the works.

So don't trust it blindly, but do check it out, as it is a worthy and honorable quest :)

Monday, September 11, 2006

Friday, September 08, 2006

Ring of the Lords

I am used to commenting on the things I see in life. I do the comments on movies on IMDb, but I haven't made an account on iblist, since I read so ridiculously few books that are not technical and IbList doesn't seem to be so complete and organised as IMDb.
So I will blog about books until the time when I see myself worthy of an iblist account.

Spurred on by a need for fantasy I've just finished Lord Foul's Bane, by Stephen R. Donaldson. Remarcably well written, it is obviously inspired by Tolkien's Lord of the Rings. There are lords, there are rings and there are brave and honorable quests. At times this becomes annoying, when characters feel compelled to sing songs (and the author actually wrote the lyrics in the book) or sacrifice themselves in rather ridiculous ways. I didn't like the way Lord of the Rings was written because of all the useless details in it. Lord Foul's Bane, the first in the Covenant series, is a bit like that, but not as bad. The main character, Thomas Covenant, is also most interesting than Frodo, having come from our world and being full of pain. Unfortunately, in the most important parts of the book, Covenant does things as moved by a puppeteer rather than by his own logic and good sense. This makes the plot seem a bit too unreal. The fantasy world, though, is pretty well done, with sensible magic and purposely made to look like a mirror image of our own, with all the bad things in our world not present and (I would say) all the good things being bad there. Like stopping from your journey and starting singing songs that are sometimes labeled as gay in the book.

I've also finished the first two volumes of The Spook series (The Spook's Apprentice and The Spook's Curse), by Joseph Delaney, which is interesting and well written. In this one, a feudal world is plagued by evil witches, ghosts and banes. The man that takes care of this, like a Dark Ages ghostbuster, is a spook. He does the job that no one wants to do, everyone needs him, yet everyone hates and fears him, including and especially the Church, which in this series are portrayed as a bunch of corrupt and amateurish incompetents. The main character is a young child who, under the guidance of his more than ordinary mother, becomes a spook's aprentice. There are twists in the plot and the magical domain is well conceived. Unfortunately, the plot is rather straightforward, with young useless brat finding out he has unsuspected power. But they don't call it heroic fantasy for nothing, so , there it goes. I liked the series and I expect to read the third book (The Spook's Secret), released this year, as soon as I find it.

I've also read the first two Eragon books. While the fantasy world is very complex and well written (especially taking into account the age of the writer) the magic "technology" is a bit hard to wield. I hope the author refines the way it works in ways that don't turn ridiculous. Christopher Paolini is a young American writer of Italian origins, born from a wealthy family of book editors. He started writing Eragon at 15 and finished it at 19. It should come to no surprise that the book became a huge hit; it is well written, but the marketing of the book was intense and privately funded by the author's family. There is an Eragon movie due to be released in 15 of december this year.

A quick mention of Christopher Stasheff, a rather prolific fantasy writer, who tries a combination of magic and space science-fiction. Unfortunately I couldn't finish his first book (Escape Velocity), the first of the Warlock of Gramarye series, as I found the writing style rather annoying. I've read good reviews about his latest books, though, and I plan on starting a bit further up, maybe with the Rogue Wizard series.

The end. :)

Wednesday, September 06, 2006

How to format your GridView autogenerated columns

The GridView is nothing more than an oversized DataGrid. The internal concept is completely rewritten, as far as I see, though. For example, Columns are not called columns anymore, they are DataControlField. Well, I stumbled upon one situation where I needed to format the autogenerated columns in a GridView. Normally, you could take the Columns collection and change the DataFormatString property for each column, but autogenerated columns (or AutoGeneratedField) are not part of the Columns collection. More than that, AutoGeneratedFields are nothing more than BoundFields with lots of useless restrictions on it like being a sealed class and throwing errors when trying to change some properties (like DataFormatString).

The first step is getting hold of the autogenerated column. Luckily the GridView control has a virtual method called CreateAutoGeneratedColumn which returns a AutoGeneratedField. So create a control that inherits GridView, override this method, take the generated field in the base method, change DataFormatString. I couldn't find any way to do that except with reflection. I noticed that the value of the DataFormatString property was stored in the ViewState of the AutoGeneratedField, so I used reflection to get to it, then I changed the value.

This is the code:
protected override AutoGeneratedField CreateAutoGeneratedColumn(
AutoGeneratedFieldProperties fieldProperties)
{
AutoGeneratedField field =
base.CreateAutoGeneratedColumn(fieldProperties);
StateBag sb = (StateBag)field.GetType()
.InvokeMember("ViewState",
BindingFlags.GetProperty |
BindingFlags.NonPublic |
BindingFlags.Instance,
null, field, new object[] {});
sb["DataFormatString"] = "{0:N}"; //or the format string you prefer
field.HtmlEncode=false; //see update
return field;
}


Update:
The BoundField object formats values differently depending on html encoding. If the html encoding is enabled, then the value is transformed into a string, then the formatting is applied. That means that number formatting will NOT work when html encoding is true.
That is why I've added the field.HtmlEncode=false; line above. A more secure option would be to make the HtmlEncode property depend on the field.DataType.

Update2:
While this works, I don't recommend doing it like that. I am using it because I have custom user controls that inherit from the GridView and I need to cover the AutoGeneratedColumns=true case. It is much easier to generate your columns yourself from the DataSource using BoundField objects (Or any other DataControlField objects) that you add to the GridView.Columns collection.

Street sweepers suck!

Welcome to another lesson in suckology! Today's topic is Manic Street Sweepers from Hell (or Bucharest).
When the weather is good I go to the office by bike. Yeah, I am a hot shot biker. My bicycle is state of the art junk and I can ride it even through major Bucharest street holes. Ok, I am being a bit unfair, as they are rebuilding all the streets now... So let me rephrase it: I can ride it even through destroyed streets that are in the process of being rebuilt.
When I first bought my bike it had no wheel protectors and I quickly realised that driving through wet or muddy terrain tended to leave a long straight line of wet dirt from my trousers bottom to the top of my head. So I bought these metal things that protect my wheels and myself from things like that. Now I can even go through moderate puddles and I only wet the bottom of my pants legs. Which is ok, I am tech guy, I'm married, I don't really need to look good. You did sense the irony there, right?
So everything was set for riding my bike. I could even hear the Queen song while going to work. To my immediate surprise I found the streets were wet! Not only in the morning, when I go to work, but also in the evening when I return. The culprits seem to be [echo]Street Sweepers!

Ok, a small technical paranthesis. All this is done to protect the mighty citizen from dust. Or so they say, actually, this is more of a EU directive or standard and, as we Romanians love to brown our noses, the City Hall felt compelled to comply. Street sweeping, in theory, should be done to clean the street of debris (by using machines with brooms) which also employ some system to keep the dust from rising up while brooming. Most employ water, the most advanced use vacuum generation and filtration.

Well, Romanians decided to split this process into two separate parts: one machine wets the street, the other sweeps. Even better, while one wets one street, the other sweeps another. The result is dry sweeping that generates immense quantities of air borne dust and wet pavement. As you might not be familiar with Romanian technology, let me explain to you what these street wetters looks like: big water containers with sprinklers. And not your average street wetter sprinkler system with a row of small water sprays, but one big water pipe with holes in it!
What this does is create huge puddles of water in the crossroads, where the trucks stop, but the drivers are too lazy/stupid to also stop the sprinkler system. Also the roads are far from flat, so in all the little depressions in the asphalt other puddles occur.

Well, how does this affect me and why these abominations suck? Let's take them one at a time:

  • water makes my bike skid on the pavement. While this might be acceptable in other countries, with flat roads, maybe even with bicycle lanes, in Romania you have roads with waves, especially on the sides, no bicycle lanes (and the only one in Bucharest is used by old people to walk on) and the sewers are right in the pavement, they look like big square 5-10 cm deep holes. So, if on bicycle, you might want to break from time to time

  • water makes cars skid on the pavement. It's actually called hydroplaning, when the water goes between the car wheel and the road. Some drivers might want to control or at least stop their car when they wake up and see they're on a collision course with a bike.

  • new research shows that water on the pavement elevates the temperature comfort level, making it even easier to affect oh, let's say, people that drive on the said roads when the heat is up and don't have air conditioning in their car. Or a car.

  • there is no way to get around a street wetter with the bike. The only solution is to wait until all the cars go past it, then go all around the other side of the street to avoid getting sprinkled. Luckily, these dumb ugly beasts are slower than my bike.



My obvious conclusion is: Street sweepers suck!
I am citing from a random link: PM-10 / PM-2.5 class street sweepers are in a developmental stage. This type of sweeper will pick up dust particulate down to 10 micron is size. The city's Envirowhirl PM-10 street sweeper utilizes a combination of mechanical and air sweeper features to pick up debris. They also utilize an internal system of dry filters to retain all dust larger than 10 microns within the sweeper's hopper. No water is used for dust control.
I hope they bring something like this in Bucharest soon and that it doesn't suck. Much.

Monday, September 04, 2006

Crocodile Hunter Steve Irwin dies

'Crocodile Hunter' Irwin killed

An incredible and sad news for me, Steve died from the sting of a stringray that (ironically) has venom with no lethal effect on humans. The barb on the end of the fish tail has up to 20 cm and it probably penetrated the heart or has hurt some other major organ in the chest area. Steve is the second man ever to die from a stingray in Australia, the previous death being in 1945. Ironic, stupid, sad.
It is amazing that his death affects me so much, when other big people's deaths have only made me a little sad. Maybe it's because he was young, in the middle of his life, having so much to look forward to. I've also admired his insane passion. I am rarely passionate about something and I admire any person that can shine a little, like Steve seemed to do 24 hours a day.
At least his memory will remain intact from the ravages of old age. My deepest condoleances to his wife and two children.

Saturday, September 02, 2006

Programming vs. Software Development

You know the annoying feeling when you want to find something on the net and you can't find the proper search keywords? It's like trying to find the Triple X movie rather than porn flicks. It happends a lot when you want to find something that you know is named in some way, but a new buzz word is emerging and you either don't find everything you need or you find a lot of unrelated stuff. Like trying to find people talking about computer programming, but you end up with all these TV programming sites. Now try to find how to turn your PC into a TV by programming :).

Anyway, searching on programming led me to wonder about the difference between programming and software development in describing my own job. As previously mentioned, there are other sorts of programming and development except computer ones and to top it all, people mean different things when using these concepts in the software context. Wikipedia, for example, takes "programming" and gives me the page for "computer programming". It then takes software development and takes me to software engineering (which in my mind are different things).

How does google see this? Let's search:
TermPage count
Software development175.000.000
Programming858.000.000
Computer programming19.700.000
Software engineering80.700.000
 
Software developer27.400.000
Programmer156.000.000
Computer programmer4.270.000
Software engineer22.500.000
Developer1.030.000.000

So it seems that there is a lot more programming and programmers than software development or software developers, but add "computer" in front and there is less. But that's because no one bothers to say "computer" in those cases.

And there is more. While software development/engineering start to go towards "designing programs", computer programming goes towards "typing code". I believe that is happening because in large software companies there are a lot of people writing code, but very few that actually have a say on how the program is to behave or what technology to use. I am watching Microsoft presentations and they are ridiculing the "old school" programmers that type their code while the new breed of software developers point, click, drag, drop and everything works in a few minutes. People that actually think through what algorithms to use and how it all works and optimize lines of code and try to think like a compiler from time to time are grunts to be enclosed in cubicles, while those who think how the general program should work, create UML diagrams of interacting business objects are the lords of their domain.
That makes no sense to me, especially since the drag and drop people use software delveloped by code typers. Or it does make sense in the way that software development has become a feudal industry, like most industries become shortly after they become mass consumed. They have an elite, a clique that behaves like aristocracy, while most members of that industry work their asses off in the employ of these people. This gives a whooole new meaning to the term software revolution :)

So what is this job that I am performing? Am I just a meta-computer? Something high level that understands what it must do and obeys blindly by using a computer? Why is it that I like to code? Is there a difference in my mind between software and a program, so that the term software developer scratches my ears while programmer boosts my ego? And why do most people feel the other way around?

These are questions that I will probably be asking for a long time. Meanwhile, take a look at this wikipedia page, which I found informative: Programming paradigm. Also, consider this little link: Javascript 3D where you can find the explanation on how to do a Wolfenstein like game in Javascript, with only 5 kilobytes of code. You might want to wait a bit until it loads completely or use Mozilla Firefox. I noticed it works faster. Can't believe it? Check it out! That's what programmers do!