Jul 29 2007

How to add a body on load function with Javascript

Posted by Hoakz in Programming

This is an article on how to add a javascript function that will be run when a webpage has loaded. We begin by defining a function for running after a page (or actually window) has been loaded:

function bodyOnLoad() {
  ..
  ..
}

And then we’ll do:

window.onload = bodyOnLoad;

However, we also want to make sure our setting of the load event doesn’t remove some other setting. This is done by also keeping any older events.

We store the previous on load even by doing;

var prevOnLoad = window.onload;

And we redefine our bodyOnLoad function:

function bodyOnLoad() {
  prevOnLoad();
  ..
  ..
}

However we can make the creation of the function and the setting of the event a little bit more effective by doing:

window.onload = function() {
  prevOnLoad();

  ..
  ..
}

You still need to get prevonload before you do that

This becomes even more obvious once we create a function for adding new load events:

function addLoadEvent(func) {
  var prevOnLoad = window.onload;
  window.onload = function() {
    prevOnLoad();
    func();
  }
}

In this way we can concentrate on creating the new load event outside of the function for adding it to the window.onload.

function myEvent(){
  ..
  ..
}
addLoadEvent(myEvent);

We might even do:

addLoadEvent(
  function (){
    ..
    ..
  }
);

Notice the difference between curly braces “{}” and parenthesis “()”

Finally, we have to make sure there is a load event set for the window before calling it from the new event, so we need to check for this:

function addLoadEvent(func) {
  var prevOnLoad = window.onload;
  if (typeof prevOnLoad != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      prevOnLoad();
      func();
    }
  }
}

Share/Save/Bookmark

Jul 18 2007

Review: Faster, Pussycat! Kill! Kill! (1/5)

Posted by Hoakz in Movies and TV

“Faster, Pussycat! Kill! Kill!” (IMDB, Amazon) is about three strippers Varla (Tura Satana), Rosie (Haji) and Billie (Lori Williams) out in the desert looking for thrills. They come across Linda (Sue Bernard) and her boyfriend Tommy (Ray Barlow). After killing Tommy, they take Linda hostage. At a nearby petrol station they are tipped off about an old, crippled man (Stuart Lancaster) living in the desert with a fortune. They decide to liberate him of his money. All they need to do is get past his two sons (Dennis Busch and Paul Trinka). However, it turns out the old man has an agenda of his own and most of the cast end up knife stabbed or hit by cars before we reach the end of the movie…

I have to admit, this movie is from 1965, and apparently, the way they acted in the 60ies are just not in my taste.

This film has huge problems with the script. Let us start with the name. When someone calls something “Faster, Pussycat! Kill! Kill!” at least I get an image of some kind of incitement/hunt/stress scene. My imagination was that the three “evil” strippers would incite the poor innocent girl to kill some other poor innocent victim. As it turns out, the script contains very little incitement, actually very little action at all.

The lack of action is, obviously, the main problem of this script. The characters (part from Paul Trinka’s Kirk) are all trying to ”be” instead of ”doing”. The three girls go around and snarl and talk “tough” but sadly enough the script fails them; there are virtually no cruelty or toughness for them to act on, leaving the poor actors to try and ”be” as good as they can, which of course just looks silly. This failure also rubs off on the victim of the story, Linda, making her fear and anxiety seem plastic and phony as well.

The script had me cringing more than once from the outright ridiculous plot turns. Especially the scene at the gas station where the station attendant tip the girls off about the old man, had me thinking of those good old days when I participated in high-school plays.

The script doesn’t give much credit to the human psyche either, and it utilizes the “linear cause-effect” type of psychology. For instance, the old man lost his ability to walk when he saved a girl from being hit by a train, so obviously, now he hates trains and girls…

If you want to see how to write a script that will kill all the characters mercilessly, then watch this flick (and by “kill” I don’t mean “blood-bath”-kill, unfortunately, even splatter would have made this less painful… most of the characters die, that’s true but they’re dead long before that happens). Or if you just feel that the good old classics has to be good, old and classic, then watch it and suit yourself! ;o)

I give “Faster, Pussycat! Kill! Kill!” 1 point of 5. (I’m not gonna f-up my own system by starting to deal out zeroes and minuses but I am pretty tempted…)

Share/Save/Bookmark

Jul 17 2007

Programming humor

