Random Thought of the Day

February 8th, 2010

Ever had this crazy awesome vision in your head but just can’t get it down into a physical format? It could be an idea for a project, a solution to an issue, whatever. Well, that’s basically the sort of problem I’ve been dealing with for the past few weeks or so.

The problem: create a design for the front page of my site (and perhaps this blog too, in time). The vision: a dark theme, using fantasy and sci-fi material as inspiration (planets, stars, floating islands…). The solution: uhh…?

I call it “creative paralysis”. It’s something similar to writer’s block (which, incidentally, I happen to encounter constantly when I’m writing academic papers and such). I suppose it’s different in that the idea is already at hand; the issue is figuring out what to do with it.

For me, I’m thinking that my lack of experience in Photoshop (and artistic skills in general) is holding me back. I’ll probably end up messing around randomly and hope things work out. Who knows, I might actually learn something in the process…

I probably have a few hundred or so images in my head that I’d love to get on paper. Hell, my lucid dreams can probably form the basis of several short stories. Now, if only the details were a bit clearer… :P

Seriously, if there was a machine that could materialize thoughts into physical matter, I’d venture to say that we’d be living in a rather interesting world. ;) In the meantime, I’d be happy if virtual/augmented reality stuff went mainstream.

Bleach (Episode 256)

February 8th, 2010

…and so the filler continues. I’m not entirely sure I like where this is heading; personally, I thought the last episode would have ended this arc rather nicely. However, I’m willing to give the writers the benefit of the doubt. They did manage to get a pretty intriguing storyline going after all… I’m just hoping that it doesn’t end on a sour note. ;)

You can watch the episode here.

The Hype Surrounding Apple’s iPad

January 28th, 2010

Geez, Apple’s hype machine is ridiculous. Pretty much every other news story and tweet I’ve been reading had some sort of reference to the iPad. Just take a look at TechCrunch and Techmeme over the last day and a bit – I’m hoping no company was stupid enough to release anything that day. :P

Building a Web Scraper Using JavaScript and jQuery

January 25th, 2010

When building web applications, sometimes there’s a need to fetch data from other sources. Perhaps you’re building a custom RSS feed of news items based on your interests or you want to aggregate data from several sites. In any case, it’s not always possible to do this elegantly; you may not have direct access to the raw data and an existing API may not exist. For these situations there’s one general (albeit fragile) solution: manually parse the end result when a page is loaded in a browser.

There are many different ways to build a web scraper. A server-side language such as PHP will have a much easier time as there are less limitations and existing libraries (such as cURL) to accomplish the task. I’ll be using JavaScript (with the jQuery library), however, as I want a standalone client independent of server technology.

Let’s start with a random snippet of code:

1
2
3
4
5
6
7
8
9
10
11
12
function fetchPage(url) {
    $.ajax({
        type: "GET",
        url: url,
        error: function(request, status) {
            alert('Error fetching ' + url);
        },
        success: function(data) {
            parse(data.responseText);
        }
    });
}

The above function attempts to make an AJAX call to a specified web page, fetch the HTML of said page and pass it to a parsing function. Simple enough, right?

Unfortunately there’s a little problem with this. Client-side programming languages have to deal with something called the same origin policy which basically restricts scripts from accessing external domains. From a security standpoint this is obviously a good thing; however it can be a headache for web app. developers (indeed, there are ideas such as the origin HTTP header to solve this). (The following bit can be ignored if the scraper is on the same domain as the data source – but in such a case why is said scraper even necessary?)

In this case, there are a couple of solutions (that I can think of). Both of them take advantage of the fact that JavaScript can read JSON even if it is located on a different domain.

  • The first one is writing a complementary server-side script that takes a few arguments (such as the target URL), makes the call, parses the result into JSON format and passes it back to the calling function. It’s a simple idea, but I never really liked it because it introduced a major dependency (which, in my case, can be a pain to deal with). However, it’s definitely a viable solution which works extremely well.
  • The second is using an existing system such as Yahoo’s YQL to fetch the required data and return it in a structured form. This is the method that I’ll be using.

YQL is an interesting little beast. From their site:

The Yahoo! Query Language is an expressive SQL-like language that lets you query, filter, and join data across Web services. With YQL, apps run faster with fewer lines of code and a smaller network footprint.

I haven’t had too much time to look into it so I do what all programmers do: Google the living crap out of a problem to find a solution. :P In this case, Chris Heilmann has a great post on how to load external content via. various methods including YQL. To simplify things, James Padolsey wrote a plugin that detects an external AJAX call and passes it to YQL automatically.

Anyway, that solves the problem of fetching data from an external source. All that’s left is extracting the relevant pieces for whatever application is being built. Consider the following example:

