Tony Stark: Engineer, Billionaire, Telekintic.

May 12th, 2010

So seeing how the 1994 Iron Man Animated Series had been released on DVD, I’ve started watching it. I am afraid that’s the one I’ve used to watch when I was much younger than I am today. It is horrible. Hilarious, but horrible. At times I am unable to tell whether it is all meta humor, places there on purpose, or perhaps the show was actually created by a bunch of drunkards who did their best. Regardless, I’m going to watch it all. And those of you unfortunate enough to find this blog, would get the best of the worst.

Today’s focus, taken from episode 1, or season 1. Behold, Tony Stark’s amazing typing skills. The first few frames are fine, but then he just can’t be bothered hitting the keys dictated by the keyboard animator. The results are shown below:

Because hitting the key you want to press is just overrated anyway.

As a bonus, here is one of the search result of the above typing mishap. The title says it all.

Monk Dismembres Mistress

Monk Dismembres Mistress

Quick note to myslef. How to create animated gifs.

April 24th, 2010

Animated gifs are a great source of entertainment. Be it silly forum avatars, animated porn on 4chan, or the spiraling circle I’ve just spent half the afternoon staring into, they are great.

From time to time I get a sudden urge to fabricate one. Usually when I see a worthwhile action sequence in an anime, or a joke which becomes better every time it is seen. Normally, I do what normal people do, and suppress those creative outbursts. But when I fail at exercising self control, I go through the exact same learning curve, every single time.
It sucks when your own life are poorly documented. And as such, until I’ll program a sexy shell to do all of this for me, here is the list of step I’ve just took to create this magnificent image:

1) Watch anime. Repeat if necessary.
2) Find a sequence which will become the gif. Get approximate time stamps
3) Extract frames using the command:
ffmpeg -i [input file] -r [frames per second] -ss [start time] -t [total length] -f image2 [outname]
Where both the start time and the length are in the format HH:MM:SS
(Thanks internet)
4) We now have a sequence of images. Time for some manual labor! Sift through the images, and delete the start and end images until all that is left are images from the sequence alone. If the source is anime, it is also very possible that the lazy animators are using a lot fewer than their fps in images. So many images would be repeated. Weeding those out can drastically reduce the size of the resulting gif.
5) The next step is to nicely process our images. Time to get our trustworthy friend mogrify!
Complete usage can be found here. Note to self, if you crop, for the sanity of all, repage.
6) Last command is imagemagick again,
convert -delay [seconds/100] -loop 0 [input files] [output file]

And viola! Animated gif, in various degrees of fail. Mine are very fail.

Online PHP textonym calculator (With source code!)

April 13th, 2010

For the actual calculator, go here

It all started a few days ago, when I saw one of my friends join the following group on Facebook: Put your phone on predictive text, and type ‘41568319681′.
The purpose of this group is for you to end up with the string “I.Love.You.” on your cellphone. Being the heartless person that I am, seeing that on my cellphone made me angry. And so I’ve decided to leave a snarky comment regarding the fanpage. What would be better than to claim I’ve done what the message had asked me to, and then pretend the outcome was completely different to expected?
And so I’ve decided to check what other phrases are equivalent to the same numerical string. The smart thing to do would be to get my cellphone, type in the sequence of numbers for ‘love’ (5683) and hit the star button to flip through the different possible words in the dictionary. However, in an Alice in Wonderland-esque fashion, I’ve left my cellphone on the counter before comfortably settling on the sofa with my laptop, and so it is now unreachable. And so the nerdyy thing to do is of course to consult the internet. However, the first few google search results were highly disappointing. As far as I can tell, there is no reliable textonym calculator online. The only thing I’ve found which were of any relevance were:

  • That words which are spelled by the same keys in a T9 input system are called textonym
  • This obviously dead website

And so I’ve realized it is my job to go forth, and set up a new online textonym service, so that people would be able to be jerks on facebook. (Alternatively, it might be used to try and understand some confusing txt messages, but that’s not very fun.)

Actual Coding Starts Here
The first step was finding a dictionary file. While this would not be exactly the same as the cellphone dictionary, I’m guessing those things are quite standard. Googling for ‘dictionary.txt’ returns a nice first result, which I’ll be using as my dictionary. It is simply a list of valid words, one per line.

Next I created my DB table:

CREATE TABLE 'DBName'.'textonym_table'
(
	'word' VARCHAR( 20 ) NOT NULL ,
	'value' INT NOT NULL
)

The field ‘word’ would be used to store the word, and ‘value’ would store the key sequence as an integer.

Next I started writing helper methods.
The first one populates a global array which maps letters to their corresponding keys (eg ‘a’=>2, ‘j’=>5 etc). The lazy solution would be to just hard code an associative array with 26 entries, but that’s cheating. Instead, given a (hard coded) list of characters per key, the method goes through the alphabet and increment the key being mapped to when enough characters had been assigned. As an afterthought, I’m also mapping numbers to themselves. This might come into use if people say things along the lines of ‘g2g’. (I’m lying. I’ve added this because I have fat fingers and I tend to mistype stuff, and this was easier than adding error handling.)

function initReverseArray()
{
	global $reverseT9;
	$keyLetterCount = array(2=>3, 3, 3, 3, 3, 4, 3, 4);
	$currentLetter = 'a';
	foreach ($keyLetterCount as $key => $value)
	{
		for($i = 0 ; $i < $value ; $i++)
		{
			$reverseT9[$currentLetter] = $key;
			$currentLetter = chr(ord($currentLetter) + 1);
		}
	}
	for($i = 0 ; $i < 10 ; $i++)
		$reverseT9[$i] = $i;
}

