and has 0 comments

Now this is a good book. It has it all: a fairly detailed description of a future world; magical kingdoms; the love between fathers, daughters, siblings; a thorough research for the book, allowing for elements of Victorian and Confucian philosophy; good writing style.

I felt it was way better than Snow Crash. I think it overlooked the transfer of energy to the nano scale devices that it describes. I loved the way it described the collapse of borders and the adoption of economic reasons why an ethnicity should have or not teritory.

Definitely a worthy read.

and has 0 comments
I have some things to say that are rather general and I hope people will read. At least I need to get them off my chest.

First of all, I am still working on the blog posts from Greece. Links, updates and pictures will pop up for a week or so. Then some books I've read. Have patience, I am lazy as hell.

Then there is the matter of all the help requests from people who want my stuff in Visual Basic. NOT GONNA HAPPEN! There are free online web translators from C# to VB and (thank heavens!) viceversa. Just Google for it, I don't doooo VB.

And last, but not least, the blog spammers. People that want to use my blog for advertising. They seem to make the effort to look for keywords in blogs, then comment with links to whatever crap scam site they have. These comments will be deleted immediately, so don't bother. I especially hate sites like developmentzone.blogspot.com or asp-net-help.blogspot.com that have two measly articles that are copyied with cut-and-paste from www.sql-server-performance.com or some other site with people that actually work for that stuff. Just so you know, every time I see a comment that links to such a site I first delete the comment, then I warn blogspot of the spam site.

Sparti, Greece (3)

When I first heard my sister in law lived in Sparti, the modern Greek town built at the site of ancient Sparta, next to the medieval settlement of Mystras, I had expected to see myriads of ruins, tourist attractions, museums and so forth. Not that I like this kind of stuff, but if Romanians had a city in Sparta, they would quickly turn it into a tourist attraction, always crowded and nauseatingly full of people and garbage. Not the Greeks. They did have something organized at Mystras, which is a small mountain fortress with a church next to it a mountain fortress towering over a small settlement boasting over 20 churches from different eras (quoting from Maria who was upset I didn't think much of Mystras), but Sparti was just like any other provincial town. We didn't visit the "Ancient Sparta site" yet, at the time we were just looking for a good long sleep in something like a bed.

Anyway, we met with Maria's sister, went to her house-in-progress in a small village next to Sparti and tried to get accommodations. The house is not finished yet. It does have its walls in place, but there are no doors inside, no floors except the raw concrete and so, after spending a day there and sleeping for the night, we decided to relocate to Maria's brother's home, in Kyparissi. But not before I got acquainted with the local cuisine, visited Mystras and made some pictures of the place. It was necessary for me to shed off some preconceptions about Greece as well.

First of all, orange and grapefruit trees don't grow everywhere in Greece. Even if my sister in law's house lay next to an orange orchard, that wasn't really very common. Instead, olive trees were practically everywhere! I love grapefruit juice. I thought I would get tons of it, freshly squeezed from recently picked fruit. The Greeks don't like grapefruit much. I had to make due with the supermarket variety of juice, of which I think I used a significant percentage. When trying to buy it, a clerk warned us that that was not orange juice! To be fair, it wasn't fruit picking season, the oranges in the nearby orchard were still green, so maybe I just visited the place at the wrong time of the year. I think I would have had more fun in the winter.


Then, the food is not that spicy or original. Greek cuisine seems to orbit the suvlaki and gyros, which are medium sized chicken meat on a stick or wrapped in pita bread. Being used to shawarma and döner kebab in Bucharest, I found it banal. I also knew about tzatziki, which is a mixture of yoghurt, cucumbers and garlic. However, most people there were amazed of my willingness to order and then ingest large quantities of the stuff. The mousaka we also have in Romania. We ate a nice one at a road diner just after entering Greece, but from then on every restaurant we asked did not have it available. Also to note is the pastitio, which is like a lasagna made with normal pasta, not sheets of it.



The only spice worth mentioning is the Greek oregano, which they called rigani. Very aromatic and flagrantly different from the Italian sort. Also, if I had ever imagined Greek peasants selling cheap olives on the side of the road (like one would find in Romania), I was sadly disappointed. When leaving the country, we actually bought the olives from a supermarket, after trying a few and not finding any except in small jars.



Driving through Sparti was shocking to us. They had no semaphores, the town was full of steep roads and the cars were packed together making it hard to move through. Or at least that's what we thought at the time. We heard they tried to implement traffic lights in the town, but that only made the situation worse. They also had some roundabouts (we were told that's what they were) which were pretty much poles in the middle of normal road intersection. The houses were the usual block like yellow model, since they never have significant snow to warrant tilted roofs and any color except yellow would probably be burned through by the relentless sun.



