Canvas width and height

When using <canvas>, remember to add width and height attributes to the markup

<canvas width="200" height="300"></canvas>

even if you have defined them in the CSS, otherwise you might see some unexpected code behavior.


VirtualBox Guest Additions on Ubuntu Server 12.04

While trying to set up the development environment for my site, I was having problems making VirtualBox Guest Additions let me share files with the host OS. The production env is Ubuntu Server 12.04 running on AWS EC2 so it was obvious I had to use a VM on the MacBook to ensure my dev env is in sync with the production.

When a couple of tries failed, I decided to start fresh. I deleted the existing VM, churned out a new machine and installed Ubuntu Server 12.04 (Precise Pangolin) on it. Then I proceeded with installing the VirtualBox Guest Additions. For this, I mounted the VBoxGuestAdditions_4.1.6.iso on the machine and ran the following command on it

sudo ./

and here’s the output

Verifying archive integrity... All good.
 Uncompressing VirtualBox 4.1.6 Guest Additions for Linux.........
 VirtualBox Guest Additions installer
 Removing existing VirtualBox DKMS kernel modules ...done.
 Removing existing VirtualBox non-DKMS kernel modules ...done.
 Building the VirtualBox Guest Additions kernel modules
 The headers for the current running kernel were not found. If the following
 module compilation fails then this could be the reason.

Building the main Guest Additions module ...done.
 Building the shared folder support module!
 (Look at /var/log/vboxadd-install.log to find out what went wrong)
 Doing non-kernel setup of the Guest Additions ...done.
 Installing the Window System drivers!
 (Could not find the X.Org or XFree86 Window System.)

The aforementioned log file printed thus

/tmp/vbox.0/utils.c:122:9: error: assignment of read-only member ‘i_nlink’
 /tmp/vbox.0/utils.c:132:9: error: assignment of read-only member ‘i_nlink’
 /tmp/vbox.0/utils.c: In function ‘sf_nlscpy’:
 /tmp/vbox.0/utils.c:563:13: warning: passing argument 3 of ‘utf8_to_utf32’ from incompatible pointer type [enabled by default]
 include/linux/nls.h:53:12: note: expected ‘unicode_t *’ but argument is of type ‘wchar_t *’
 make[2]: *** [/tmp/vbox.0/utils.o] Error 1
 make[1]: *** [_module_/tmp/vbox.0] Error 2
 make: *** [vboxsf] Error 2
 Creating user for the Guest Additions.
 Creating udev rule for the Guest Additions kernel module.

This had me confused so I Googled for solutions. Here’s one I stumbled upon and tried, but didn’t help fix the problem. Even though the problem was apparently occurring due to missing headers, adding them didn’t fix it.

I continued searching and landed on ubuntuforums. I followed these instructions and voila! it worked.

Also, looks like it is a fixed changeset on Vbox.

Finally, peace was restored 🙂

Hat tip: You would need to edit /etc/group file and add your username, www-data and root thus in order for permissions on the shared directory to work:

change vboxsf:x:1001: line to vboxsf:x:1001:<your-user-name>,www-data,root

CSS Margin In Percentage

Okay, this is funny; but only if it doesn’t come in the way of you getting things done on time. I was trying to assign percentage margin to a <div> and it kept throwing me off on the calculations. A bit of googling led me to this explanation.

If you are giving padding/margin in percentage, due to some out-of-the-world reason it would calculate on the basis of the width of the parent element; whether you are calculating left-right values for margin/padding, or the top-bottom ones.

It beats me as to why is it this way. Let me know if you know the answer.

Back to work!

Just For Fun

Just the other day…

import re, os
avi_re = '(Friends)(\\.)(S)(01)(E)(?P<epi>.*?)(\\.)(DVDRip)(\\.)(XviD)(\\.)(avi)'
sub_re = '(Friends)( )(-)( )(1)(\\.)(?P<epi>\w+)(?P<name>.*?)(\\(EN\\))(\\.)(sub)'

for avi_f in filelist:
  if re.match(avi_re, avi_f):
    e = re.match(avi_re, avi_f).group('epi')
    for sub_f in filelist:
      if re.match(sub_re, sub_f):
        ep = re.match(sub_re, sub_f).group('epi')
        if e == ep:
          new = 'Friends - 1.' + ep + re.match(sub_re, sub_f).group('name')
          os.rename(avi_f, new + '.avi')
          os.rename(sub_f, new + '.sub')

because I can! 😉


Happy 2012 folks! 🙂 In Feb it will be two years since I started working. There are things that come obviously to people. Then there are the ones which take some time. There are the ones that everyone tells you do but you don’t follow until you’ve been bitten in the ass by not following them.

Here are a couple of things (my resolution for 2012? Lets call them that) that I’ve realized make life easier for you as a developer:

1. Use getter functions instead of directly referencing attributes. Helps you modify and control behavior in a much more centralized way (those from the Javaland, I know what you’re thinking 😀 )

2. Use debugging tools frequently: Breakpoints, logs, prints, inspectors. They’re there to save your sanity.

3. Write self-contained and pluggable/reusable code, as much as is possible while maintaining the cleanliness and without making it over-pluggable. Then you’re just writing 2 lines of code to replace 1 line. Bad idea.

4. Don’t write even ONE line of code until you have planned how to go about building whatever it is that you’re working on; be it a full project or a 3-line method. (Okay, there are exceptions to this one. But I’m gonna put it in anyways)

5. Use a pen-and-paper or a whiteboard to write down points rather than keep them in your head. Its much easier to revisit things this way.

6.  Talk. Anything that you’re doing new or have even the slightest doubt on how to do/what is the best way to go about it; its best to pull in 1-2 people and explain what you are trying to accomplish. Maybe they will tell you an easier workaround. Even if they’re not able to answer, they might be able to ask questions that might help you come up with solutions that rule out the need to do, say, a big chunk of your task. [This one comes from the meeting after which we didn’t have to replicate our ALL databases, as we realized there was an easier solution out there]

[Please note that these are just a few of those I have found helpful. This list is in no means comprehensive, complete or THE list. Also, these are things relevant to my development environment setup (python, django, mysql, mongodb, uwsgi, nginx etc.) Might be totally useless for you 🙂 ]

Oh look, its already the longest post on this blog till date. 😛

EDIT: Adding from @nikunjlahoti‘s comment: If you don’t want to code then just plz don’t please anyone by writing crap. or copy pasting snippets. just get a better job. & if u r stuck for good then look at the best-practices (at least). make lives easier.

Duplicate a MySQL database

I was testing something out, and realized that I needed to clone my database to run some tests while still being able to keep the data intact. And that’s when I started searching for a way to do it, and turns out there’s a one-liner to do the same 🙂

# mysqladmin create DB_name -u DB_user --password=DB_pass && \
mysqldump -u DB_user --password=DB_pass DB_name |
mysql -u DB_user --password=DB_pass -h DB_host DB_name

This is the site where I found it: (although at this point of time I’m kinda feeling it was moot writing this post as anyone Googling for the solution can land on the page anyway 😛 )

Gotta run! Peace out.