Friday 31 July 2009

FrightFest@Home - conclusions

I've had the priviledge recently to be able to watch two batches of horror movies from start to end without interruption, what I lovingly like to call FrightFest@Home. All my movie comments can be found here as well as another list, ordered by my vote here. The permanent links are in the top right of the blog as well.

However, after this, I felt compelled to also write a blog entry about them, since, as the horror genre goes (and, why not, the entire movie class), most of the films I have seen were rubbish.

So, these are the movies I have watched. I will cross out all the movies that are not worth seeing and bold out the ones that I felt need to be seen. I reiterate: all the movies in the list are horror (or at least marked as such on imDb). I would like to add a special thanks to M'hael from The Horror Club blog who recommended many of the films in the list. Here is goes:

Have fun!

Tuesday 28 July 2009

T-SQL ordered Update

I was trying to do this update, but I wanted done in a specific order. I have found two solutions. One is to use a Common Table Expression, which would look like this:
WITH q AS (
SELECT x,y,z FROM SomeTable
ORDER BY z
) UPDATE q
SET x=y+z
Strangely enough this updates the SomeTable table in the order of z.

However, I had to do it in SQL 2000, so Common Table Expressions were not available. The only other solution I could think of was a temporary table with an identity column:
CREATE #temp (
realid INT IDENTITY(1,1),
x INT,
y INT,
z INT
)
INSERT INTO #temp (x,y,z)
SELECT x,y,z FROM SomeTable
ORDER BY z
UPDATE #temp SET x=y+z


The most difficult part of the task was to not think procedurally. SQL is a functional language and one must think differently. Weird is I knew that I had to think in a functional way and I said it out loud when I started the task. It took a few hours of trying to create recursive functions or emulate loops in SQL before I could change my thinking. Using SQL in a procedural way, even if possible, means using something in the wrong way.

Internet Explorer 8 debug freezes system after Visual Studio 2003 install

So I had this legacy project that I was supposed to work on and so I installed Visual Studio 2003. That is, over VS2005 and VS2008. From then on, every time I had a javascript error in Internet Explorer 8 and that "Do you want to debug" window appeared, if I clicked yes, the system would freeze. And I mean total freeze, not even the mouse would move.

After a few angry reboots I noticed that unchecking "Use the built-in debugger in Internet Explorer" checkbox would not freeze the system. Setting it back on would bring the problem back. So this is what I did:
  1. went to a page with a js error on it
  2. unchecked the setting so that the system would not freeze
  3. chose a debugger from the presented list (but not the default one)
  4. set it as default
From then on, my problems were gone.

In conclusion, I have no idea what caused the error, but this is how it was fixed. I hope it helps people in the same predicament as myself.

Monday 27 July 2009

A(nother) replacement for barcodes

I am not working with barcodes or anything, but I think this new technology is kind of cool. Something that acts like a barcode, encodes more information and it is several times smaller. More than that, it can be read from multiple angles and from a distance of up to 20 meters!

I can imagine multiple applications, but what I specifically think could be great is augmented reality. It would start with markers that would tag objects from computer detection, but then it would probably transform into a communication system, if the codes are dynamic. And I am not talking about replacing IR or bluetooth here, but couldn't one imagine a programmable bokode that would change the tag of an object? Think picture frames. Or TV images. Something that would tag a dynamic object like a video screen.

Friday 24 July 2009

CSS quirks parsing can lead to unexpected results

I was having real trouble with an html menu. Every time I would move the mouse over an item, a large gray area would appear over the screen. This only happened on Internet Explorer 7, not Internet Explorer 8 or any other browser. When I changed the Doctype from XHTML to HTML I reproduced the error on IE8 as well.

Strangely enough, when I first found the source of the problem, a border of 899px , I thought it was a browser javascript incompatibility. How could it be differently? The CSS was mine and the JS was not. Obviously it was their fault. However, after reproducing the problem in IE8, I could use the more advanced developer tools available and I realised that the strange border width was not part of the element style, but the CSS class style itself. It was there, the interpreted style for my menu control class: border: 899px;.

I rechecked the CSS and I found the actual problem: no hash in front of the colors! So the browser found something like D8C89A instead of #D8C89A, did a weird parse on it, got 899, then considered it a size in pixels!

Hopefully, someone will read this and save themselves a lot of grief and time.

Tengen Toppa Gurren Lagann

