Code & Craft

Code

All blog posts related to coding, developing, etc.

  • Posted on

    I am bit frustrated with WordPress. Porting WordPress to a new hosting provider is a bit cumbersome. My previous blog was ported as per instructions, but it hasn't worked. Moreover WordPress tends to be a heavyweight content wise. Meaning it downloads a lot of content for just a blog. I am aware that there are other open-source lightweight alternatives to WordPress, but developing something my own might add valuable experience.

    I am still in the process of developing this and even though you see the blog posts below the development is not complete yet. It should all be ready in some time.

    Thank you for visiting.

  • Posted on

    Have you ever seen one of these irritating, half-assed, Tamil dubbed versions of English movies on the various Tamil channels?

    I recently saw The Hitchhiker's guide to the galaxy dubbed into Tamil. Not only was it totally silly, they changed the story all together.

    Every dialogue was changed to something that didn't even resemble what was originally said.

    For instance, there's a scene where Ford Prefect warns the patrons of a bar that the Earth will be destroyed in 10 seconds. The Barkeep (originally) responds by asking him whether they should cover their head with a paper bag or something. In the Tamil Dubbed version, this was changed to the Barkeep asking Ford to stop his insanity. The joke of this moment is entirely lost on Tamil audiences.

    To someone who hasn't read the book or seen the original movie, I am sure watching it in Tamil would have been bewildering. Needless to say, I switched channels within 10 minutes.

    You know what would be great, take an entire movie that has been dubbed in Tamil and transliterate it back in English.

    That would be hilarious!!!

    I will do it someday.

    Oh and here's a transliteration for this month.

    Quote: Mayirai katti malayai izhu - vanthal malai ponal mayir (மயிராய் கட்டி மலையை இழு - வந்தால் மலை போனால் மயிர்) Intended meaning: Pull a mountain by tying a hair to it. If you succeed you will get a mountain, if you lose you will lose a hair. There is no harm in trying. Transliteration: Hair tie mountain pull - coming mountain going hair.

    Cheers!

  • Posted on

    Am I the last person in the world to discover this?

    One way to round off numbers in Javascript is to use the parseInt method. Like so.

    var someRandomNumber = 123.1872;
    var roundedOff = parseInt(someRandomNumber);
    

    Remember though that parseInt does not actually round, it truncates the decimal portions of the number.

    But that's not the point. I don't know how good parseInt is performance wise, but an easier way to round off (or truncate the decimal parts) numbers in Javascript is to right-shift a number by 0. Like so.

    var someRandomNumber = 123.1872;
    var roundedOff = someRandomNumber >> 0;
    

    Both these examples yield 123 as the result.

    So I did some performance tests to see which one performed better. Each method was run a 1,000, 10,000 and 100,000 times and the time was noted. The tests themselves were carried out 20 times.

    I did not see a great deal of difference when the tests were ran a 1,000 times. Each method ran for more or less a millisecond, however I have to say that over 20 times, the right-shift edged out.

    There was still no big difference when the tests were ran 10,000 times. Still, right-shift edged out.

    The big difference was when it was run 100,000 times. The right-shifting outperforms parseInt as a method to round off (or truncate) number.

    Here's the result of 20 runs. Each run was 100,000 conversions.

    # ParseInt Right-Shift
    1 9 5
    2 4 1
    3 5 1
    4 3 1
    5 2 1
    6 3 1
    7 3 1
    8 3 0
    9 4 1
    10 3 0
    11 3 1
    12 3 1
    13 3 1
    14 3 0
    15 3 1
    16 3 1
    17 3 1
    18 3 1
    19 3 0
    20 3 1
    Average 3.45 1

    Here's the code if you want to do this yourself.

    var testing = "ParseInt - Right-Shift\n";
    for(j=0; j<20; j++)
    {
      var startTime = new Date().getTime();
      for(i=0; i<100000; i++)
      {
        var myVar = Math.random() * 1970;
        var roundOff = parseInt(myVar);
      }
      var endTime = new Date().getTime();
      var timeTaken = endTime - startTime;
      testing += timeTaken + " - ";
    
      startTime = new Date().getTime();
      for(i=0; i<100000; i++)
      {
        var myVar = Math.random() * 1970;
        var roundOff = myVar >> 0;
      }
      endTime = new Date().getTime();
      timeTaken = endTime - startTime;
      testing += timeTaken + "\n";
    }
    alert(testing);
    
  • Posted on

    So in other news, Bill Gates has regained his title of the world’s richest man with a fortune that is valued at 72.7 billion US dollars. That's right he's back on top of the list. The last time he was on top was in 2007. You know how much is 72.7 billion dollars? Read on.

    The words million and billion are used so frequently (often together), we fail to recognize just how big a billion really is. Perhaps it is because these words sound so similar to each other.

    So how much is a billion really?

    In the short scale, numbers progress such that a new term greater than million is a 1,000 times the previous term. Thus,

    A million is thousand thousands; that is 1,000,000

    A billion is a thousand millions; that is 1,000,000,000 and so on and so forth

    Here’s an exercise that is guaranteed to blow your mind. Let’s calculate how much is a million seconds. For the sake of readability I am going to round-even all calculations.

    A minute has 60 seconds, so dividing 1,000,000 by 60 gives us 16667 minutes.

    An hour has 60 minutes, so dividing 16667 by 60 gives us 278 hours.

    A day has 24 hours, so dividing 278 by 24 gives us more or less 12 days.

    That’s how big a million seconds is. 12 days.

    And if you thought that was big, let’s do the same thing a billion seconds.

    A minute has 60 seconds, so dividing 1,000,000,000 by 60 gives us 16666667 minutes.

    An hour has 60 minutes, so dividing 16666667 by 60 gives us 277778 hours.

    A day has 24 hours, so dividing 277778 by 24 gives us 11574 days. That doesn't seem right..... right? Nope. The math checks out.

    A month has, on an average, 30.5 days, so dividing 11574 by 30.5 gives us 379 months.

    A year has 12 months, so dividing 379 months gives us 32 years.

    That’s how big a billion seconds, 32 years.

    Mind blown yet? And don't even get me started on the long scale.

  • Posted on

    This is harder than I thought! I thought it would be easier to keep this blog updated. I thought ideas would just float into my head. They didn't. At least not so far.

    So, here's the plan. Every time I don't get anything to say, I am going to transliterate a Tamil quote or proverb into English.

    Years ago we had a manager who had, shall we say, a little trouble with English grammar. It seemed that his internal monologue was Tamil and he was transliterating everything into English on the fly. The result was hilarious. That's the inspiration of posts like these. I will categorize these posts as #tamiltransliterations.

    Transliterating is not translating. Most translation tools found on the web do this. "To be or not to be" from English to German translates to "Zu sein oder zu nicht sein" and the same from German to English translates to "To be or be to not". Subtle, but hilarious.

    So here we go. I'll start with my favorite Tamil quote.

    Quote - "Ellu na ennai ya vandu nikkanam". (எள்ளு ந என்னைய வந்து நிகனம் ) Intended meaning - "Do more than what is expected of you." OR "...going the extra mile". Transliterate - "Sesame seeds means you should come and stand oil".

    Oh by the way. I had a blogspot years ago meant for just such a thing. I am borrowing stuff from there.