1
2
3
function parse(data) {
    alert($(data).find("h1").text());
}

The parse() function takes the responseText data from the earlier fetchPage() function and then proceeds to pick at it slowly and painfully. What’s really cool about it is that pretty much all of jQuery’s selectors can be used to select relevant data. In the above case, I’m trying to extract text inside the first <h1> tag found on a page and outputting it as an alert to the browser. Obviously there are more complex uses for this but they are outside the scope of this post. :P

And…that’s it! :D Those two code blocks combined pretty much handles all of the grunt-work in extracting data from external sources. Again, this is a rather fragile solution – it can break if the target page’s HTML changes (one possible solution is to pick unique identifiers or classes). In addition, some sites may have restrictions on their data – but I’m sure everyone reads those long-winded documents. ;)

“What’s Your Fastest Text Input Tool?”

January 24th, 2010

Here’s an interesting post on Lifehacker: What’s Your Fastest Text Input Tool?.

I’ve been using full-sized keyboards for a *very* long time now so that blows everything else out of the water for me. When I’m motivated I can type at speeds exceeding 100 words per minute, although that’s typically not necessary with the stuff I do.

I’d rank pen and paper as second. It’s pretty much a necessity in university when you’re taking down notes and whatnot. Although some people can get away with using laptops in class, I find that it’s extremely hard to copy out diagrams and mathematical equations. Perhaps this is some indication that I should learn LaTeX or something? :P

Next up would probably be a close race between my Wacom tablet (using Window’s handwriting recognition software) and my iPod Touch. I’m still rather slow at both, although that might just be because of a lack of practice.

In last place is a standard phone with a three-letters-per-number keypad. Yeah. I don’t use my phone very often and I text even less. :P

Fairy Tail (Chapter 167)

January 19th, 2010

Looks like the latest chapter of Fairy Tail came out a day or so ago (geez, MangaStream is ridiculously fast when it comes to releasing stuff – it didn’t appear on One Manga until much later).

Links:

Anyway, I really like how Gajeel is desperately looking for a cat. He must have gotten pwned pretty badly with all those scratches on his face. ;) Something tells me there’s more to them than meets the eye; the conversation between Charle and Happy raises a few bells.

We see Mystogan reveal some of his history with Wendy as well. I’m pretty sure this is the first time he’s done so in the series. :P It kind of reduces the impact of Gildarts’ arrival in the previous chapter though.

Speaking of Gildarts, I find it interesting to see that he has Ivan Deyar listed under “dislikes” on his guild card at the beginning of the chapter. There must have been some interesting things going on between them during their time together at Fairy Tail.

It looks like we’re in for a new plot arc as well, although it seems kind of sudden. What’s with this “Anima” that Mystogan was talking about and how can it destroy Magnolia before everyone can escape? Eh, we’ll see…

The “A” in “AJAX”

January 16th, 2010

Consider the following code snippet using JavaScript (with the jQuery library):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function blah() {
    var pagedata;
    $.ajax({
        type: "GET",
        url: "test.php",
        error: function(request, error) {
            alert("Error: " + error);
        },
        success: function(data) {
            pagedata = data;
        }
    });
    return pagedata;
}

Looks reasonable enough. The purpose of the function is to make a GET request to some page (“test.php” in this case), store the result in a temporary variable and return said variable (of type string).

However, it turns out that this doesn’t work too well. When the function is called, chances are pretty good that the returned string is empty. Why? At first I thought it was because of some weird variable scoping rules in JavaScript, but that didn’t really make too much sense.

It turns out that I forgot about the “A” in “AJAX” (i.e. Asynchronous JavaScript and XML). The function above doesn’t execute in a top-bottom manner; the $.ajax() call is made in parallel with the rest of the script. Generally this isn’t too much of a problem (indeed, it’s a valued property by those making web applications) but in this case it isn’t what I want.

Anyway, there’s a simple solution to this. What I want to do is make the call synchronous with the rest of the script. Fortunately, jQuery makes this extremely easy in the $.ajax() method by providing an option (async: false) to turn this off. Thus:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function blah() {
    var pagedata;
    $.ajax({
        async: false,
        type: "GET",
        url: "test.php",
        error: function(request, error) {
            alert("Error: " + error);
        },
        success: function(data) {
            pagedata = data;
        }
    });
    return pagedata;
}

This locks up the browser while the call is being made so it’s probably not the best solution. It shouldn’t matter too much with small requests though (or requests made with the user’s consent via. the UI or something).

Avatar

January 11th, 2010