The cars are either small, and of all kinds, all pickup trucks, which are almost all Asian cars. Mitsubishi is a popular brand in Greece for trucks, although I have seen only about three Colt and three Lancer models around. Instead zillions of truck/van variations, from the ancient Canter model to the more modern L200. You can find a lot of Nissan, Toyota, some Ford and Isuzu, etc. In the area people seemed to love pickup trucks.

Greek villages are built like mountain villages, even those placed in valleys. The houses are packed together, with barely enough space between for cars to pass by each other and with no sidewalks. If driving through Sparti was a bit new and awkward, driving inside the village where my sister-in-law lived was hell! No straight roads, no markings anywhere. The convex mirrors that I sometimes saw installed in Romania in difficult mountain curves are popular even in flat valley Greek villages. During church days, a side of the road is used for parking so if two cars face each other, one of them must back up all the way to a larger portion or an intersection. Amazingly (for a Bucharest guy like myself), they hardly ever honk.

The logic behind it is that they built the houses in (and with) the rock of the mountain, obviously in the portions that were easiest to support a house, like flat and safe. They left space for two loaded donkeys to pass by each other, they didn't need more. In the ancient Greeks view, the roads had two lanes! Things were perfectly fine until all the nonsense with the cars came along. But why would they apply the same crowded style to their valley villages, I don't know.

I will not linger on the nearby Mystras. It is a ruined fortress on a mountain side full of foreign tourists. I made some quick photos and ran away. It was hot and I found it less than inspiring, although beautiful to look at for a few moments :)




Kyparissi, Greece (4)

Oh, boy! If we were shocked by the roads so far, we were in for a surprise. The village of Kyparissi was over a mountain from Sparti and near the sea. The way there was carved into the rock and both steep and curvy. The same lack of safety installations or warning signs was apparent. We kind of got used to it, in a while, and then we entered the village. Imagine a place where your car has just enough place to squeeze through and where the main road has portions that allow for two cars to pass by, in the others, one must back up in steep, even tightly curved places to allow for the other to pass. How we haven't bumped, scratched, crashed our car is beyond me.




The village itself is nice to look at. Not much to do in it. It consists of houses covering a side of the mountain from the top down to the beach. Whatever space is left is covered in olive and carob trees. With the typical Greek nonchalance, the beach is not regulated in any way, nobody seems to clean it or the water and there are no tourist accommodations to be seen on it. The sea is light blue and very clear, so the combination of mountain, sea with some yachts on it and small houses is very beautiful.



What striked me, a guy used to the sandy beaches of Romania, is that the beach was small and full of rounded rock. I could barely walk on it (although, to be fair, Maria had no problems). There were no birds that I could see, no oyster shells, just a lot of wasps! The Greeks don't seem to mind, I even heard the idea that they enjoy rocks more, since they don't get into their bathing suits. After a first very unpleasant beach day, I found the solution: I would use my slippers on the beach and when entering the sea, then I would move them from my feet to my hands and use them to either support by head when floating around or as swimming accessories. It worked wonders and it allowed me to enjoy the sea.

The sea itself was very clear and very salty. When it entered my nose and eyes it stung to high heaven. I got used to it eventually. There were small fish swimming around and, if there were no waves, the water was very clean. However, when the waves came rolling in, they brought plastic bags, plastic cups, twigs and big red jellyfish! I noticed that if I let the waves bring this crap closer to the shore, it eventually got stuck in some places and the water was clean again in about an hour.

