Skip to main content
·959 words·5 mins

Every now and then you might need to shuffle some elements on your page, like in an online banking page you might have to display a virtual keypad which could be shuffled on demand, or on a tile game you’re most likely to have to shuffle the board. This problem usually boggles the mind of many people, but it has a very simple solution.

Let’s start with the basics. Javascript arrays have a method called sort(), which returns the sorted version of an array (note that it doesn’t actually modify the array itself), and receives a callback function as a parameter (called a predicate function), which in turn receives two parameters, referring to tuples of values from the array. The predicate is expected to compare those two values, and return a numeric value that tells the method which of the two values is supposed to rank first. Given that the two values are represented by a and b, the predicate would return a negative value when a comes before b, a positive value when b comes before a, and 0 if a and b match. Let’s look at an example.

Given an array of integers such as [ 3, 2, 8, 1, 5, 1 ], and given that we mean to sort it by ascending order, our predicate can be as follows:

Read more...
·1514 words·8 mins

I was making a list of movies I own in Excel 2010, and I was also adding links to their pages in IMDB. However, while Excel does automatically convert typed links into hyperlinks, it doesn’t convert pasted ones.

I could do that manually (copy the link text, right click on the cell, select Hyperlink, paste the link into the address bar on the dialog window and click OK) but that would be too time-consuming, considering I had over 250 entries. So I needed something automated to do that for me.

The most basic of these is a function called HYPERLINK(). It turns the text in a different cell into a hyperlink and pastes it into the cell it’s typed in. It also lets you “hide” the link behind a text you specify, but in any case I would have to use another cell for each cell containing the link text. See the syntax:

Read more...
·327 words·2 mins

I started playing Batman: Arkham Asylum yesterday and I found it amazing. I played it for a couple hours until I arrived in Arkham North, but then my left eye started hurting like crazy and I had to rest for a while. Today I progressed a little more and came into Arkham Mansion. My mission was to reach Dr. Young’s research notes before Joker did. I had to get in her office to get the notes and even though I was able to pinpoint its location, I couldn’t get in. It took me a while to find where to go, but I did it. Here’s how to enter the office.

Warning! This post may contain spoilers.

Read more...