Throughout the last month or so, I’ve been hearing a lot about James Cameron’s Avatar (words such as “revolutionizing”, “awesomesauce”, “epic”, etc. come to mind). So I finally got to see it last Friday at West Edmonton Mall’s Scotiabank Theatre. I’d say the movie lives up to its hype. :P

The first thing I found out was that the entire movie is in 3-D. I was never a big fan of wearing those funky glasses (and indeed, they’re pretty annoying for anyone wearing actual glasses) but it’s a minor issue for me. Perhaps one day we’ll have true 3-D in the theatres (think holo-projectors). I can dream, right?

Anyway, the movie starts off with Jake Sully – a paraplegic (former) marine – joining the avatar program on Pandora, an Earth-like moon with its own unique environment. The goal of the program is to improve relations with Pandora’s natives so that a human mining operation can continue in peace. Throughout the movie we see Jake slowly preferring his avatar’s lifestyle to his own (Jake’s avatar is a biologically-engineered version of one of the natives, the Na’vi). One major recurring theme is how damaging human tendencies can be on an environment (in this case, making war on the natural inhabitants all in the name of profit); in this aspect I was drawing comparisons between Avatar and Princess Mononoke.

The visuals and animation were mind-blowing. I expected nothing less from a movie whose official budget of $237M makes it one of the most expensive ever made. The 3-D aspect was interesting and really brought out Pandora’s natural beauty; throughout the movie the atmosphere seemed realistic, the native species lifelike. I’d say Avatar is one of the few movies that can truly be comparable to a high fantasy novel. It definitely had an impact on my imagination in any case. ;)

Most of the major characters were well-developed. They each had their own beliefs and act accordingly no matter the consequences.  Trudy – a fighter pilot – best summarizes this when she abandons the first human-Na’vi conflict with a “fuck this” and subsequently aids Jake and the rest of the avatar team in the second. It was very possible to relate to them (which adds to the emotional factor when some of them die).

All in all, I’d say Avatar is one of those movies that everyone should watch. Heck, I wouldn’t mind watching it a second time if I can find an IMAX theatre near me. ;)

A New Moon in 2012

December 31st, 2009

I had the (dubious?) pleasure of watching New Moon and 2012 over the last week at West Edmonton Mall’s Scotiabank Theatre. Here are my thoughts on those two movies… :P

Let’s start with New Moon. First of all, I haven’t read Meyer’s books so I can’t really do a fair comparison between the two. In general I much prefer doing the readings since a lot of details tend to get lost in translation – there’s only so much that can fit in a 2-3 hour movie! I did attend an early screening of Twilight last year however (in which my enjoyment of the movie was negatively impacted by rabid fans screaming in my ears).

Bella (as a character) is uninspiring. To be honest, I still don’t have a clue on how she became the love interest of two other characters. She has next-to-zero hobbies, is consistently gloomy and is melodramatic. For someone nearing adulthood, she’s emotionally weak (well past dangerous territory). It reminds me of those classical fairy tales in which we have a damsel-in-distress rescued by some random knight-in-shining-armour. Haven’t we gotten past those stereotypical views already?

Similar to Twilight, most of the supporting characters contributed little to the plot. They could pretty much be pulled out of the movie without seriously affecting the outcome of the story. That’s kind of disappointing since it really makes them seem two-dimensional. Of course, this is probably an artifact of the movie translation; it’s probably a lot better in the books (someone please tell me that it is). :P Some mini-arcs seem kind of redundant as well. For example, what purpose did sending Charlie et al. wolf hunting serve? I was hoping for a twist – that a heavily guarded secret would be leaked to the public. Unfortunately, nope. :(

As a whole, I thought New Moon was relatively predictable and slow. In fact, I made it almost like a game, guessing the chain of events as they unfolded (and then there were some – like Jacob being a werewolf – that were too ridiculously obvious to not get at first sight). Perhaps it’s just the fact that I have no real interest in the romantic genre, but there’s a problem when my sister (who is clearly in the crosshairs of the series’ target audience) picks up on some of these issues. :P I did enjoy the action and computer animated scenes though, few and far between as they were; Jacob in wolf form is cool. ;)

Moving on. 2012 is one  of those oh-my-gawd-the-end-is-near-please-help-ahhh apocalyptic movies in which the world order collapses and is reborn in a new light. The basis of  the movie is the 2012 phenomenon which is essentially a conglomerate of beliefs that cataclysmic events will happen throughout that year (more details can be found on Wikipedia). Though the general theme has been recycled millions of times, the movie still provides ample entertainment and even *gasp* some things think about.

