Today a new AjaxControlToolkit was released. I had hoped that at least they noticed the patch I made the effort of sending them, the one that fixed the dynamic TabPanel issue. But no. Three more controls and probably most of the same old bugs.

Here are more details: New release of the Ajax Control Toolkit

and has 0 comments
I don't pretend to know much about mathematics, but that should make it really easy to follow this article, because if I understood it, then so should you. I was watching this four episode show called Story of Maths. Its first episode was pretty nice and I started watching the second. The guy presented what he called the Chinese Remainder Theorem, something that was created and solved centuries before Europeans even knew what math was. It's a modular arithmetic problem. Anyway, here is the problem:

A woman selling eggs at the market has a number of eggs, but doesn't know exactly how many. All she knows is that if she arranges the eggs in rows of 3 eggs, she is left with one egg on the last row, if she uses rows of 5, she is left with 2 eggs, while if she uses rows of 7, 3 eggs are left on the last row. What is the (minimum) number of eggs that she can have?
You might want to try to solve it yourself before readind the following.

Here is how you solve it:

Let's call the number of eggs X. We know that X 1(mod 3) 2(mod 5) 3(mod 7). That means that there are three integer numbers a, b and c so that X = 3a+1 = 5b+2 = 7c+3.

3a = 5b+1 from the first two equalitites.
We switch to modular notation again: 3a 1(mod 5). Now we need to know what a is modulo 5 and we do this by looking at a division table or by finding the lowest number that satisfies the equation 3a = 5b+1 and that is 2. 3*2 = 5*1+1.

So 3a 1(mod 5) => a 2(mod 5).

Therefore there is an integer number m so that a = 5m+2 and 3a+1 = 7c+3. We do a substitution and we get 15m+7 = 7c+3.

In modular that means 15m+7 3(mod 7) or (7*2)m+7+m 3(mod 7). So m 3(mod 7) so there is an integer n that satisfies this equation: m = 7n+3. Therefore X = 15m+7 = 15(7n+3)+7 = 105n+52

And that gives us the solution: X 52(mod 105). The smallest number of eggs the woman had was 52. I have to wonder how the Chinese actually performed this calculation.

Let me summarize:
X 1(mod 3) 2(mod 5) 3(mod 7) =>
X = 3a+1 = 5b+2 = 7c+3 =>
3a 1(mod 5) =>
a 2(mod 5)=>
a = 5m+2 =>
X = 15m+7 = 7c+3 =>
15m+7 3(mod 7) =>
m 3(mod 7) =>
m = 7n+3 =>
X = 15(7n+3)+7 = 105n+52 =>
X 52(mod 105)
.

For me, what seemed the most hard to understand issue was how does 3a 1(mod 5) turn into a 2(mod 5). But we are in modulo 5 country here, so if 3a equals 1(mod 5), then it also equals 6(mod 5) and 11 and 16 and 21 and so on. And if 3a equals 6(mod 5), then a is 2(mod 5). If 3a equals 21(mod 5), then a equals 7(mod 5) which is 2(mod 5) all over again.

I have been working on a silly little project that involved importing files and then querying the data in a very specific way. And I wanted to do it with the latest technologies so I used The Entity Framework! (imagine a little glowing halo around that name and a choir in the background).

Well, how do I do an efficient import in Linq to Entities? I can't! At most I can instantiate a lot of classes and add them to the DataModel, then SaveChanges. In the background this translates to a lot of insert statements. So it occurred to me that I don't really need Entities here. All I needed is good old fashioned ADO.Net and a SqlBulkCopy object. So I used it like that. A bit of unfortunate translation of objects to a DataTable because the SqlBulkCopy class knowns how to import only a DataTable and I was set.

Ok, now back to the querying the data. I could have used ADO.Net, of course, and in this project, I would probably have been right, but I suspected the requirements for the project will change so I used Entities. It worked like a charm and yes, the requirements did get bigger and stranger as I went. But then I had to select the users that have amassed a number of rows in two related tables (or use a value in the user table) but only if the total number of amassed rows would satisfy a formula based on a string column in the user table that mapped to a certain value stored in the web.config a complicated query. I did it (with some difficulty) in Linq, then I had to solve all kind of weird issues like not being able to compare a class variable with an enum value because the number of types that can be used in a Linq to Entities query is pretty limited at the moment.