Posted by Hoakz in Programming

In case you wondered. Sure, programming can be humorous, but this is more about looking at programming with humor. Or, well I’ve found a few funny things I’d like to share… XML is like violence: if it doesn’t solve your problem, you’re not using enough of it.

People who make buttumptions about their search and replace options, will be embarbutted when they repeat this clbuttic mistake.

Share/Save/Bookmark

Jul 13 2007

At day’s end

Posted by Hoakz in Poetry

At day’s end
when crickets sing
and darkness fall
the evening might turn cold
but no less beautiful

Share/Save/Bookmark

Jul 13 2007

Review: Paycheck – Let the future be untold (4/5)

Posted by Hoakz in Movies and TV

Paycheck (IMDB, Amazon) is a story about Michael Jennings (Ben Affleck) who is an engineer, or to be more precise a reverse engineer. Michael is paid to take competitor’s work and reverse engineer it into something his employees can make into a products of their own.

Since it would be very bad if information about whose technology was reverse engineered into what, Michael’s assistant Shorty (Paul Giamatti) helps removing all of Michael’s memories of the project once work is finished.

A once in a lifetime opportunity comes along as Michael’s old friend Rethrick (Aaron Eckhart) offers him work that will give him stocks in Rethrick’s promised-to-become-great company. Michael takes on the three year project, even if he risks losing his memory for the whole period, and that of a probably blooming romance with one of Rethrick’s employees, doctor in biochemistry, Rachel Porter (Uma Thurman).

Three years passes, Michael finds himself back where he once begun, in Rethrick’s office, his memory wiped and all that stands between him and his millions, a trip to the bank.

That is however, when problem starts, because Michael finds not only has he switched the personal effects he once had to leave before entering Rethrick’s employee, he has also forfeited a 100 million dollars worth of stocks in Rethrick’s company.

Why did Michael say no to the money and, of significantly less importance, what became of his personal effects? Michael soon realizes his former employees and the FBI are out to get him, and his bag of assorted effects seems to be the only thing that keeps him ahead of the game. A game, that if lost, could cost him his life…

You can read the whole review by clicking the below link, but there may be spoilers in that text…

Read entire article.

Share/Save/Bookmark

Jul 09 2007

Programming booleans

Posted by Hoakz in Programming

When looking at other programmer’s code I’m sometimes surprised with things like this:

exportDocumentView(java.lang.String absPath, java.io.OutputStream out,
boolean skipBinary, boolean noRecurse)

And in such prominent frameworks as Java Content Repository as well.

What’s my problem then? Double negations. In order to do exportDocumentView and get binary data and recursive export you’ll need to do:

exportDocumentView(“/path/to/my/Node/”, System.out, false, false)

Sure I can handle it… but… false to opt something in? I find it rather fishy. Call me an idiot but my brain just don’t deal with that kind of stuff easily…

What I would have wanted instead was:

exportDocumentView(java.lang.String absPath, java.io.OutputStream out,
boolean includeBinary, boolean recursive)

Which would have been called like:

exportDocumentView(“/path/to/my/Node/”, System.out, true, true)

For when we want binary data and recursive export, and like this for the case when we don’t want either or both:

exportDocumentView(“/path/to/my/Node/”, System.out, false, true)
exportDocumentView(“/path/to/my/Node/”, System.out, true, false)
exportDocumentView(“/path/to/my/Node/”, System.out, false, false)

I’m just saying. In my world false means “no” and “no” means don’t give me something or don’t do something:

“Don’t return binary data.”
“Don’t recurse the tree of nodes.”

To be compared with:

“Don’t skip binary data.”
“Don’t do no recursing.”

(But you’re free to curse? :o )

Share/Save/Bookmark

Jul 08 2007

He heard her own gasp of astonishment

Posted by Hoakz in Creative Writing

I just read the following sentence:

“He heard her own gasp of astonishment”

Some words just don’t work well with things no one else can do for you, I mean…

I entered the room and guess if I was surprised. My neighbor gasped with my astonishment, and as he had one of my thoughts, he came over to my own apartment to have a talk with me. He told me, with his wife’s voice, he disliked all but his own ideas. I had one of his ideas and in a contrary to his position, decided I liked it, so I made it my own idea.

It could get pretty interesting after a while of that. Perhaps the next pop-style of writing…?

