Wednesday, 15 August 2012

The Strain, by Guillermo del Toro and Chuck Hogan

One of the vampires kindly posed for us before eating the photographerYes, it's that Guillermo del Toro and he wrote a book, together with this Chuck Hogan dude. Actually he wrote more books, this is part one of the Strain trilogy which, judging by the name, should have been about either a contagion or some sort of pulled muscle, but instead is about vampires.

Now, I don't want to be mean towards poor Guillermo. Vampires, even if really overdone nowadays, are pretty cool. The ones in the book are not even sparkling or talking with a Russian accent, but are vicious creatures that have in mind only one thing: to feed. That makes them the more believable type of vampire, although the technical details that are trying to explain in scientific terms the process of vampirification are complete rubbish.

The book is about a contagion of sort, that of vampirism. A "master" comes in New York (where the hell else), wreaking havoc and turning everybody to vampires. They even say this type of vampire is a virus incarnate, although the analogy gets a little strained (get it?). An old Jew is the only one who knows what vampires truly are and how to fight them and he teams up with this New Yorker epidemiologist (and later a pest control rat hunter second generation Russian) in order to fight this asshole vampire.

This melange of different cultures gives opportunity to talk about the Holocaust and 9/11 and even Romania, all at the same time! The writers shamelessly abuse this without actually connecting these facts with the story in any significant way. That bothered me. I understand people can become a little obsessive over things like this, but what kind of a jerk keeps using them to further their careers and books? Anyway, before turning this into another "stop using Hitler, the Holocaust and 9/11 as arguments" extension of the Godwin law, let's get on with the book.

The writing itself is not bad. The only things that kept me getting out of the atmosphere of the book (except the shamelessness above) were some of the emotional background stories used to describe the beginning of the infestation. I would blame that on me, though, as I am often prone to get annoyed by the feelings of others, especially when they get in the way of a good storyline.

Being a trilogy, the book doesn't really end at The Strain. It's just a broken shard of a whole story. You get some hints on what would happen and also some of the arches are closed by the end of the book, so it isn't completely annoying.

Bottom line: Hmm, it was good, not really a masterpiece. It reads like a movie, with a simple almost linear plot. The thing is that, even if it managed to convey the terror of such an occurrence in general, it didn't really evoke in me feelings of horror or at least some empathy with characters that feel that horror, and that is what I was looking for. I've read the book in under a week, but I am not really prepared to spend another two reading the continuation.

Friday, 10 August 2012

How to force a browser render on elements in Internet Explorer (and other browsers as well)

I know of this method from the good old Internet Explorer 6 days. In order to force the browser to redraw an element, solving weird browser refresh issues, change it's css class. I usually go for element.className+='';. So you see, you don't have to actually change it. Sometimes you need to do this after a bit of code has been executed, so put it all in a setTimeout.

More explicitly, I was trying to solve this weird bug where using jQuery slideUp/slideDown I would get some elements in Internet Explorer 8 to disregard some CSS rules. Mainly the header of a collapsible panel would suddenly and intermittently seem to lose a margin-bottom: 18px !important; rule. In order to fix this instead of panel.slideUp(); I used
panel.slideUp(400/*the default value*/,function() { 
setTimeout(function() {
header.each(function(){
this.className+='';
});
},1);
});
where panel is the collapsible part and header is the clickable part. Same for slideDown.

Do not remove the element having focus in Internet Explorer 9!

I had to fix this weird bug today, where only in IE9 the entire page would freeze suddenly. The only way to get anything done was to select some text or scroll a scrollable area. I was creating an input text field, then, when pressing enter, I would do something with the value and remove the element.

It appears that in Internet Explorer 9 it is wrong to remove the element that holds the focus. Use window.focus(); before you do that.

The perils of instanceof in Javascript

I was having one of those Internet Explorer moments in Javascript, when I wanted to use Array.isArray and I couldn't because it was IE8. So, I thought, I would create my own isArray function and attach it to Array, so that it works cross browser. The issue now was how do I detect if an object in Javascript is an Array.

The instanceOf operator came to mind immediately. After all, don't you do the same thing in C#, compare if an object "is" something? Luckily for me, I checked the Internet and reached the faithful StackOverflow with an answer. The interesting bit was explaining why instanceOf would not work for all cases and that is that objects that cross the frame boundaries have their own version of class.