It was funny to see the fish jump from the water one after the other. One less attentive fish jumped right in my shoulder. He probably expected some warning sign that I was there, so maybe it wasn't a Greek fish! One day I noticed something red in the water. I thought of warning Maria, but then I saw the same thing on another wave of water, looking exactly the same. I thought it was a reflection or something until Maria shouted that something touched her. Swimming there I found that the waves brought jellyfish close to shore, big fist sized reddish-brown tentacled jellyfish that now I believe are of the species Pelagia noctiluca. I never seen them glow in the dark, but then again, I didn't go swimming at night either. I was right not to touch them, as they apparently are the stinging type.

While in Kyparissi I visited an abandoned "old village" which consisted of some old buildings that very few people lived in. It was like a good MMORPG map, people could learn a thing or two about how to make games wandering around there. I forgot to bring my camera that time, sorry. Then we went to a cabin higher up the mountain, which provided us with more beautiful scenery and more Greek road horror. Imagine an unpaved road full of broken rock that goes higher and higher, while the wheels of the car are centimeters away from free fall. Made a lot of plant pictures and I even photographed an eagle in the sky.



We also went to the Wine "Panigiri", which is Greek for festival, in the close village of Pistamata. We saw a lot of people in front of a church with lots of wine, we turned the car around and went back :) What did you expect? I am a software developer. If I'd had people skills I would have had some other job!

Other places we've seen are the town of Molaus and the citadel of Monevasia. The latter was a nice castle city at the edge of the sea, something like the Romanian Sighisoara, but with a lot more good taste and with the sea :) Took some pictures there, as well.







We spent a little over a week in Kyparissi, lazing around. I brought a few books with me, but they weren't all so interesting so I ended up watching Romanian satellite TV and eating a lot. It was like an advanced course in couch potatoing. I slept, I ate, I went to the beach (sometimes), I watched TV. I gained like 5 kilograms doing this :)

I promised to tell you about the Greek schooling system. Well, in order to get to a university you have to learn everything you've been taught in highschool. It makes sense. In order to help children to learn it, sometimes parents hire tutors, paying them for the service of upgrading their children's knowledge. Again, understandable. What is really nasty in Greece is that eveybody hires these tutors, so much that then entire educational system pretty much assumes the children will go to these "frontistirio". The demand is so great that the market is not controlled by the parents, but by the tutors. They get to teach and, if things don't work out, blame it on the child! All the time the parents are paying 5000-10000 euros per year for this crap! While it is nice to see Romania doesn't have the crappiest educational system on Earth (although we are working on it), I can't help feeling sorry for all those kids and their parents.

Next post will be about the trips around Sparti and the way home to my beloved computer! Yay! Coming up right after these commercials!

Sorry for being away and not thinking of writing a small explanative post. I went to Greece for my holidays, to visit my wife's brother and sister who moved there some years ago. This is going to be a long post, so grab your popcorn.

Bulgaria (1)

When you have never been to Bulgaria on your own and you plan to go there with your personal car or at least transit the country, you hear the following things:
  • it is an ugly country
  • it is overrun by car thieves, corrupt cops and enterprising murderers
  • it has no, little or bad roads
  • it is poor like a third world country
. Well, I can tell you it is all pretty much bullshit.

I only transited the country, so I can't tell you I did a lot of sight seeing, and all I knew about Bulgaria is from a few years ago when I went to Balchik and I found it charming and full of lovely people. This time we went with our own car (Maria driving, as I am not really into cars) and I found it a beautiful country at least from the road towards Greece. People always helped me out (to an extent that I would have never expected, but that is for later to discuss) and a lot of them knew English to a reasonable degree (which put me to shame, since I all but forgotten the perfect Bulgarian I spoke when at 8 years of age). The roads are better than those in Romania by a long shot, almost highway material, only not with so many lanes.



My only problem lies with the way towards Greece, where the road was peppered with 40 km/h and 60 km/h speed signs accompanied by hidden police cars waiting for you to snap and go over the legal limit. Unfortunately the Bulgarian cops are crooked and even if I find placing a 5 euro banknote in the passport when they stop me - making both the bill and the speed violation disappear as by magic - a lot easier than all that dancing one normally has to do in Romania ("please officer, my grandmother is dying and I have to get to her before my granddad finishes strangling her"), I still found it annoying, especially since almost all local vehicles were passing by us like we were standing still.