Share/Save/Bookmark

Jul 08 2007

Review: Ultraviolet – Xenophobia (3/5)

Posted by Hoakz in Movies and TV

Ultraviolet (IMDB, Amazon) is a story about Violet, an ordinary woman whose life changed when she was infected by a virus that turned her into a feared and hated hemophage.

Once contracting hemophagia, Violet was incarcerated and experimented on, and perhaps these experiments cost her the child she was bearing when infected, perhaps the infection itself did, regardless, Violet escaped and now she is out to steal the government’s latest and most deadly weapon in the fight against hemophages.

The hemophages have superhuman strength and speed, but at a cost; few live longer than a decade. Since the virus that causes hemophagism infect on blood contact, the number of hemophages should have grown had it not been for the government’s prosecution.

Like vampires the hemophages have pointy eyeteeth, but unlike the vampires they do not require sucking blood and taking lives to survive. They are far from demons, and rather unfortunates infected by a deadly and infectious disease, and the only demon thing about them is the demonizing of them done by the government.

You can read the whole review by clicking the below link, but there may be spoilers in that text…

Read entire article.

Share/Save/Bookmark

Jul 08 2007

Show and tell

Posted by Hoakz in Creative Writing

I am sure you have come across this advice if you have read about creative writing:

“Show, don’t tell.”

It has been repeated in several discussions I’ve had and books I’ve read. Being from Northern Europe (Sweden to be precise) some of the literature I’ve grown up with does the opposite. It tells a story. Very little details, broad strokes, brushed by in high speed.

The good thing with showing, instead of telling, is that the story reveals lots of details that can easily capture the audience. You get to feel, hear, see, smell, taste what the characters experience. You get to “be there.”

However, there are other concerns than revealing detail. The downside to showing instead of telling is that everything takes forever. You can hardly have a character sneeze without writing half a page about it.

Stories that show too much lose tempo, and become dreadfully long. I’ve seen amateur authors write a normal sized story (say about 3-400 pages soft cover) in twice, three even five times the number of pages, and when you analyze the story for this specific aspect you find everything is shown in painstaking detail.

I’m willing to bet, if you take your favorite book or author and analyze their texts you will find both showing and telling. This is done because showing gives detail, whereas telling gives speed, and higher tempo.

With telling you can manage the weekend trip to aunt Ruthie’s in a page, even half a page, with showing you could spend the whole book writing about it (I’m sure several authors have).

I can think of one reason this rather strange advice has been introduced in books on creative writing; it may have been borrowed from books on screen writing. When writing a manuscript (for the movies or the stage) being visual and showing details becomes important, unless the characters will start blathering the piece to shreds, or the crew filming the whole thing will have to improvise details. However, recent developments in movies have introduced a narrator as a story telling tool, and the theater has had story telling in it from the beginning (story telling may even have been the beginning of theater).

Telling or showing can both be as capturing for the reader if done right. When to use which becomes a question of what story you are telling, the rhythm versus details, and the ultimate measure is more about feeling than anything else. You have to read and write until you gain an ear for when to show and when to tell, in order to write the story you want with the rhythm that will capture audience the most…

Share/Save/Bookmark

Jul 08 2007

DVDs catching up?

Posted by Hoakz in Computer Architecture

Once upon a time a CD was large. Huge. You used it to save lots and lots of data.

Then came MP3s, movies, digital cameras with millions of pixels and suddenly the CD was small. And the DVD came, and for a while it was large… I don’t think it ever was huge.

Today I would have to use more than 300 4.4 GB DVDs to save all my data, and that only includes the data on hard drives. Making back-ups becomes a question of selecting what to back-up and what to leave for chance. A real pain.

But there might be light at the end of the tunnel.

Researches at the Technical University of Berlin claims they’ve managed to put up to 500 GB of data on a CD/DVD-sized disc

This is (layman’s interpretation) done by using holograms. The disc is transparent (wonder how that will work with labeling?) and uses ten layers of data (to compare with blu-rays that use two, and ordinary DVDs that use one). Anyway, sometime around 2010 they might be able to fit as much as 1 Terabyte to a CD-sized disc.

That’s probably the same time as hard drives comes in 10-20 Terabyte sizes, and soon after the 1TB DVD will once more be insufficient.

Wheehoo…

Share/Save/Bookmark