Monthly Archives: November 2009

Sharing Folders in Ubuntu 9.10 using VirtualBox

I just wanted to share a folder in Ubuntu 9.10 which I have installed using VirtualBox. Whenever I tried mounting the shared folder using the mount command, I kept getting the following error:

/sbin/mount.vboxsf: mounting failed with the error: No such file or directory

After wandering through forum after forum and post after post, I finally got to share my folder in Ubuntu 9.10 using VirtualBox. The whole process was a mesh so I thought I should create a simple post, so here goes:

Adding Share Folder to VirtualBox

  1. Start by opening VirtualBox (making sure Ubuntu is Powered Off), right-click the Ubuntu Virtual Machine in the left column and choose Settings
  2. Click Shared Folders option in the left column
  3. Click the Add new shared folder button (its a folder with a + sign) located on the right
  4. A small window pops up asking you the Folder Path (a drop-down) and a Folder Name (no spaces)
  5. Once you are happy with everything, press OK twice to close this pop up and the Settings window. Now start the Ubuntu 9.10 Virtual Machine

Mounting Shared Folder in Ubuntu 9.10

  1. Start the Terminal by going to Applications > Accessories > Terminal
  2. Create a folder under mnt directory by:

    sudo mkdir /mnt/my_shared_folder

    replace my_shared_folder with whatever you want to call the shared folder

  3. Now mount the shared folder by:

    sudo mount -t vboxsf my_folder /mnt/my_shared_folder

    replace my_folder with what you entered in the Folder Name when you added the folder under Settings and replace my_shared_folder with whatever you have called the folder in the previous step

  4. You’re done!

Please do leave a comment if this works for you 🙂

Flattr this!

Function to dynamically resize images using jQuery

UPDATE: I have created a jQuery plugin that dynamically resizes the images. It is faster and is optimized better (minified).

I have noticed that there has been quite a bit of interest in my post about dynamically resizing images using jQuery. I have created a function to do this job better. Not only it makes the code cleaner but it also makes it a lot easier to use it.

First, for those people looking for a quick lookup of solution, here is the optimized version of the function followed by a couple of examples to use it:

And now the explanation.. The function takes one argument, a number, which is the maximum height and/or the width of the image. The function automatically decides what is the best way to resize the image as its all calculated from the proportions of the original image.

What follows below is an expanded (non-optimized) version of the function and explanation on what each statement does:

NOTE: I do highly recommend using the optimized version of the function above

Line 1 declares the function “resize” and accepts a variable for maximum height/width.
Line 2 stores the Math.ceil function to a single letter variable for calling up later by m(). It is same as calling Math.ceil() and is done this way for reducing the size of the script (called minifying).
Lines 3 to 5 check if a maximum height/width was specified, if not, the script defaults to a maximum size of 200px.
Line 6 & 7 sets two variables ‘h’ for height and ‘w’ for width to the maximum size. One of these variables will be changed depending up the proportions of the image being resized.
Line 9 starts the jQuery.each function that iterates over each image one by one.
Line 10 stores the image’s height to a variable and is for reducing the size of the script.
Line 11 stores the image’s width to a variable and is for reducing the size of the script.
Line 12 checks if the image height is greater than the image width.
Line 13 only executes when the image’s height is bigger than the width. It calculates the image’s new width with proportion to its original size (which would be less than the height).
Line 14 is basic else statement.
Line 15 only executes when the image’s width is bigger than the height. It calculates the image’s new height with proportion it its original size (which would be less than the width).
Line 17 uses the jQuery’s built-in CSS function to set the new height and width for the image.

Flattr this!