Well, was it the best way? I don't know. The generated SQL is something containing a lot of select from select from select sometimes 6 or 7 levels deep. Even the joining is done with select from tables. Shouldn't I have used a stored procedure instead?

To top it off, I listened to a podcast today about Object Databases. They do away with ORMs because there is no relational to begin with. The guy argued that if you need to persist objects, wouldn't an Object Database be more appropriate? And, as reporting would be a bitch when having to query large amounts of tabular data, shouldn't one use a Relational Database for this particular task in the project?

So this is it. It got me thinking. Is the database/data access layer the biggest golden hammer out there? Are we trying to use a single data access model and then build our applications around it like big twisting spaghetti golden nails?


Well, this is a time of great change in my life. First I had to give my cat away, due to medical reasons. I had him for more than 5 years and I really liked him. Now he is living in the countryside, with my parents in law, trying to get some pussy (sorry, couldn't help it :) ) and getting beat up for it by sturdy country female cats.

A few months after I got the cat, I also got a new job, prompting me to write my first blog entry. I was saying then that I am starting my first real software developer job in an Italian company. Now, after almost five years, I am giving away my cat and also changing jobs.

My new company is (hopefully) a place where I can accelerate the rate of my learning and professional development and I will be working there on a Windows desktop WPF+WCF+WF+Entity Framework application. So expect a lot of blog entries about new (for me) technologies. I will be starting work there on the first of June.

On the other hand I don't know if it would be permitted (or I would have the time) to stay available for chat on the blog, so if I don't answer, it's probably because I can't.

Wish me luck, everybody!

and has 0 comments
Here is a fun little site called Wordle. It allows the graphic creation of a compact word cloud. Unfortunately it doesn't seem to take into account the counts for the words.

and has 0 comments
After a very long wait, one destined to only increase expectations on this movie, the second adolescent Naruto movie, Bonds, reached me. Well, as with any high expectations they were destined to breed disappointment, but I think beyond that, this movie was bad in an objective way.

I mean, yeah, Sasuke and Naruto meet once again in the face of the most pathetic enemy yet. They didn't even try with this one. After a sneak Pearl Harbour attack from some weird ninjas, a four people team kicks their asses completely. Meanwhile, Naruto is fighting with Reibi, the 0-tails (I know Japanese are masters of zero-based numbering and logic, but this is ridiculous) and the master of Dark chakra. Guess what? He kicks their asses. But it was so ridiculously easy. Was Sasuke even required?

On the emotional level, it was like an atom bomb. I feel I can do anything, so I do it. And that's it. Big bang, no subtlety whatsoever. Not that Naruto is known for subtlety, but there are limits.

And on the animation... it all seemed so mechanical, unchiseled.

Bottom line: bad movie. Even worse since I waited so long for it. I can imagine a two episode mini arch in the series doing the same job, but better. It's not unwatchable, just disappointing. :(

You know how difficult is to test a web site on the many (conflicting) versions of Internet Explorer browsers that were created. While most of us don't even bother to test for anything lower than IE 6.0, there are major differences between IE6, 7 and 8. I used to use something called MultipleIEs before that contained IE versions up to 6, but now I found something that looks even better: IE Collection, boasting IE versions up to and including Internet Explorer 8.0.

I have installed it and so far I had no major issues with it. It does seem to change some part of the default IE configuration, so take a look there after you finish installing it.

A while ago I wrote a little post about pandemics. I was saying then how little we know about them and how little we are taught about disease outbreaks as opposed to, say, war. This post, however, it about the reverse of the coin: mediatization of pandemic fears.

I was watching the news and there was this news about a swine flu pandemic in Mexico. Thousands were infected, more than 100 people dead and the disease had already spread in the entire world and it was impossible to contain. Gee, serious trouble, yes? I had to stay informed and safe. (see the twisted order on which my brain works?)

So I went directly to the World Health Organization site and subscribed to their disease outbreak RSS feed. And what do I read? 27 cases of infections and 9 dead. Come again? They said 150 dead on the news. The news can't possibly lie! It must be either a) a US site where they only list US citizens b) a machination so that people don't panic when the situation is so obviously blown. [... a week passed ...] I watch the news and what do I see? The reported death toll from the swine influenza strain has dropped to about 15 people. False alarm, people, the rest of those 150 people actually died of other unrelated stuff. So the WHO site was right after all, maybe it having to do with the fact that they work with data, not viewer rates. Hmm.

The moral of the story? My decision to stop watching TV is a good one. Get the real genuine source of information and "feed" from it. I am now subscribed to the new disease outbreaks feed and the earthquake feed and I feel quite content in that particular regard.

That doesn't mean the "Swine" flu is something to be taken lightly. As of today, there are almost 1000 cases of infection world wide and, even if the flu development has reached a descendant curve, this might change. The 1918 epidemic actually had four outbreaks, two consecutive years, in the spring and autumn.

On a more personal note, my wife has (and probably myself, too) something called toxoplasmosis, a disease that you take from a cat. I only heard about it two times, one from a colleague and one from Trainspotting. It a strange disease, one that is mostly asymptomatic, doesn't have a real cure, causes behavioral changes in mice and has been linked to a certain type of schizophrenia. Wikiing it, I got that there are about 30% to 65% of the world population that have it and that the drug used to treat it is actually a malaria drug. Is toxoplasmosis the malaria of the developed world? A lot of us have it, but we bear with it?

Stuff like that shows how fragile is both our understanding of as well as our defense from the microscopic world. Could it be that, with all the medical advances from the last century, we are still in the Dark Ages?

and has 0 comments
A friend of mine asked me about what a tea was based only on pictures of the Japanese writing on the tea bag. How can I do that? I knew it was Kanji, or the Chinese style of writing, but I had no idea what to do. Looked for online Kanji character recognition, Kanji character list, etc. Nothing really worked. Until I accidentally (half through painstaking translation) bumped into nciku! Why, of course, you idiot! If they are Chinese style characters, wouldn't you be able to find an online dictionary for Chinese, not Japanese characters?

Well, nciku has a nice feature called "Handwrite Characters" which pretty much allowed me to translate the rest of the text. But the trick is to take the recognized character, then go to... Wikipedia! Because you don't really need the Chinese translation, but the Japanese one. You get the translation and the use and other useful things.

So, use nciku for online Japanese Kanji/Chinese character recognition. Yatta! :)