I thought the beginning was rather fragmented and confusing especially since it glossed over three years. It did provide a quick introduction to all the main characters though (as well as why humanity was screwed) so I’m willing to let that slide. We have Jackson (a writer-turned-driver) as the unlikely protagonist of the story along with his children (Noah and Lilly) and his divorced wife Kate. Gordon – Kate’s current boyfriend – joins the ride as the five dodge calamity after calamity. Geologist Adrian Helmsley becomes the focal character in providing a lot of background information on the impending event.

The action in the movie was as expected: pure awesome. The computer animation might have been overdone but it was still exciting to watch – especially if you just want to switch off your brain and see stuff explode. :P Speaking of which, I still haven’t watched the latest Transformers movie…

Scientific explanations were reasonably adequate for those with a very basic education in geology and astronomy (i.e. knowledge of fault lines, magnetic fields, solar flares). I suspect those true geologists and astronomists would object however. :P It’s about as close as one can get when dealing with a topic with few, if any, factual basis.

Character development was alright for a movie in this genre. I liked how Noah – initially portrayed as a stubborn, pessimistic kid – gradually accepted Jackson as the movie progressed. Many of the more selfish and arrogant characters like Yuri and Tamara displayed compassion in strenuous situations. It’s surprising how much people can change in a short period of time…

In a nutshell, the movie attempts to show collective human behaviour in the face of impending danger. I think the other message it was trying to convey is how woefully unprepared we are should we face disaster. Given, for example, how Hurricane Katrina was handled in the U.S.,  that wouldn’t be too much of a stretch. Overall, I thought 2012 was decent entertainment (me being the ooh-stuff-is-blowing-up type). :D

Future Plans at UW

December 21st, 2009

It looks like I’ll be entering the second half of my university career next term. Wow – time has definitely flew by quickly. It wasn’t that long ago that I was a frosh looking to find meaning in life… :P

I suppose it’s about time that I start specializing in topics that I enjoy. After 3A I don’t have any real required courses so I have a multitude of options. Heck, even in 3A I only have 2 courses that I absolutely have to take (CS 341: Algorithms and CS 350: Operating Systems). That pretty much leaves ~18 slots to complete various degree requirements and whatnot. Woot.

From the beginning I knew I was going to lean heavily towards business. I finally formalized my plan change today and added the option in (it’s essentially a minor that isn’t a minor). I don’t know how much it really matters, but eh.

Anyway, for my 3A term I’ll likely be taking CS 348 (Introduction to Database Management), PSYCH 338 (Organizational Psychology) and BUS 352W (Introduction to Marketing Management) along with the two listed above. That looks like a pretty decent selection. :D I might make some changes depending on various factors of course.

After that… Well, there’s a number of courses that I can take. I guess I’ll break it down for future reference.

  • BUS 362W (Building and Managing Products, Services and Brands) will likely be the last business course I’ll enroll in to fulfill a couple of requirements. It’s the successor to BUS 352W (I suppose that’s why the course number was changed) and the topic itself looks pretty interesting.
  • ENGL 119 (Communications in Mathematics & Computer Science) and CS 492 (The Social Implications of Computing) are “required” courses for the business option. I don’t really have any further comments at this point.
  • CS 370 is a prerequisite for a course I want to take. It appears to be a whole lot of math. :P I’m just hoping it’s more applied than theoretical.
  • CS 488 (Introduction to Computer Graphics) is pretty much the course I’ve been looking forward to since my first term here at UW. Graphics has always been one of the few topics that *really* interest me. Indeed, I’ll probably try to learn a bit of OpenGL over the next few months.
  • PHYS 121 and PHYS 122 (Mechanics and Waves 1/2) are pretty much filler courses to satisfy my degree’s breadth & depth requirements. I chose physics in part because I think I can apply a lot of it in, say, animation. My other alternative is to take a couple of astronomy courses, but eh…
  • CS 490 (Information Systems Management) links together computer science and business. That’s all I need to say on that matter. :P
  • CS 349 (User Interfaces) also looks to be a very entertaining course (especially since I wrote my last work report on application design…).
  • Considering how much I’ve been lashing out at Facebook, Google, RockYou and others over the last couple weeks, it’s no surprise that CS 458 (Computer Security and Privacy) is on this list.
  • CS 486 (Introduction to Artificial Intelligence) is pretty obvious. Evil robots ftw! :P
  • I might take CS 448 (Database Systems Implementation) as a follow-up to CS 348 depending on whether I have room. We’ll see.
  • Finally, I’ll probably take CS 343 (Concurrent and Parallel Programming) to round out my programming skills and to satiate my curiosity on developing for multiple cores (pretty useful considering the shift in CPU development over the last few years).

That’s a pretty comprehensive set of courses I think. It should give me a pretty solid foundation to build on in the future. :)

Information Systems Management