Let's say that you have two pages and one if having the other in an iframe. Let's call them innovatively testParent and testChild. If you create an array instance in testChild like x=new Array(); or x=[];, then the result of x instanceOf Array will be true in testChild, but false in testParent. That's because the Array in one page is different from Array in the other. And, damn it, it makes sense, too. Imagine you did what I did and added a function to the Array class. Would that class be the same as the Array in the iframe, without the function? What if I decide to add
Array.prototype.indexOf?

So, bottom line: in Javascript, instanceOf will not work in any meaningful way across frame boundaries.

Oh, and just so you do have a good way to check if an object is and array, do this:
var strArray=Object.prototype.toString(new Array());
Array.isArray=function(obj) {
return Object.prototype.toString(obj)==strArray;
}

Tuesday, 7 August 2012

That's the way the world works

I am linking four news items. Do you see the connection?
Standard Chartered accused of over $250bn of illegal transactions to Iran
Kim Dotcom judge rules mansion raid was illegal
Gary McKinnon extradition decision delayed until October
TV Shack founder loses round in extradition battle


So let me break this down for you. A British bank is accused of dealing with Iran, against the American embargo laws, to the sum of 250 billion $. It risks losing its licence to operate in the state of New York.

Kim Dotcom, the mega rich founder of MegaUpload, site used almost exclusively to store and share copyrighted material. There are emails of the employees and his detailing the ways they were sharing links to stuff they knew were copyrighted. The New Zealand government raided their offices, arrested him, prepared him for extradition to the US. He was released on bail and the link above explains how the raid was found to be illegal.

Gary McKinnon, a hacker looking for evidence of the US government suppressing information about UFOs and free energy in their military servers, is fighting against extradition to the US. He did minimal damage, and that according to his accusers (McKinnon denied it), he didn't leak the information, he just snooped. The link above shows he is not being extradited yet as the UK home secretary is busy with the Olympic events. If convicted in the US, he is facing up to 70 years of jail. The problem the US government seems most damaging seems to be the bloated cost of 700000$ to "track and correct" the problems McKinnon allegedly caused. In other words, they want him to pay their security costs.

Richard O'Dwyer has hosted links to copyrighted material (not the materials themselves) on UK servers, where such linking is legal (or may be, the discussion rages on). No matter, he is awaiting extradition to the US, where such practices are apparently illegal. The link above shows he lost the first battle against extradition. If convicted in the US, he is facing up to 10 years of jail.

Now do you see the connection? The smaller you are, the larger the punishment. The deed is irrelevant (especially in Great Britain - not so great now, eh?) as well as any national laws when the US is involved. Frankly, I was expecting something like this from my own government, a ridiculous joke that sways whatever way the other nations say, but not from the UK. Canada almost has the same problem, but there the citizens actually rise up against American influence.

Monday, 6 August 2012

House of Leaves, by Mark Z. Danielewski

It is hard to describe House of Leaves in relation to any other I have read before. It is clearly a masterpiece, a mad foray into personal darkness and schizophrenia, maybe Mark Z. Danielewski's (it is certainly difficult to imagine a non-extraordinary person writing this).

What is it about? At the surface, it involves a guy that works in a tattoo parlor finding some old papers in the apartment of a blind old man and getting obsessed by them. You see, this old man has written an extensive analysis of a house made movie than was released to critical acclaim and that was viewed and analysed by a lot of others. Only the film does not exist, the references are mostly bogus and the people that happen to be real deny any connection with this fictitious film.

Now, the old man, Zampano, has died in a house that was sealed from the outside, with various implements used to cover every open bit from the door and windows. Now Truant, the tattoo guy, is reading the Zampano papers and starts to get similarly affected, being overwhelmed by a subtle horror emanating from the old man's writing.

The film itself is about a guy, Navidson, a famous international photographer, who decides to move with his family to a new house, a gesture of healing and reconnection, as his job often took him away from his wife and two children. This house, though, has a secret. Suddenly, there is a corridor in one of the walls of the house. It is terrifying through his deep black color and the fact that the wall is an exterior wall and no evidence of its space is visible from outside. More than that, the corridor twists randomly and seems to go forever, even changing configuration.

