Tuesday, 13 April 2010

Solution for _WidgetManager undefined error

I started using a script that shows me what javascript errors occur in my blog. I soon found out that there were about 10-20 errors each day, intermittently, the vast majority of them being '_WidgetManager is undefined'. I googled it, of course, only to discover that a lot of people had it, some fix was applied by Google and thus most of the articles on the web were completely unuseful.

Well, what seemed to happen is that some code was added at the end of the blog page, loading a js file, and if the js file was (for some weird reason) not loaded, the script following would throw an error. So I added my own script to create a fake _WidgetManager class just in case the script did not load.

Hoping it might help others, here is the script:
_WidgetInfo=function(){};
_WidgetManager={
_Init:function() {},
_SetPageActionUrl:function() {},
_SetDataContext:function() {},
_SetSystemMarkup:function() {},
_RegisterWidget:function() {}
};

Tuesday, 6 April 2010

Toll the Hounds, by Steven Erikson

Book coverThe eighth book in the Malazan Book of the Fallen series, Toll the Hounds was the worst, I think. First, Steven Erikson experimented with a narrator of sorts, all philosophical and moving the "frame" of the story with wise sounding words that actually sounded fake and convoluted like Kruppe's. Second of all, most of the characters started thinking deeply about all kinds of things that had no real relation to the story, all metaphorical and stuff. Third, the stories themselves were vague, disconnected or filled with "his words brought tears into his eyes" scenes. I swear, even Kallor sheds tears at one moment. The ending was a disappointment too, where the convergence of forces that we got used to in the series seems random and pointless. To top it all off, Fisher Kel Tath made his appearance, thus filling the book with bard poems.

As for the story itself... if you wanted closure on something previous, tough luck. Some new characters, some old ones die (including Hood, how cool is that?) most of the action happens in Darujhistan, while the rest is in Black Coral. No Crippled God at all! Also you may find Wiskeyjack fighting in Hood's army. Didn't they ascend? What is he doing there? Pointless battles abound (and I mean pointless, they are not even strategic, just an enumeration of people starting the fight and then, later on, finishing it. Most of the time the result is pretty much known beforehand, but the battle is honorable or something like that.

Mixed news about the ninth and tenth books in the series. First of all, the series ends! Yes, a huge book, with so many open ends and a great mythos, just ends, because the contract was for ten books. That is both brave and insane in the same time, although I suspect that future books will be scoped in the same universe, just not as part of the Malazan Book of the Fallen series. The books nine and ten will actually be a single two part story, with the ninth ending in a cliffhanger. Erikson apologized for this:

While I am, of course, not known for writing door-stopper tomes, the conclusion of The Malazan Book of the Fallen was, to my mind, always going to demand something more than modern bookbinding technology could accommodate. To date, I have avoided writing cliff-hangers, principally because as a reader I always hated having to wait to find out what happens. Alas, Dust of Dreams is the first half of a two-volume novel, to be concluded with The Crippled God. Accordingly, if you’re looking for resolutions to various story-threads, you won’t find them. Also, do note that there is no epilogue and, structurally, Dust of Dreams does not follow the traditional arc for a novel. To this, all I can ask of you is, please be patient. I know you can do it: after all, you have waited this long, haven't you?

The ninth book, Dust of Dreams, started cool, though, in a KChain Che'Malle city with a Matron giving a Destriant the task of finding a Mortal Sword and a Shield Anvil. The Destriant is human and the Matron is insane. Promising, huh? I was considering waiting for a year and reading both ending books, but how can I now?

Thursday, 25 March 2010

window.postMessage for cross domain communication

There are security concerns when communication between different HTML windows or frames occurs, that is why the communication is one way (from the child to the parent) and only if both windows are from the same domain.

Enter postMessage, an HTML5 feature, that allows sending messages that will be received as message events. Checking the origin (very important) and using with care the event parameter data, a simple string, is all that is required for a good relationship between friendly parties. window.postMessage is or will be implemented in Firefox, Opera, Safari, Chrome and even IE8.

Here is a link that describes the feature: Cross-Window Messaging.

Also, check out the jQuery cross-browser plugin that uses hashes to send data back and forth (naturally, the same mechanism should be implemented at both sides)

Infragistics, SnapToDevicePixels and Utilities.SnapElementToDevicePixels

I was trying to add some content to Infragistics WPF controls and some of the images used were blurry. I have tried setting SnapToDevicePixels, but to no visible effect. I did stumble upon a property in the Infragistics.Windows.Utilities class, called SnapElementToDevicePixels. I didn't know what it does, but I tried it anyway. Voila! The image got crisp and clear.

This is the comment from the property in the Infragistics WPF sources:

/// <summary>
/// SnapElementToDevicePixels Attached Dependency Property
/// </summary>
/// <remarks>
/// <p class="body">The SnapsElementToDevicePixels is meant to be used on elements such as an Image that
/// does not currently support SnapsToDevicePixels.</p>
/// <p class="note"><b>Note:</b> The RenderTransform of the element is used so you should not set the RenderTransform
/// on the same element on which you are setting SnapElementToDevicePixels to true. You may set the RenderTransform on
/// an ancestor element. Also, you should not set this property on an element that is an ancestor of one or more
/// elements that have this property set to true. In such a case the results are undefined since the child element's
/// RenderTransform could be calculated before that of the ancestor element. Since this property should be set on
/// discrete elements such as an Image, this scenario should not be required.</p>/// </remarks>

In order to use it, make sure you load the Infragistics.Windows namespace in your XAML:

xmlns:Windows="clr-namespace:Infragistics.Windows;assembly=Infragistics3.Wpf.v9.2"

and then set the Windows:Utilities.SnapElementToDevicePixels property to True.

Saturday, 20 March 2010

Using NetCat (nc) running in the background

Short version: use nc -dl portNumber instead of just -l

Netcat is a nice little tool that is very useful in all kinds of networking problems. Basically it listens on a port and it sends to ports via TCP/IP. Using the piping mechanism of Linux, one can send anything, from files compressed on the fly in the network stream to telnet sessions and back doors.

Today I was trying to copy a few files from a computer to another, therefore I did something like this:
tar -c -C /source/folder file1 file2 file3 | nc theOtherComputer portNumber
on the second computer I did this:
nc -l portNumber | tar -x /destination/folder

And it worked perfectly. I made all kinds of cool stuff in the bash scripts and then, wanting to execute the "server" in the background I did:
serverApp &

From then on, nothing worked. The sender would report success, the received file would always be truncated. After trying all kinds of things, I stumbled upon the -d switch of the nc tool. The man page says: -d' Do not attempt to read from stdin.. It appears the application is trying to keep a reference to the input of the starting environment. It makes no sense for a listening scenario, but it does it anyway. Failing to find one (since it is runnning in the background), it just exits earlier than expected.

So, whenever you want to use NetCat listening in the background, don't forget to use the -d switch.

Monday, 15 March 2010

Reaper's Gale by Steven Erikson

Book coverReaper's Gale, the seventh book in Steven Erikson's series called The Malazan Book of the Fallen made me feel all kinds of things. There was boredom a lot of times, there was uncomprehension in others, there were moments when tears flowed from my eyes as well as great moments of tension. At the end of it, I feel unqualified to actually discuss it. It is still a great book, it ends with a convergence of paths, as all the others have, but it somehow felt different from the previous six books.

I believe that Erikson fell into a well known writer trap. He was so caught in his own world, that he forgot most readers are not, and cannot be unless with great effort. Therefore the characters got out of control. They did things as they pleased, regardless of the reader's need. That is why I think this book was weak compared to the others.

The plot is too complex to expand here. Enough said that Icarium, Karsa Orlong, Quick Ben, Mael, The Errant, Fiddler and Hedge, Bottle and Beak, The Adjunct and Lostara Yil and all the Bonehunters, they all meet in Letheras. Even after reading the book you don't get to know why all that buildup was for, why in the last 50 pages all the characters acted so strangely, where Karsa and Icarium went and, most of all, why did a woman Seguleh have such a small part! The dragons (all of them) are beaten senseless, the Sengars have the worst of luck and the t'Lann Imass are just peripheral characters.

As did the sixth book, but at a larger scale, more avenues are opened than closed. I can barely wait reading the eight book, but I feel cheated a bit. Hope lives on, though :)