VirtualPathUtility.ToAbsolute("~/") = /Site/
HostingEnvironment.MapPath("~/") = c:\InetPub\wwwroot\Site\.
new Uri(HttpContext.Current.Request.Url,VirtualPathUtility.ToAbsolute("~/")).AbsoluteUri = http://server/Site/

and has 2 comments
I have hidden the private chat [that's the blue one] by default. In order to access it, you need to click on the "Show private chat" link in the top-left. I did that because I would like people to help each other rather than talk only with me, so I recommend using the Jabbify chat [the slightly annoying orange pop-up one]. Also, when entering your name, use a real looking name or nickname. I will not even answer anymore to people called "asfdd", "sfd", "hi" and "can you help me". People with correct names that start conversations with "adsdfs" will also be ignored.

I have also added a small piece of code to remove unwanted spam comments. If you feel that your comment was not spam and it was flagged as spam, let me know in the chat (or another comment :) ) and I will fix the issue.

I urge you again to tell me if there is anything that is bothering you about the blog in order to facilitate positive change.

Have fun, keep trying and good luck!

Update: I have fixed an issue with the layout and IE making the text disappear, especially when scrolling. Also I added a little something on the left that you can copy paste to your blog. So, if you want to help me spread the knowledge put it into your blogs. I am not making any money out if this, so make Siderite famous!! :)

and has 0 comments
A Romanian blogger made a very information link laden post about the new features in .Net 4.0. Check it out: Learning resources for .NET 4.0 new features.

I wrote a while ago about Pluto being a very nice manga and about the author also doing work on something called Monster. The story in Monster, as in Pluto, has finished after 162 manga chapters or 74 anime episodes. I didn't read the manga, instead I have watched the anime, but it took forever, because after a while, frankly, it got boring.