Well, only one encounter like this actually took place, the cops pulled us over and then we did the 5 euro magic trick and, as we were preparing to leave, a moron with his trailer door unlocked passes by us and cracks the left rear-view mirror with the aforementioned door. I am grateful that the mirror did not break, that the metal door only hit the mirror and not the car door or (I might add) a child's head or something like that.

Anyway, we traveled all day through Bulgaria in order not to stop (we still gave credit to the third world country hypothesis above) and I took some pictures of what I think was beautiful: green forests on small mountains, long tunnels and bridges, nice straight perfectly asphalted roads (with 40 km/h speed limits on them!). I am not the world's greatest photographer and I have to sift through all the stupid pictures, but I promise I will update this post with media in a few days.




The other incident on our way to Greece was in Sofia. Apparently the ring road around the city was under (re)construction and we had to take a detour. The detour was not clearly marked in any way and the only thing the Bulgarian cop that directed the traffic had to say was "follow that car", showing towards one that was just leaving and which had a more enlightened driver in the way of the Bulgarian language. It all went nicely until the said driver decided to pull over for some reason. We followed the small serpentine road, took some guesses on which direction to take later on and quickly got lost. The GPS we had with us had only the most basic maps loaded so when we left the road it knew, we were pretty much in the Wild West.

At this time my wife decided to go through a PM moment and started shouting at me, at the GPS and blame everything on me. In this kind of emotional state trying to use logical reasoning only works to enforce the idea that I am not empathetic to her feelings and only opaque to the obvious truth that everything that ever went wrong is my fault. The GPS was of no use, the map showed very clearly that we were dangling on the vertical line of the letter F in Sofia and we were going nowhere. Since getting angry would not help, making her more angry would make her more expressive by use of car throttle and breaks and since I didn't want to die I agreed that it was all my fault, lack of preparedness, a lot of laziness and that I was very sorry for it. Then I tried directing the conversation towards a solution.

I mean, how bad could it be? We were next to the darn capital of the country, where could we get lost? At a moment where the panic was going bubbly bubbly on the seat next to me, I got to read a sign that pretty much placed us on the map of Bulgaria we brought with us and this time not on any of the capital letters on it (capital letters, get it?). So we went on a small road that was parallel to the one we should have been on and (at least in my opinion) were fortunate enough to see raw country, beautiful scenery and not to many cars. Of course, the panic ended only 50-60 km or so after, when we were back on the GPS tracked course, but that was still to come.

The next big hop was when trying to decide what road markers to follow. I looked at the map, noticed that the biggest city after Sofia that we were going towards was Blagoevgrad and decided to look for that name. My wife was nagging me constantly that her sister told her we should always go towards Kulata. I could not find any major city called Kulata on the map, so I was skeptical of the information. But we did find Kulata road signs and we followed them until there were none. Did we pass Kulata? Where the hell was Kulata?? Where the fuck was Blagoevgrad?!?

At one time we noticed a big Sofia sign. My wife said we should take it. I didn't understand, we just came from Sofia, what would be the point? She finally (after some shouting from both our parts) articulated that the road going towards Sofia probably comes from somewhere, and we should go that way, once we reach the road. It made sense, but then why would the road sign say only Sofia? What happened to the damn Blagoevgrad? Or Kulata for that matter.

Turns out she was right. People just didn't put all the markers. Why would they? In Romania that would probably happen very rarely, at least our road markers are top of the line (and I was pretty happy with my country at the time). One marker finally told me Kulata was 82 km on the road, so I looked it on the map approximately 82 km from our location. I found it, written with letters about five times smaller than the letters used to spell Blagoevgrad. It was the border town towards Greece. I found it odd; it was like trying to go to Sibiu but finding only Nadlac signs. (they are Romanian cities, mind you).

Well, we did manage to get out of Bulgaria, pretty much upset by the GPS maps, my own performance, Maria's sensitive nerves and the Bulgarian road markers.


Greece (2)