Anime poster I usually don't like Mecha anime, with silly robots fighting battles that make no sense. I also dislike the Ecchi style, where young almost preteen boys and girls fall in love or are dressed in a sexual manner, with no sense either. At first, this is what Guren Lagan seemed to be. However it evolved into something else, and there is a pun in this phrase.

The series revolves around the "spiral power" (enough with the puns already!), the power of evolution, which allows people to get to new heights every time they meet an obstacle. Even if the animation was pretty basic and the story about always shouting robotic pilots that power their machines with the strength of their souls (geez! :) ), I just have to give it points for rapidly changing form and evolving in style.

We follow a bunch of "villagers" escaping from their underground almost stoneage dwelling and getting to the surface, where, in the course of 7 years, reach another universe and destroy the very beings intent on annihilating humanity with a robotic starship. Now that's fast :)

However, this is not it. What began as a simple courageous brawl twisted into a story about friendship, then despair, then rebuilding, going through the unforgiving politics of unintelligent human masses and ending with a galactic... no, universal battle for the survival of the human race, all in 27 episodes. I say not bad! I was expecting to see tens of episodes going nowhere and then ending suddenly when the funding was gone, but no, it was a complete story, evolving from the level of 7 year olds up to almost adult (in a timescale sense :P) level.

So watch it, it might surprise you. Prepare yourselves for really corny dialogs and a rather simple animation, though. Oh, also, you might find a Guren-hen movie that is like a summary of what happened from episodes 1 to 11 in the series. If you have watched the series already, the movie is made of fragments of it, so you don't need to watch it. If you are in a hurry and you have seen neither, watch the movie, then the series from episode 12 upwards.

Tuesday 21 July 2009

Infragistics LoadPreset doesn't work!

The Infragistics web controls have a way of saving design time settings into XML files and then loading them. You can do this either by loading the presets in the designer or dynamically from code, using the LoadPreset method. It accepts Stream, TextReader and string parameters and it is pretty easy to use.

The problem is that it doesn't work in inherited controls! The explanation is that a piece of its code is searching for the root element of the XML file by getting the assembly defined TagPrefix and then adding to it colon and the name of the object.

In other words, I had a control that inherited from UltraWebGrid, and in the ASPX it looked like omega:OmegaGrid, when styling it with the designer and then saving the preset, it created an XML that has its root element . Since my assembly had no assembly TagPrefix defined, it was looking for ":OmegaGrid" and failing.

The solution was to add the TagPrefix assembly attribute: [assembly: TagPrefix("Super.Desktop.GUIControls.Web", "omega")] in the AssemblyInfo.cs file.

Monday 20 July 2009

Lux Aeterna - Clint Mansell

Yay! Post 600! I will post about a new song that you have certainly heard during movie trailers or if you watched Requiem for a Dream: Lux Aeterna, composed by Clint Mansell. No video for this one, even if the embed is from YouTube.

It's just nice and hints on the rithm of development of both myself and the blog ;) Have fun!

Thursday 16 July 2009

Internet Explorer 7 dynamically loaded CSS and the Infragistics Web Menu

Now, that title doesn't much, but it's the only one I could think of, because I haven't yet determined the source of the problem. Baiscally, what happends is that there is a difference of behaviour between style included directly into the page and actually using javascript to add to the head of the page a dynamically created link element.

I have no idea what exactly is going on, but I will try to explain it based on the evidence. There was this menu control, an Infragistics Web Menu from the NetAdvantage 9.1 suite, that, given the right styling, would look exactly like what I wanted. After setting that style in a css file I decided to load it using a javascript dynamic load just in case the control would be rendered only on asynchronous postbacks. And it worked perfectly. In IE8, Chrome and FireFox. However, when tried on IE7, it exibited the strange behaviour that, on mouse over, the entire table that the menu was rendered as expanded to fill the screen and was completely blank. After extensive attempts to capture the element with Internet Developer toolbar I noticed that the border-bottom-width and border-left-with were abnormally high, like thousands of pixels.

As of now I know not the cause of this. I can tell you, though, that moving the same style from the dynamically loaded CSS into a statically loaded one or by copying that style in a style tag in the page fixed the issue. I really hope it helps someone lose less days of their lives attempting to see what is going on.

Also, if you know the cause of this, or maybe other pages reporting the same behaviour or, I dare hope, a fix, please let me know.

Wednesday 15 July 2009

Revelation Space by Alastair Reynolds