The idea is very interesting and one close to my heart: there is a sociopath capable of controlling other people by understanding their fears and manipulating them with words. He also has no problems with killing people. The main character is a brilliant Japanese doctor living in Germany who has the misfortune of saving the "Monster" in a brain surgery. The rest of the show is the doctor trying to find the guy and kill him while concomitantly running from the police who blame him for some murders. In a way is like The Fugitive meets Silence of the Lambs :)

I would say that the way people are portrayed and the deep darkness of the series make is a brilliant one, an even better effort than the later Pluto, but it fails somewhere in the middle. Characters are very emotional and act in a very predictable way and after a few tens of episodes in which the doctor is following the killer and not being able to kill him (because he is the GOOD guy!!) one starts fantasizing about going to Tenma, the doctor, slapping his face, taking the gun, killing Johann the monster and then giving the gun back and silently leaving the manga. In a sense, this is what happens in the end :) but I am not going to spoil it for you.

My advice is to at least watch the first 10 to 20 episodes and decide if you will read/watch further.

I have seen a small video presentation about the new ASP.Net 3.5 SP1 Script Combining feature. Basically you take a bunch of scripts (like the ones from AjaxControlToolkit) and you bundle them together in a single cacheable file. This decreases the number of concurrent connections on your production site.

The problem was that you had to use some component to see what script files were being loaded and then manually add them to the ScriptManager CompositeScript Scripts collection. And this applies only to correctly registered scripts, not stuff that is embedded in the HTML or what not. Isn't it easier to just parse the generated HTML and then replace the script tags, I thought?

Well, I did a small Response filter/IHttpHandler in about two hours. It would take all consecutive external file references and combine them in a single cached and cacheable call. Then I tested it with Asynchronous postbacks. Epic Fail! The main problem was that the combined scripts would re-register themselves at postback and throw all kinds of errors therefore. But how did they know if they were registered or not before?!

I vaguely remembered an old post of mine about the notifyScriptLoaded function that must be called at the end of every external javascript registrations. Examining the system a little I realised that the flow was like this:
  1. register the script (either include it in the HTML in regular render or sending it to the UpdatePanel javascript engine to be registered as a new dynamically script element in the Head page section)
  2. if the registration is an async dynamic one, check in an array if the script is loaded and if it is, don't register it
  3. in the script call Sys.Application.notifyScriptLoaded() which would take the src of the script element and use it as a key in the above mentioned array to declare it has been loaded


Of course, that means combining all the scripts in a single file registers only that file and you get the original files registered again. Then you get errors like 'Type [something] has already been registered.' or (because there are more than one script file bundled together) 'The script [something] contains multiple calls to Sys.Application.notifyScriptLoaded(). Only one is allowed.'.

Well, I did manage to solve the problem by following these steps:
  1. forcefully remove Sys.Application.notifyScriptLoaded() from bundled scripts
  2. add Sys.Application.notifyScriptLoaded() at the end of all scripts
  3. surround the various scripts with a code that looks like
    sb.AppendFormat(@"if (!window.Sys||!Sys._ScriptLoader||!Sys._ScriptLoader.isScriptLoaded('{0}')) {{
    {1}
    if (window.Array&&Array.add&&window.Sys&&Sys._ScriptLoader) Array.add(Sys._ScriptLoader._getLoadedScripts(), '{2}');
    }}
    ", HttpUtility.HtmlEncode(src), content.Replace("Sys.Application.notifyScriptLoaded();", ";"),src);
.

With problem solved, the AutoScriptCombiner works, but it feels wrong. I wanted to post it on Github, you see, but in the end I've decided not to. However I did learn something about how the Asp.Net Ajax framework functions internally and I wanted to share it with you.

Another great blog post from Rick Strahl made me investigate a little the new JSON support in the latest browsers. Internet Explorer 8 already has it and FireFox has it in its beta version and soon to be released 3.5 version.

Rick's article says more than I could. A short summary:
  • use the native JSON object
  • much faster and safer than any js library
  • still has problems with types of data which have no native notation or type, like datetime
.

Update: the native JSON object is not something that Microsoft and Mozilla got together and decided is a good idea (which for me seems the natural way of deciding the direction of code versus compatibility, not overbloated committees and standards) but because the release of the latest ECMA Javascript specs which contains, among other things, the JSON thing and the getter/setter syntax.