If Bulgaria started up pretty much like Romania in terms of soil and plants, when getting closer the Greece everything got more and more yellow. The soil turned red or disappeared completely, replaced by sun whited rock or yellow-red sediment compression rock. The plants got more and more Mediterranean until only olive trees remained. Imagine a humid air hot, dry soiled, olive tree infested land and you get Greece. They don't have much in terms of railways, so they have a lot of roads. Good roads, only very sinuous, since they have to go up and down a whole range of mountains.



If Bulgarians forgot some cities on their road markings, the Greeks forget the markings completely. You enter small villages or towns and you have no idea where you are. If you are lucky, you find out when you exit. The curves are rarely secured with metal sheeting and sometimes not marked at all. A person could drive into any number of precipices just by missing a turn. Both me and Maria felt that they used "dangerous curve ahead" markings on easy curves, while on the really dangerous ones they used nothing. And to top it all, their writing is both complex, uselessly complicated and there are hardly any markers written in Roman characters. If there are Roman characters markings, they are 10 meters after the Greek ones. My brother in law explained it by a joke: the Greeks are hard headed and need more fore warning. Anyway, it's not that all Greek roads are this badly directed, it's just that some of them really are. And it is shocking to come from a normal, protected, with proper signs and directions on it, road and getting on portions where the signs are missing or wrong and a problem with the steering would probably send you in a beautiful, albeit short, flight.

I knew a little Greek lettering and tried to understand where we were and where we were heading. The GPS was of real help. But it was not without gain. Just by reading the Greek for Exit (Exodos) ,for example, made me realize that both Exit and Exodus are based on the same word.

Our plan was to get to Thessaloniki, visit the city, sleep somewhere, then continue on our way. We got to the city, left the car on a street, asked the people there for the name of the street and how to get to the "White Tower", a construction Maria had heard about that was worth visiting, we were directed there, and started visiting Tessaloniki. Alas, the directions were idiotic, we turned out walking aimlessly through the city, tired, nervous and hot (there were about 35C in the shade at that time).

The city itself was really beautiful. And when I say beautiful, I don't say it lightly. I usually hate sight seeing, I care nothing for buildings and I am interested in the local cuisine more than the local ancient art. But this one was a very balanced mélange of beautiful things. It boasted a great deal of hotels and nice houses and shops, mingled with ruins from the old citadel (which almost no one bothered to mark in any way) having mountains on one side and the sea on the other. Other people that visited Thessaloniki told me they found it crowded with people and didn't enjoy it so much. Maybe it was a good time of the year, but when we visited it, the only people we saw were sitting in outdoor cafés.

A great deal of photos came out of it, but after a while we realized we did not know how to get to the car. I knew where the car was, obviously, and so did Maria. The problem was that our views differed substantially. Tired and in the beginnings of another PM moment, we decided to ask a cabbie where the street where we left the car was. "Do you know English?", the typical Greek answer was "No". On a hunch I asked him if he knew Romanian and turns out he knew more of it than English, since he was married with a Moldavian girl. If you are Romanian, you probably would get a few kicks from seeing a Greek mispronounce Romanian words that he learned with a heavy Moldavian accent anyway. But we got to the car.






The next step was to find somewhere to sleep. We asked in a hotel nearby; they charged 60 euros per night without breakfast. We thought the price might be lower in a motel on the highway. You see, Romania is in the middle of an economic boom. People have and find new business opportunities every day. On the Romanian highways you find a lot of motels, hotels, places to rest, drink or sleep. No, the Greeks had some places to eat and some highway parking places where you could stop the car and fall asleep in it, nothing else. We searched for somewhere to sleep for so long that we got to the point where I was wondering if Maria would fall asleep on the wheel or not.

At one particular bad moment we reached the conclusion to leave the highway and (instead of driving another 40km to Lamia) stop in a place called Sourpi. We immediately found the Greeks gathered around three or more taverns, enjoying their social lives in the relative cool of the night. And just as fast we learned that they have no place for someone to sleep in the whole town! Again, coming with a Romanian mindset I expected some of the Greek people there to offer a place to sleep in exchange for a nominal fee. I was surprised to see that the thought didn’t even cross their tanned little heads. They directed us, though, to a town nearby where they should have had hotels or something like that. The directions sounded like follows: “go 4 km and you will find a biiiig blue sign that says the name of the town (which I immediately forgot, of course)”. After 20 km of pitch black country roads we haven’t found any blue sign. We managed to find a gas station and ask where we could find a place to sleep. They directed us to another town, which boasted two hotels. Enough said, when we found one of the hotels, no one answered the door!