book cover I had not read a scifi book in quite a while, but then I heard of Alastair Reynolds, once an employee of ESA, and now turned hard sci fi writer. I just had to read something by him and I started with Revelation Space, the first of the Revelation Space universe books, which spans 5 books and several short stories and novellas.

What can I say? I loved the book. Not in a very intellectual way, though. Certainly the universe in which the action takes place is very ingenious and the story full of twists and hi-tech marvels, however, I felt like the writing style was not completely to my liking. The characters are all very much alike, the leaps in logic are pretty big and only to support previous ideas that the book had put forward. It seemed lazy to me. But I did say I loved the book, once I got over the "revelation" that the PhD in Astrophysics and the ESA work did not compel Mr. Reynolds to be very thorough. Besides, it's only the first volume. Maybe the next ones will be more natural, now that a first book has established the rules of the universe.

Prepare to delve in a place where technology is way more advanced than today, but faster than light travel is not yet possible and the lives of people on spaceships, frozen in stasis and moving at relativistic speeds, feel like weeks have passed between a world and another, while for the people on the planets decades or even centuries have passed. Extinct races, time spans of billions of years and impressive armament (both in the physical and virtual realms), favourably offset the fact that humans are pretty much the same and they all sound like Asimov characters :)

Monday 13 July 2009

jQuery UI resizable plugin - relative position issues and external handles

Well, I have been trying to build this control and from day one I had weird issues with the display on Internet Explorer 7. Apparently, because of a bug Rick Strahl reported in his blog, elements that have the position relative escape their containers when the containers themselves are not relative. You will see there a comment from me when I hadn't really understood the problem :(

With the jQuery UI resizable plugin, the base functionality is to change the entire body of the resized control to position relative, causing all kind of trouble, only to permit the resize handles to move around the element (like the south handle having a bottom setting of aproximately 0 px). So, after making all kinds of changes to the javascript in order to solve the IE7 relative position bug, I finally submited and started changing the resizable plugin itself.

The idea was simple: remove position relative, make two divs, one inner and one outer, resize them both in the same time, while another div placed in between would act as the south handle. But it didn't work. I couldn't set an element external to the resized element as the handle, as explained here.

The fix above, though, doesn't entirely show the dimension of the problem. The resizable plugin is incredibly buggy! The documentation says that you can specify custom handles either as jQuery strings or as elements or jQuery objects. That is not correct, as the handles passed as objects are stored in a handles field, but then another _handles field is initialized and the first completely ignored! Also, as in the post above, you need to bind the javascript events to every external element as well, since the original mouse capturing events are placed only on the resized element.

Ok, so the fix is this:
  • look for a this._handles = $('.ui-resizable-handle', this.element).disableSelection(); line. This is where handles is being ignored. Replace it with:
    if (this.handles) {
    var handles=$('nothingReally');
    for (var i in this.handles)
    handles[handles.length++]=this.handles[i][0];
    this._handles=handles;
    } else {
    this._handles = $('.ui-resizable-handle', this.element)
    }
    $.each(this._handles,function() { $(this).disableSelection(); });
  • look for a _mouseInit: function you will see there a line like this.element.bind... you need to add a similar one underneath for all the handles:
    // Add mouse events for the handles as well
    if (this._handles)
    for (var i=0; i<this._handles.length; i++) {
    $(this._handles[i]).bind('mousedown.'+this.widgetName, function(event) {
    return self._mouseDown(event);
    })
    .bind('click.'+this.widgetName, function(event) {
    if(self._preventClickEvent) {
    self._preventClickEvent = false;
    event.stopImmediatePropagation();
    return false;
    }
    });
    }


The change here allows to pass objects (either elements or jQueries) as handles, thus allowing for external elements to act as handles. Removing 'this.element' from the query is not a good idea in case you want to use more resizable controls on the same page. You want only children of a container to act as handles. It could work to move upwards on the control tree until you can get a child that fits the string jquery, but I think that's overkill.

Hope that helps someone.

Thursday 9 July 2009

GetWebResourceUrl generated WebResources.axd url is invalid

I made a few controls that loaded and included a resource js file. And it all worked well, until I wanted to load the js file from the Page object. The generated url was invalid. After hours of nervewrecking attempts I realised that the problem was I was using control.GetType() to get the type required as a parameter in GetWebResourceUrl. And the page, even if inheriting from a custom page object that resided in the assembly where the embedded resources were, was of the site assembly.

Solution: use GetWebResourceUrl(typeof(knownClassInTheAssembly),resourceName);