Thursday, 11 March 2010

The collapse of capitalism

Yesterday I was talking with friends of a weird situation near my home: there are 3 pharmacies in the same building and 3 others very close by. Well, pharmacies and banks have the same business model, if you think about it, so no wonder there. What felt a bit strange is that in the building there was the pharmacy that I have been buying medicine from my youth and recently it was bought by one of the larger pharmaceutical chains and converted into a flashy, colorful and very expensive venture. The same happened to a company called Plafar, a Romanian company opened in 1999 with state capital which specialized in natural remedies, infusions and so on. In 2007 it was purchased by a pharmaceutical chain that loses its origin in the vagaries of stock exchange. Now all they sell is terribly expensive as well.

So yes, I think that is strange as seen from the naive view of free market in capitalism. You have a competitive segment of the market, providing no bullshit service at low price, being bought and replaced by the people that gain at least half of their money by overpricing. It's like a virus (A virus enters a bar. The bartender says "We don't serve viruses in here". The virus replaces the bartender with a copy of its own and says "Now you do") and it spreads especially fast in a low immunity environment like a freshly "liberated" country like Romania.

What is going on here? Well, since we are in the medical/pharmaceutical context, let's address the notion of economic health. At economics.about.com they say The value of stock market indices seem to be the barometer many use for the health of the economy.. Well, that is not what I had in mind. What I think is health in an economy is how fresh growth is not hindered, but nurtured. Just as in the human body, disease impedes growth and disables functioning mechanisms that are vital to life. Are other countries healthy? No! They are in the same kind of crap, only there it is harder to suffocate others.

Is there a solution? I don't know. But a full ecosystem is needed to promote health. When only predators remain, the land dies.