Maria got angry immediately and we went back to Sourpi (in the process finding the biiig blue sign as a little blue tree branch covered tin foil), back to the highway, stopped in a parking and slept there for a few minutes, until we realized that sleeping with the windows closed doesn’t work and keeping the engine running just to have air conditioning wasn’t really cool and also that we care not for mosquitoes. Maria fearlessly drove on. Fortunately her metabolism allows for great surges of energy from just minutes of sleep.

So this is how we got from Bucharest to Sparti in southern Greece in 27 hours, with some visiting, lost and found ways, and some awkward sleeping. (we got some real sleep just before Sparti, fortunately).

See you in the next part, where I explain the horror of driving in small mountain Greek towns, the way they like stony beaches instead of sandy ones and how they live out of tourism, but do nothing to help it out. Also, about the incredible Greek learning system, which pretty much sucks.

Also, you might get a Sys.WebForms.PageRequestManagerServerErrorException with code 500 when using Ajax. It usually happends when you click on a button in a GridView or another bound control. You expect it to work, but it doesn't, even if the code is relatively clear.

The answer is (probably) that you are binding the container bound control every time you load the page (instead of only on !IsPostBack). The thing is this used to work in ASP.Net 2.0.

Bottom line: check your binding, see if you are not doing any DataBind in between the button click and the eventual event catch.

and has 3 comments

We started our first ASP.Net 3.5 project and today I had to work with the Linq database access. Heralded by many as a complete revolution in the way of doing ORM, LInQ is not that simple to move to. A lot of stuff that has become second nature for me as a programmer now must be thrown in the garbage bin.

I'll skip the "how to do LInQ" (there are far too many tutorials on the net already) and get down to the problem. Let me give you a simple example. You want to select a User from the Users table. Let's see how I would have done it until now:

User u=User.SelectById(idUser);

or maybe

User u=new User(); u.IdUser=idUser;
u.SelectOne();


In LInQ you do it like this:

var c=new MyDataContext();
User user=(from u in users where u.idUser=idUser select u).FirstOrDefault();

or maybe

var c=new MyDataContext();
User user=c.Users.Select(u=>u.IdUser=idUser).FirstOrDefault();



I am typing this by hand, forgive me the occasional typos or syntax errors.

Well, my eyes scream for an encapsulation of this into the User class. We'll do that by creating a new User.cs file that contains a User partial class that will just mold on the LInQ generated one, then adding methods like SelectById.

Ok, I have the bloody user. I want to change something, let's say rename him or changing the password, then save the changes to the database. Here it gets tricky.

User u=User.SelectById(idUser);
u.Password="New Password";
....?!



In LInQ you need to do a DataContext.SubmitChanges(); but since I encapsulated the select functionality in the User class, I have no reference to the DataContext. Now here are a few solutions for doing this without saving the linq queries in the interface:

  1. Add the methods to the context class itself, stuff like SelectUserById();. You would still need to instantiate the DataContext though, in every query
  2. Add a second out or ref parameter to the methods so that you can get a reference to the DataContext used.
  3. Make a method for each operation, like User.SetPasswordById();, that would become quickly quite cumbersome.
  4. Add a reference to the DataContext in the User object, but that would become troublesome for operations like SelectAll

.

I am still not satisfied with any of these solutions. I am open to suggestions. I will link to this little article I found that suggests encapsulating the LInQ queries in separate extensions methods: Implementing ORM-independent Linq queries

and has 0 comments
Oh, I know you probably have heard of Augmented Reality, but you have never experienced it in a way that is trully easy to use and that really feels... real. Here is a small demo from Total Immersion, a company that uses image recognition software to add computer generated interactive objects to real time videos.