Warning: my object was inherited from Page and placed in the necessary assembly. And it still didn't work. It is good to remember that ASP.Net pages are not of the type they inherit from, but a class with the name of the page and that resides in the dynamically generated assembly of the site! So be careful where you use this.GetType()

jQuery Firefox error: Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]

Update 3rd of March 2016: I've tested for this bug with the latest versions of Internet Explorer, Firefox and Chrome, using the latest jQuery libraries (1.12.1, 2.2.1 and 3.0.0.beta) and it could not be reproduced. The rest of the article may be obsolete.

So I am building this new jQuery based control and I am terribly smug about it until I run the test site on FireFox. Kaboom! Nothing is working. Why? Because FireFox has some issues with the computed style on hidden elements and jQuery people just don't want to fix the problem. But hey, jQuery is open source, right?

So, let's detail the problem. Here is a jQuery bug posting that explains far better than I could what is going on. Apparently, the offsetParent of a hidden element is null in FireFox and the jQuery core function returns the document object when null is given as a parameter [ $(null)==document ]. Then running the FireFox specific function for getting the computed style [ document.defaultView.getComputedStyle(element,null) ] throws an error because the element is now document and it has no style, only its body has.

So, why not fix that? The FireFox error text is '[Exception... "Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: /jqueryJsFile/ :: anonymous :: line 1349" data: no]'.

The line number might vary with the type of jQuery file version you are using and the amount of modifications you have done to it. What you should find at said line is something like: var computedStyle = defaultView.getComputedStyle(elem, null);.

Solution: Just add above it if (elem == document) elem = document.body; and it solves this particular issue.

In the minifyied version look for var M=q.getComputedStyle(I,null) and add before it if (I==document) I=document.body;


It would be far more elegant to address the problem where the offsetParent is assumed to be not null, but with so many plugins for jQuery, you can't just test them all.

Wednesday 8 July 2009

PNG images are not displayed!

I met an especially obnoxious situation where I had deployed a perfectly working control library on a server and then, when testing how it worked using the remote browser on that server, I noticed only some of the resources where displayed. Mainly, some PNG files where not loaded.

Funny enough, if I went to the properties of the displayed images I saw their correct size. That actually meant that they were loaded correctly, so it wasn't a WebResource.axd issue. The remote browser was Internet Explorer 7, which has no problems displaying the PNG format. After changing all the images to GIF, I also found a solution for that problem.

Some "security" feature in Windows, especially Windows Server 2003 SP1, but also in SP2, messes with some PNG images being displayed. Probably, that security option was implemented to fix this issue. Here is the Microsoft knowledge base article detailing the fix.

WebResource.axd or ScriptResource.axd do not work!

So you have some embedded resources in your ASP.Net control library and you want to use them. But instead, nothing works. Scripts are not loaded and images are not displayed.

Look in the IIS log files and check for an error like this: "Exception information: Exception type: ArgumentOutOfRangeException Exception message: Specified argument was out of the range of valid values. Parameter name: utcDate".

If you see it, then your assembly where the resources are embedded has the build date into the future! This also applies to the code you just built and the date is correct and the date of the server where you want to copy it to is in the past. It also applies when the time is in the past, as when you are copying it on a server in a different timezone!

Update: There are other reasons why axd files are not loaded. One of them is that some other IHttpHandler (defined in web.config) is messing up with your settings.

Another is that the .axd extension is not defined in the virtual directory mappings (You get the dreaded Webform_PostBackOptions is undefined javascript error). Go to IIS manager to the properties of the virtual directory, click on the Configuration button, select the Mappings tab. You have to have the axd extension defined to open with aspnet_isapi.dll. Warning: there is a checkbox in the properties for the extension mapping called Check that file exists. Make sure it is unchecked, as the WebResource.axd and ScriptResource.axd are not actual files, so the mapping will fail if the check is set! On Windows 2003 there is also a listbox at the bottom of the Mappings tab. Edit it and look for yet another Check that file exists checkbox and, of course, uncheck it.

Tuesday 7 July 2009

jGenerateRefresh jQuery plugin on Github

Ever wanted to bind something to the layout rendering phase of an element in Javascript? This helps, by checking at a fixed interval if the size or position of an element have changed and, if so, firing the 'refresh' custom event. All one has to do is then bind to it.

Github page: https://github.com/Siderite/jGenerateRefresh
JQuery plugins page: http://plugins.jquery.com/node/9030

Example:
$(function() { 
$('#target').bind('refresh',{},someRefreshFunction);
$('#target').generateRefreshEvent(100); // every 100 milliseconds
});