The second helper method just uses the global array we just populated in order to map a word into its numerical equivalent eg love -> 5683.
Note that it must return an actual numerical value, and not a string!
So the solution is of course to scan the string, and for each character, convert it to a digit, shift it the correct number of places (by multiplying by a power of 10) and then add it to the result.
Error handling is in the form of returning -1 if an unrecognized character has been found.

function wordToT9($word)
{
	global $reverseT9;
	$result = 0;
	for($i = 0; $i < strlen($word) ; $i++)
	{
		if(!isset($reverseT9[$word[$i]]))
			return -1;
		$result += pow(10, strlen($word) - $i - 1) * $reverseT9[$word[$i]];
	}
	return $result;
}

This is all that is required for the database to be populated. All that is left now, is to loop over the dictionary, and store word/value pairs.
The following code does just that, and is lacking any form of error handling. This is bad practice.

function initDB()
{	initReverseArray();
	$dblink = mysql_connect('localhost');
	mysql_select_db('DBName');
	$fileHandle = fopen("dictionary.txt", "r");
	while (!feof($fileHandle))
	{
		$word = trim(fgets($fileHandle));
		$t9Value = wordToT9($word);
		$query = "INSERT INTO textonym_table (word, value) VALUES('$word', $t9Value )";
		mysql_query($query);
	}
	fclose($fileHandle);
	mysql_close($dblink);
}

This function is to be called exactly once. Otherwise the database would contain multiple entries for the same word.

Now everything is set up, and the only thing left to do is to query the database appropriately so that we may get our textonym.
This too is fairly trivial. As no GUI was designed for this, the request for textonym is fetched via $_GET['word'] if no such argument is provided, we gracefully terminate.

if (!isset($_GET['word']))
{
	echo 'Usage: ?word=w';
}
else
{
	initReverseArray();
	$dblink = mysql_connect('localhost');
	mysql_select_db('DBName');
	$t9Value = wordToT9(strtolower($_GET['word']));
	echo "Words of equal value to ".$_GET['word']." ($t9Value)<br>";
	$q = sprintf("SELECT * FROM textonym_table WHERE value=%s",
		mysql_real_escape_string($t9Value));
	$result = mysql_query($q);
	if(mysql_num_rows($result) == 0)
		echo 'no matches found';
	else
		while ($row = mysql_fetch_assoc($result))
		{
			echo $row['word'];
			echo '<br>';
		}
	mysql_close($dblink);
}

And this is it. We can now quickly and efficiently learn that 'I love you' is equivalent to 'I loud you' and that facebook is not a place where sarcasm is properly conveyed.

Doppelganger attack!

October 25th, 2009
This is not me, nor is it my jacket.

This is not me, nor is it my jacket.

I spotted this guy on the other side of the road. I’ve chased him down, and took a photo. Somewhere in China, the production of ItaClones had already started.

IEEEXtreme 3.0

October 24th, 2009

Today is the IEEEXtreme 3.0, my team, “Citrus Celebration”, will take place. 24 hours of programming. A fairly standard day minus settlers.

This blog post (and perhaps a few more after it) would tell the epic tale of the day.

Current time: 12:17
Contest starts in 43 minutes. My team is not here yet, but I’m not particularly worried. Most of the excitement happened this morning, around 9am, when an Email was sent to the whole IEEEXtreme mailing list thanking them for the participation, and telling them to get some sleep. Seeing how this Email was dispatched some 4 hours before the contest eve started, some people got stressed.

A while back, a guy who is probably about as old as I am, came to the contest room with both his parents, which made sure he is comfortable, and asked the supervisor if their boy is allowed to sleep throughout the event, because he really needs to from time to time. The boy wasn’t embarassed, seeing how there was almost no one in the room at the time, but I am very happy to see my parents aren’t the worst of the lot…

We have been placed in the back right corner of the room. Which is nice. No need to back to ensure no one is peeking at our screens. I’ve brought my laptop with, which means I get to double my screen tan, that is if I’ll find a plug. Currently using it because I am unable to login to the normal machine. Curse you engineers. Should have stole someone’s login.

The team names are not particularly amusing. We got 2 pokemons, “Team Mudkip” and “Team Snorlax”. I’m not impressed.

So my bag is full of food, my laptop is running crimson editor, and I’m listening to glglz. Had to connect to 213.8.138.13 again. Not sure what’s wrong with the actual url.

Photos will be uploaded at a later time. Go bluetooth.

Workstation. Note the emptiness:

IEEEXtreme Workspace

IEEEXtreme Workspace

Update (12:31)
Bluetooth now comes with extra fail. I can transfer stuff from my cellphone, but it crashes afterwards. Not cool.

On Convincing My Parents of My Mainstream Sexual Orientation

October 17th, 2009

After the appearance in Craccum and PLT1, it is time the article made its way here.

I wish to make an apple pie from scratch

October 1st, 2009

I am so very afraid this blog is going to become my twitter page. Making a sub 140c post is so much simpler than actually putting the time and effort into a larger post. I claim lazyness is a virtue.

In other news, I saw the Labour party’s student branch on campus yesterday. They are called “young labour”. The first thing which popped into my head was sweatshops.

It’s a start!

September 29th, 2009

I still find this name highly entertaining. Enough to justify the purchase of the domain. Good times.