As far as I understand it, they plot some points on the image, they store its contents and the software can recognize it even skewed or warped or even partially visible. In the video you will see how this applies to a classic green-screen-like board that the demonstrator can actually move around, then how it applies to an image on a t-shirt and then, finally, an interaction between computer generated and real objects.

and has 0 comments
I started reading Neal Stephenson at a friend's recommendation. That reminded me of the cyberpunk novels that I used to read in my teenage years and enjoy so much. However, I remember them slightly more fun :) That's why I would call Snow Crash more of a Cy-Fi novel, a piece of cyberpunk with a slightly overexagerated plot. Even Wikipedia calls it a post-cyberpunk novel. You see, when Gibson wrote about hackers and the artificial intelligences and the future, he was actually trying to convey a believable, predictable future. I believe Neal Stephenson actually crossed the line and pushed the vision a little in order to put some ideas on the table.

However, it was still a good novel, with interesting characters, fantastic vision of the future and quite a bit of research, which he modestly attributed to a lot of his friends.

The story revolves around Hiro Protagonist, a sword wielding computer hacker, and Y.T. (Yours Truly - a 15 years old skateboard courier), both caught in a complex plot that I cannot reveal without spoiling the read. It has some of the standard cyberpunk motiffs like the collapse of governments and law, the world being ruled by corporations like the Mafia, the church and Mr. Lee's greater Hong Kong (to name a few) and a focus on the services individual people can provide rather than the material benefits of technological items.

I recommend reading it, although some parts of the "future" are already old and silly by now. I've also read some short novels like The Great Simoleon Caper and Spew, that were both good reads, especially the latter. I am moving on to Diamond Age now.

You usually get this using an Internet Explorer version 6 (but also later versions might exibit this) on pages that seem to be loading ok in the background. You press ok and the page disappears and the regular error page is displayed.

What is happening is that javascript is trying to change a html element that has not finished loading. The usual cause of this problem is an embedded script block that executes as it loads, rather than on the onload event of the page.

The fix is easy. Take all the scripts that execute as they load and either mark them as defer or encapsulate those commands in a function that is executed on the onload event of document.body. Be careful with defer. This post describes the various implementations of the keyword in various browsers.

Yay! My first real SilverLight post :)

Anyway, the problem is with controls in SilverLight that expect an URI as a parameter. It doesn't work. After trying all kind of stuff and googling a litle I found out that
  1. the path is relative to the web application ClientBin directory
  2. the path cannot contain .. or other directory/URI navigation markers like ~
  3. the SilverLight control does not have access to a Request object like a web page does


This link already discusses it: Silverlight 2.0 Beta 1 Uri inconsistency, but I also have an additional solution to the ones listed there.

Here are the solutions for this:
  • Provide an absolute Uri either statically or by generating it with this piece of code:
    New Uri(Application.Current.Host.Source.AbsolutePath + "../../../video.wmv", UriKind.Absolute)
  • Copy the images, videos, files into the ClientBin directory then only provide their name
  • Create virtual directories inside ClientBin that point to your resource directories. For example create a virtual directory Videos that points to the ~/Resources/Videos folder in the site, then simply use Videos/video.wmv as the URI


Of these three, the last I find the most elegant, even if the setup of the website itself might be rendered a lot more difficult by this.

ASP.Net 2.0 added a very useful thing, the '~' sign, which indicates that a path is relative to the application directory. Since the application itself should be indifferent to its name, this little thing comes in useful when trying to set the location of user controls, style sheets and so on. The problem is that this feature only applies to user controls. That is not a problem for most tags, since even a link tag can be set as a user control with a runat=server attribute.

The problem comes when trying to set the location of javascript script blocks. A script block with runat=server must be a server code block by definition, i.e. C# or VB, whatever the site language is set to. One of the solutions often used to solve this is to use a code block inside the src attribute of the javascript block like this:
<script language="Javascript" type="text/javascript" 
src='<% =ResolveUrl("~/scripts/myScript.js")%>'></script>
.

But this is still a nasty issue, because of the dreaded The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). error. As in the post I linked to, the solution for this is to place all external script blocks within a server control like a PlaceHolder or a even a div with the runat=server attribute set. The drawback to this solution is that you can't do that in the <head> section of the HTML output.