Saturday 4 July 2009

Scrum and XP from the Trenches by Henrik Kniberg

book cover Wow! This book is a must read. Not only because it is short, well written and freely available online, but because it does what very few books manage to do lately: actually showing you how to practically apply the knowledge and the consequences of that. Basically, it's like a technical book with a story.

As the title suggests, Scrum and XP from the Trenches is a book about software management, moving step by step through all the requirements of the management process in a Scrum environment and showing in detail what Henrik's actual implementation was, the problems he encountered, the options he had and why he chose one, the other, or a combination thereof. Even if he talks mostly about Scrum, he does mix in the elements of XP that he thought worthy of borrowing, making this not a book on any management theory, but of a real life process.

As previously mentioned, the book is freely available on InfoQ, although you are highly encouraged to buy the book to support Henrik Kniberg and other endeavours like his. A must have for any manager or team lead, and a very good read for any developer, having the chance to glimpse at a real software work environment.

For me I am glad to have read it and to see more of my current job in the book than the previous one, which means I have actually moved upwards and not only horizontally.

Friday 3 July 2009

To arms, brothers! Fight against the SQL oppression!

It seems that there is a renewal of the non-relational database movement. Since I know nothing about the specifics I will list only a few links that I found relevant:
No to SQL? Anti-database movement gains steam
NOSQL debrief
Neo4j - The Benefits of Graph Databases

Of course, this "revolution" is only gaining momentum because of the huge quantity of data being moved around on the web. There can be no centralised system that could handle Google, Facebook, Amazon data sizes and therefore they all move to distributed systems. Tables are now a hinderance, rather than a programming advantage and object oriented schemas step forward.

Will that change our daily work as developers? Well, only if we decide to use some "live" database system to store our data. As proven by the previous "revolution", relational works pretty well for small systems or networks.

WPF Altered States

As you have probably noticed, a lot of my recent posts have been about WPF. Having to do a demo in this new (for me) technology I had a lot of thing to learn and a lot of brick walls to hit. It was exciting, but also difficult, with new concepts that felt awkward, mind twisting. I even burst one day shouting "I hate WPF".

However, I am now working, temporarily, with ASP.Net (no Silverlight) again. And guess what? At every step where I need to design something, I think in the WPF way and find the web way lacking. Riddle me this, riddle me that. :)

Of course, some might say that this is another proof of my whiny personality. I hate when people say that about me!

Thursday 2 July 2009

A PopEndTag was called without A corresponding PushEndTag

I only met this while working on a Menu control, but who knows, maybe it occurs in other situations as well. Bottom line I wanted to create a CSS friendly Menu without using an adapter. So I inherited from Menu, did some stuff, then Kaboom! "A PopEndTag was called without A corresponding PushEndTag" error.

I could not determine where it cam from. The only helpful article on the net seemed to be one from a guy that also wanted to inherit from Menu. Strangely enough his problem only appeared in Design mode, while mine was a runtime thing. And weirder still, the problem was "solved" by the same ridiculous fix, that of calling an extra
base.RenderBeginTag(writer);
in my RenderBeginTag method override. However, his explanation that is all came from IControlDesignerAccessor did not solve anything for me. Menu only overrides the SetDesignModeState and GetDesignModeState methods from IControlDesignerAccessor and when I also overrode them and removed any code inside, I still got the error.

So, after an hour of searching, I solved it by overriding the Render method with
protected override void Render(HtmlTextWriter writer)
{
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(this);
}
if (this.Items.Count > 0)
{
this.RenderBeginTag(writer);
this.RenderContents(writer);
this.RenderEndTag(writer);
}
}
which is the exact implementation from the original Menu source code, but without the 'false' parameter in RenderContents and RenderEndTag.

Hope it helps someone.

Javascript isnull operator

In C# 2.0 and above there is this new feature of the '??' double question-mark operator that operates like the SQL isnull function. If x is null then x??y will return: x if it is not null and y if x is null.

A bit annoying, though, that Javascript does not have an operator of the sort. Or so I thought. Enter ||, the logical OR operator. In fact, in javascript x||y will return y if x is null. Also if x is undefined, string empty, 0 or false. But it works in a reasonably similar manner. Beats x===null?y:x anyway.

This is called Short Circuit Evaluation, if you want to be pedantic about it. Be aware that you can chain it, too, similar to a Coalesce function:
0 || null || '' || false || undefined || 'something' // result 'something'