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.


Gödel, Escher, Bach by Douglas Hofstadter has won a Pulitzer Prize and I believe it is the only thing that ever made me want to read other Pulitzer Prize books. I have to thank Meaflux for pointing me to this book and if he ever writes anything in his blog, you can find it here. Anyway, here is my humble review:

I have just finished reading the book and, in its self-referential spirit, I am also starting reading it. A strange loop of sorts, when starting to read a book follows finishing it. It is not an easy read, but it is certainly worth it. I was instantly both in awe and full of envy on this Hofstadter guy that I have never even heard about before.

What is the book about? I believe the most basic answer is it is about the roots of consciousness, and before you run away thinking this is some sort of new age pseudo (or fully) religious crap, let me assure you it is not. The title itself shows the perspective one gains by reading it: look at the same thing from the viewpoints of a mathematician (meta-mathematician, at that), an abstract painter and a great music composer. It's a definition of abstract thought by intersecting the works of three great abstract thinkers. But it is more than that.

The most intriguing part of the book it is how self referential it is. There are portions in the book that are modeled after Bach fugues while paraphrasing Escher drawings in order to illustrate a mathematical idea of Gödel. It talks about artificial intelligence, consciousness, the workings of the brain, formal systems, computer programming, music, art, science, mathematics, quantum mechanics, biology, genetics and does so in a way that links all these things together in a reasonably easy to understand way. It does not feel like a book made out of separate chapters, but one master-single-piece linked to itself in the most imaginative and twisted ways.

I urge you to buy the book, if you find it. I have read a text OCR version of it and I know I missed a lot. If you can't afford it, there it a torrent on the net with the PDF scanned version as well as the music, paintings and other media the book talks about.

The bottom line is that it is an amazing book. For someone like me, a software programmer dreaming of AI, it was a shame I didn't read it before. I almost believe that you will see me in buses like those old ladies reading the Bible, only with GEB in hand. I can't imagine anyone over 15 years of age that shouldn't read this book. I doubt anyone under 15 can truly comprehend it and, as Frank Herbert's Dune, it must be read every 10 years or less, just to see how much more you can understand from it.

Update: I found on the Internet a full length movie based on Hofstadter's ideas. Interesting, in a geeky/goofy kind of way. Here it is: Victim of the Brain.

and has 1 comment
A while ago I bought this LaCie 500Gb external hard drive and I was rather satisfied with it. With the occasion of the horrible Easter holidays I finally turned off my computer (after weeks of it working continuously). So imagine my dismay when I came back home, turned the LaCie on, then the computer and all I had to show for it was an USB mass storage controller error in the Hardware Manager.

After trying a few things (and noticing that the hard drive would not actually turn on, instead a tick-tock sound was heard from inside) I decided to open up the drive box, proudly written on it "Designed by F. A. Porsche". Well, fuck you, Porsche! I had to almost destroy the box to open it, then the insides had so many "one installation, no after service" components that I felt like walking on broken glass.

Anyway, inside the LaCie there is a small USB controller and an SATA Seagate Barracuda 7200.10 hard drive. I installed the hard drive as an internal drive and... nothing! Windows XP blue screen 0x0000007B. The computer wouldn't even recognize the drive in the boot up screen.

Well, after looking for drivers and stuff like that, I was resolved that the hard drive was defective and all my music, movies and books were lost. But shutting the computer down I noticed that the drive was actually spinning in its internal setup configuration. So, desperately, I tried to use the power from the internal computer power source and the rest of the drive in its USB setup... and IT WORKED!

Now I am going to buy another drive and get all data from this one, but still, if you are desperate that your USB hard drive is lost, try to open it up and power the internal drive with a normal computer power chord.

As for why the internal drive did not work directly on the computer? I have almost no idea. The Seagate site says clearly that SATA drives do not require drivers, but the various SATA controllers do! Since I already have a SATA internal drive, I think that that is not the issue. Rather, the people at LaCie used another drive firmware! The Seagate drive also provides with some downloadable firmware so it is clearly possible. As a completely desperate option to recover your lost data, I guess trying to rewrite the hard drive firmware could work, but I don't recommend it and I wonder how it is possible, considering it wouldn't allow me to boot Windows.

I hope this helps somebody. And Happy Easter everybody!

Update September 2012: after three years and a half, the drive (powered by both USB and internal computer power) started to develop bad sectors. It still works, mind you, I just removed it because I didn't need it as much. Thus ends the saga of the mutant harddrive in the computer that never sleeps and never dies [creepy music in the background] :)