The other solution is to use from within the server code the ScriptManager.RegisterClientScriptInclude method to add the script programatically to the page. While this is elegant, it also defeats the purpose of the aspx page, that is to separate content from code.

Somebody asked me how to add things at the end of an AutoCompleteExtender div, something like a link. I thought it would be pretty easy, all I would have to do is catch the display function and add a little thing in the container. Well, it was that simple, but also complicated, because the onmousedown handler for the dropdown is on the entire div, not on the specific items. The link was easy to add, but there was no way to actually click on it!

Here is my solution:

function addLink(sender,args) {
var div=sender.get_completionList();
if (div) {
var newDiv=document.createElement('div');
newDiv.appendChild(getLink());
div.appendChild(newDiv);
}
}

function getLink() {
var link=document.createElement('a');
link.href='#';
link.innerHTML='Click me for popup!'
link.commandName='AutoCompleteLinkClick';
return link;
}

function linkClicked() {
alert('Popsicle!');
}

function ACitemSelected(sender,args) {
var commandName=args.get_item().commandName;
if (commandName=='AutoCompleteLinkClick') linkClicked();
}


The AutoCompleteExtender must have the two main functions as handlers for the item selected and popup shown set like this:
<ajaxControlToolkit:AutoCompleteExtender OnClientItemSelected="ACitemSelected" OnClientShown="addLink" ...>


Now, the explaining.

First we hook on OnClientShown and add our link. The link is added inside a div, because else it would have been shown as a list item (with highlight on mouse over). I also added a custom attribute to the link: commandName.

Second we hook on OnClientItemSelected and check if the selected item has a commandName attribute, and then we execute stuff depending on it.

That's it folks!

We have this web application that needs to call a third party site that then redirects back to us. The other app is using a configured URL to redirect back. In order to develop and debug the application, we used a router redirect with a different port like this: the external site calls http://myExternalIp:81 and it gets redirected to my own computer on port 80.

I was amazed to notice that when entering my local page, Request.Url would be in the format http://myExternalIp, without the 81 port. As the page was executed in order to debug it, I was baffled by this behaviour. I tried a few things, then I decided to replicate it on a simple empty site and there it was. The only thing I could find that had any information about the original port number was Request.Headers["Host"] which looked something like myExternalIp:81.

I guess this is a bug in the Request object, since it uses the port of the actual server instead of the one of the request, since my server was responding on port 80 on localhost and not 81.

Here is a small method that gets the real Request URL:


public static Uri GetRealRequestUri()
{
if ((HttpContext.Current == null) ||
(HttpContext.Current.Request == null))
throw new ApplicationException("Cannot get current request.");
return GetRealRequestUri(HttpContext.Current.Request);
}

public static Uri GetRealRequestUri(HttpRequest request)
{
if (String.IsNullOrEmpty(request.Headers["Host"]))
return request.Url;
UriBuilder ub = new UriBuilder(request.Url);
string[] realHost = request.Headers["Host"].Split(':');
string host = realHost[0];
ub.Host = host;
string portString = realHost.Length > 1 ? realHost[1] : "";
int port;
if (int.TryParse(portString, out port))
ub.Port = port;
return ub.Uri;
}

Just a short infomercial. Response.Redirect(url) is the same with Response.Redirect(url,true), which means that after the redirect, Response.End will be executed. In case you get a weird 'Thread was being aborted' exception, you probably have the Redirect/End methods inside a try/catch block. Remove them from the block and it will work. Probably the ending of the Response session doesn't look good to the debugger and that particularily obtuse exception is thrown.

If you absolutely must put the thing in a try/catch block, just put everything EXCEPT the Redirect/End. Another option (only for Response.Redirect) is to add a false parameter so to not execute Response.End.

and has 0 comments
And still, pigs are not yet flying! Here is the news article:
history.forward()

Bottom line: IIS is being optimized for PHP, PHP is being optimized for Sql Server and, by becoming a sponsor of Apache, Microsoft probably gets a say in their development.

What a typical corporate move that is. But what would be the effect of such a move only time will tell. Will ASP.Net start working habitually on Apache?