These are not the only dimensions of the book. Indeed, the fact that a terrifying hole in a wall exists in their family home terrifies the wife, who forbids anyone going in there, under the threat of leaving. Navidson, though, an explorer and a man dedicated to committing the world to photo and film, feels the need to explore it. The very house that was supposed to bring the family together, breaks it apart.

Zampano's notes are comprehensive, academic, with references from linguistics, physics, philosophy, psychology and literature. They contain numerous quotes from documents and books written about the film. The notes have a lot of footnotes, that contain not only more details about the analysis, but personal ideas and emotional outbursts.

Now, Truant is not really a scholar, but he transcribes all of Zampano's work and adds his own notes, together with the story of the document and bits of his personal life. He does drugs, goes clubbing and has a lot of sex, all while obsessing over his bosses girlfriend. But it is not enough to switch him from his transcribing work and the dark effects this has on him.

And that's not all, either. At one time a foot note describes Truant going into a random bar and hearing a band singing about something in Zampano's notes. He asks the members of the band and they show him the published version of the House of Leaves, by Zampano, annotated by Johnny Truant. Truant starts seeing more and more horrible versions of his own life, only to switch back to reality and not be sure which is which.

The book itself is written in 3 different colors, emphasizing Truant's and Zampano's notes. The references are often insane, hyperanalysing a single quote or sequence of the film through analogies with psychological complexes, Latin quotes and mathematical analysis of sound when it echoes. The notes often end abruptly and continue with Truant's story that itself ends with no discernible pattern.

However, the story somehow remains cohesive and the feelings of alienation and unspeakable, more: undefinable, horror transpire through the book. The early Truant drug trips go further in defining this weird combination of Lovecraft, Kafka and Philip. K. Dick.

Bottom line: this book is as brilliant as it is insane. I have never read a book like it and I can only bow to the immense effort of constructing it. It is itself like a dark corridor, ever shifting, and totally gigantic. You should read it.

Be forewarned, though, this is ergodic literature. To truly understand it, you need to read it on paper or in PDF form; OCR doesn't really work on this book and various rtf, doc, html versions you might find are probably close to unreadable.

Friday, 3 August 2012

Updating a T-SQL table from rows in the same table

I had to do a very simple Microsoft SQL query in which I wanted to update some of the values in a row from a row in the same table. Actually, the query was already there, but was using two local variables to store the information, then make the update. Something like this:
DECLARE @Var1 INT
DECLARE @Var2 INT
SELECT @Var1=Column1,@Var2=Column2 FROM MyTable WHERE ID=1
UPDATE MyTable SET Column1=@Var1,Column2=@Var2 WHERE ID=2
I really hated that I was using two SQL statements and all that declaring to do a simple update, so I looked up the syntax for the UPDATE statement. It said that if I want to update a table from a source I need to use the FROM keyword, like this:
UPDATE MyTable 
SET Column1=Alias.Column1,Column2=Alias.Column2
FROM MyOtherTable AS Alias
WHERE ID=2
AND Alias.ID=1
As you can see, we use an alias to name another table or query, we use the Alias name for all the conditions for that table and nothing for the conditions on the table we update. Easy, no? I even tested it and it worked. So I tried this:
UPDATE MyTable 
SET Column1=Alias.Column1,Column2=Alias.Column2
FROM MyTable AS Alias
WHERE ID=2
AND Alias.ID=1
I used the same table to update and to alias and it seemed to work. However, the number of updated columns was always 0. Remarkable how difficult it is to find on the net a straight answer about a simple situation like this.

It turns out that even with the alias, MSSql is confusing some things. The solution is to use a query from your table, rather than the name of the table itself. Here is how you do it:
UPDATE MyTable 
SET Column1=Alias.Column1,Column2=Alias.Column2
FROM (SELECT * FROM MyTable) AS Alias
WHERE ID=2
AND Alias.ID=1


SQL 2005 also introduced Common Table Expressions, which can be used to clarify a query. In this case, using a CTE results in the same execution plan and makes the entire query even more convoluted:
WITH Alias(Column1,Column2)
AS (
SELECT Column1, Column2 FROM MyTable
)
UPDATE MyTable
SET Column1=Alias.Column1,Column2=Alias.Column2
FROM Alias
WHERE ID=2
AND Alias.ID=1

Even if the documentation says you can specify a CTE without declaring the column names, I couldn't do it in this situation, I don't know why. I admit I only tried the CTE solution for a minute before discarding it as too verbose.