jquery link

my custom css

slimbox 2

analytics

Thursday, March 24, 2011

Installing Firefox 4 on Ubuntu...

1) Adding ppa to repositories
    $ sudo add-apt-repository ppa:mozillateam/firefox-stable
2) Update repository
    $ sudo apt-get update
3) Reinstall package to latest version
    $ sudo apt-get --reinstall install firefox
Note:
Tested on Ubuntu 10.04 32-bit and Linux Mint 10 64-bit.

Wednesday, March 16, 2011

Auto activate Slimbox 2 on Blogger...

Why I switched to Slimbox 2?
  • No issues when using with latest jQuery library on IE8.
  • Small footprint.
  • Centers images vertically on startup, not just horizontally.

Installation steps
1) Download the plugin from here.

2) Extract the file.

3) Upload images in \slimbox-2.04\css to Picasa Web Albums.

4) Login to your Blogger Dashboard.

5) Go to Design > Page Elements, add two HTML/JavaScript gadgets and place it below header.

6) Open \slimbox-2.04\css\slimbox2.css, copy the content and paste it into first HTML/JavaScript gadget (within <style> tag) and save changes. Note, need to tweak images url in css so that it'll point to our image in Picasa Web.
    <style type="text/css">
    /* paste \slimbox-2.04\css\slimbox2.css content here */
    </style>
7) Open \slimbox-2.04\js\slimbox2.js, copy the content and paste it into second HTML/JavaScript gadget (within <script> tag) and save changes.
    <script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>

    <script type="text/javascript">
    /* paste \slimbox-2.04\js\slimbox2.js content here */
    </script>
8) Save changes to Page Elements.

Auto activation
Slimbox 2 provide an auto activation script within the distribution for convenient use. Here's how to:

1) Open \slimbox-2.04\extra\autoactivation.js and copy the content.

2) On Blogger, go to Design > Page Elements. Open second HTML/Javascript gadget that contains Slimbox JS. Replace the code block below with the one from autoactivation.js.
    // AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
    if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
        jQuery(function($) {
            $("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
                return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
            });
        });
    }
3) Save changes.

Note:
I've used autoactivation.js but somehow it didn't grouped my images correctly. Something might be wrong from my side. For now, I'm using my own auto activation code below. Not as elegant as the one that came from Slimbox, but at least it works for me.
    <script language="javascript" type="text/javascript">

    ...

    if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
        jQuery(function($) {
            $('div.post-body').each(function() {
                var $postbody = $(this);
                var index = $('div.post-body').index(this);
                $('a[href*=".jpg"],a[href*=".png"],a[href*=".gif"]', $postbody).each(function() {
                    var $div = $(this).parent();
                    var $title = $('p', $div);
                    var htmltext = $title.html() != null ? $title.html() : '';
         
                    if($(this).attr('onblur')) { $(this).removeAttr('onblur'); }
         
                    var hrefval = $(this).attr('href');
                    $(this).attr('href', hrefval.replace('s1600-h', 's1600'));
         
                    if(!$(this).attr('rel')) { $(this).attr('rel', 'lightbox-album' + index); }
                    if(!$(this).attr('title')) { $(this).attr('title', htmltext); }
                });
            });

            $("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
                return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
            });
        });
    }
    </script>
Update (17/03/2011)
Found out that the combination of Slimbox 2, jQuery 1.5.1 and SyntaxHighlighter 3 will caused the image viewer to stop working on IE8 (only IE8). Removed SyntaxHighlighter will solve the problem. I need to find a better way to fix this.

Tuesday, March 15, 2011

Changing default Blogger icon...

The solution is quite simple.

1) Login to dashboard.

2) Go to Design -> Edit html (please backup your template before you make any changes).

3) Search for </head> tag.

4) Paste the code below on top of </head> tag.
    <link href='your icon url' rel='shortcut icon' type='image/x-icon'/>
5) Save Template.

It'll be great if you could find a good hosting for your icon. Picasa Web won't allow us to upload .ico file. ImageBoo does provide free hosting for icon however it's been blocked by proxy at my office (plus I've read some negative feedback somewhere about the service, then decided to use other alternative). Icon generated by IconJ was kind of ugly (probably to encourage people opting for the premium service).

Alternatively you could use .png image as your icon (which can be hosted on Picasa). However, it'll only work with Google Chrome and Mozilla Firefox. No luck for IE.

Update (02/05/2011)
Icon file can be hosted at Google Sites.

Saturday, March 12, 2011

Auto activate lightBox on Blogger...

So, you have successfully installed jQuery lightBox plugin on your Blogger. Now the toughest part would be applying rel="lightbox" attribute to all your images (not to forget image grouping rel="lightbox[album-n]"). It's going to be a pain process if you have 50+ images in an n amount of posts. Worst, post from old editor required two more extra steps (removing onblur attribute and renaming s1600-h to s1600).

Using jQuery, this process can be automatically done without the need to change on html code. Here's the steps:

Prerequisites:
jQuery 1.3.2, later version will cause problems with this plugin on IE8 (use latest version if you plan to ignore IE8).

Steps:
1) Login to your Blogger Dashboard.

2) Go to Design > Page Elements.

3) Open the third HTML/JavaScript gadget as mentioned in my previous post (create a new one if you've installed the plugin by other methods).

Page Elements


4) Replace the old script with the new one below (assuming you've added the link to jQuery library before, otherwise add the link on top of the script below).
    <script type="text/javascript">
    $(document).ready(function() {
        $('div.post-body').each(function() {
            var $postbody = $(this);
            var index = $('div.post-body').index(this);
            
            $('a[href*=".jpg"],a[href*=".png"],a[href*=".gif"]', $postbody).each(function() {
                var $div = $(this).parent();
                var $title = $('p', $div);
                var htmltext = $title.html() != null ? $title.html() : '';

                if($(this).attr('onblur')) { $(this).removeAttr('onblur'); }

                var hrefval = $(this).attr('href');
                $(this).attr('href', hrefval.replace('s1600-h', 's1600'));

                if(!$(this).attr('rel')) { $(this).attr('rel', 'lightbox[album' + index + ']'); }
                if(!$(this).attr('title')) { $(this).attr('title', htmltext); }
            });
        });

        $('a[rel^=lightbox]').lightBox({
            imageLoading: 'your-url/lightbox-ico-loading.gif',
            imageBtnClose: 'your-url/lightbox-btn-close.gif',
            imageBtnPrev: 'your-url/lightbox-btn-prev.gif',
            imageBtnNext: 'your-url/lightbox-btn-next.gif',
            imageBlank: 'your-url/lightbox-blank.gif'
        }); 
    });
    </script>
5) Save changes.

Explanation:
1) Once page load completed, script will query for all <DIV>s that use post-body (you might need to change the script if you're using non-standard Blogger theme) css class.

2) Search an <A> elements with href value contains ".jpg", ".png" and ".gif" (case sensitive, add the uppercase value if needed) in each <DIV>.

3) Search <P> element for retrieving image title (this is for the structure that I've use like shown below). If none exist it'll return an empty string (compatible with other structure).
    <div>
        <a href="">
            <img src="" />
        </a>
        <p>title</p>
    </div>
4) Remove onblur attribute from <A> element if exist.

5) Rename "s1600-h" to "s1600" on <A> href attribute value.

6) Adding rel and title attribute to <A> element if none exist. Otherwise, leave an existing value.

Test:
1) Click image on any post and you'll see Lightbox in action.

2) One image group per post.

This might not be the best solution. Feedback and comment are most welcome.

Note:
Tested with images posted from both new and old editor. Using Google Chrome, Firefox, IE7, IE8 and IE9 RC.

Update (13/03/2011)
This auto activation script will not work with lightBox JS version. This is due to conflict between the JS version and jQuery library.

Update (14/03/2011)
Script updated. Added ".gif" to selector.

Friday, March 11, 2011

Installing jQuery lightBox plugin on Blogger...

First of all thanks a lot to:

Now, here's the steps required to install jQuery lightBox plugin on Blogger

Pre-installation steps
1) Download the plugin from here.

2) Extract the zip file.

3) Upload images in \jquery-lightbox-0.5\images to Picasa Web Albums.

4) Open \jquery-lightbox-0.5\js\jquery.lightbox-0.5.js.

5) Go to line 79 and replace the code below
    // Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
    for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {
        settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
    }
with this code and save changes
    // Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
    for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {
        if(jQueryMatchedObj[i].getAttribute('rel')==objClicked.getAttribute('rel')) {
            settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
        }
    }
Installation steps
1) Login to your Blogger Dashboard.

2) Go to Design > Page Elements, add three HTML/JavaScript gadgets and place it on top of Blog Posts like shown below.

Page Elements


3) Open \jquery-lightbox-0.5\css\jquery.lightbox-0.5.css, copy and paste the content (within <style> tag) into the first gadget and save the changes.

4) Open \jquery-lightbox-0.5\js\jquery.lightbox-0.5.js, copy and paste the content (within <script> tag) into the second gadget and save the changes. Don't forget to add link to jQuery library like shown below. Use jQuery 1.3.2, later version will cause problems with this plugin on IE8 (use latest version if you plan to ignore IE8).
    <script language='javascript' type='text/javascript' src='http://code.jquery.com/jquery-1.3.2.min.js'></script>
    
    <script language="javascript" type="text/javascript">
    // this is where you paste the content of \jquery-lightbox-0.5\js\jquery.lightbox-0.5.js
    </script>
5) For the third gadget, copy and paste the code below then save the changes.
    <script type="text/javascript">
    $(document).ready(function() {
        $('a[rel^=lightbox]').lightBox({
            imageLoading: 'your-url/lightbox-ico-loading.gif',
            imageBtnClose: 'your-url/lightbox-btn-close.gif',
            imageBtnPrev: 'your-url/lightbox-btn-prev.gif',
            imageBtnNext: 'your-url/lightbox-btn-next.gif',
            imageBlank: 'your-url/lightbox-blank.gif'
        }); 
    });
    </script>
Test the plugin.
1) Edit any post with image.

2) Add rel and title to image href.
    <a href="your image" ... rel="lightbox" title="title">
        <img src="your thumbnail image" />
    </a>
    
    <-- for grouping -->
    <a href="your image" ... rel="lightbox[album]" title="title">
        <img src="your thumbnail image" />
    </a>
3) For html generated from old editor, you need to remove onblur attribute and rename s1600-h to s1600 in the url.
    <-- change the html from this -->
    <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_jkdsue/AAAABB/s1600-h/someimage.jpg" ...>
        <img src="your thumbnail image" />
    </a>
    
    <-- into this -->
    <a href="http://1.bp.blogspot.com/_jkdsue/AAAABB/s1600/someimage.jpg" ... rel="lightbox" title="title">
        <img src="your thumbnail image" />
    </a>
4) Save changes and view your post. Click the image and you should see lightbox in action.

Next, I'll post on how to auto activate lightBox on Blogger. Feedback and comment are most welcome.

Wednesday, March 9, 2011

USB startup disk creator for Linux and Windows...

Info: If you're searching for "how to create Windows USB installer", click here.

When started playing with Linux distro, I realized that I need to have a lot of blank CDs / DVDs so that I can burn the downloaded iso image and test the LiveCD on my machine (to make sure all the devices working as expected before installing). End up with a lot of cd / dvd installers that been used once and forgotten. Then, saw an option to use USB pendrive as an installer. At initial stage the process was quite tedious, but now since the technology has matured there's a lot of tools available that can do the process easily. I'll list down a few of it for reference. Some history about Live USB.

Prerequisites:
  • Fat32 Formatted Flash Drive
  • PC that can boot from USB

Name: UNetbootin
Platform: Linux / Windows

Summary:
"UNetbootin allows you to create bootable Live USB drives for Ubuntu, Fedora, and other Linux distributions without burning a CD. It runs on both Windows and Linux. You can either let UNetbootin download one of the many distributions supported out-of-the-box for you, or supply your own Linux .iso file if you've already downloaded one or your preferred distribution isn't on the list."

My comment:
The most famous one.
Name: MultiSystem
Platform: Linux

Summary:
"Multisystem enables a LiveUSB to do everything, ideal for exploring different Linux distributions without installing on your PC, and it seamlessly; or to install the Linux distribution of your choice on your PC much faster than via a LiveCD with fast USB 2.0 ports Essential throughout the current range of netbooks that have no CD drive."

My comment:
My favorite one. Love the ability to bundle multiple distros and had a GRUB menu as a selection to which distro to be use.
Name: Ubuntu Live USB creator
Platform: Linux

Summary:
"Ubuntu Live USB creator (usb-creator) is an official tool to create Live USBs of Ubuntu from the Live CD or from an iso image. The tool is by default included in all releases after Ubuntu 8.04, and can be installed on Ubuntu 8.04. A KDE frontend was released for Ubuntu 8.10, and is currently included by default in Kubuntu installations. To run the current version on Ubuntu or other distributions, enter either usb-creator-gtk or usb-creator-kde at the command line."

My comment:
First tool that I've used for the task.
Name: SARDU
Platform: Windows

Summary:
"Shardana Antivirus Rescue Disk Utility (Sardu) is software that can produce an ISO or an IMA anti-virus bootable CD, a comprehensive collections of utilities, the most popular distributions of Linux Lite, and the best known Windows PE. It is freeware (it is licensed as an individual ISO / IMA). Once the files are extracted Sardu creates a CD / DVD or USB bootable device with a handy menu divided into four categories: Antivirus, Utilities, Linux, and PE."

My comment:
Seems to me this is the best tool available on Windows platform. You can also have the recovery disk for XP, Vista, Seven or XP (64bit, Professional or Home) in a practical multi-boot menu. Definitely going to try with this one.
Name: Universal USB Installer
Platform: Windows

Summary:
"Universal USB Installer is a Live Linux USB Creator that allows you to choose from a selection of Linux Distributions to put on your USB Flash Drive. The Universal USB Installer is easy to use. Simply choose a Live Linux Distribution, the ISO file, your Flash Drive and, Click Install."

My comment:
An option for Windows user. One Distribution can be installed at any given point in time.
Name: MultiBoot USB
Platform: Windows

Summary:
"MultiBootISOs enables each user to create their own custom Multiboot UFD containing only the Distributions they want. New Distributions can be added to your UFD each time the tool is run."

My comment:
Same feature as MultiSystem but for Windows user. One thing that attract me to this tool was the ability to put Windows Vista / 7 installation disk into the USB. I haven't try this one yet.

Update (02/04/2011)
Tested the tools for Windows platform. Personally I would say SARDU is the best tool available for Windows.

Monday, March 7, 2011

PowerShell cmdlet aliases similar to Bash...

CmdLet Alias Bash
Get-ChildItem gci, dir, ls ls
Get-Content gc, type, cat cat
Get-Command gcm which
Get-Help help, man man
Clear-Host cls, clear clear
Copy-Item cpi, copy, cp cp
Move-Item mi, move, mv mv
Remove-Item ri, del, erase, rmdir, rd, rm rm, rmdir
Rename-Item rni, ren, mv mv
Get-Location gl, pwd pwd
Pop-Location popd popd
Push-Location pushd pushd
Set-Location sl, cd, chdir cd
Tee-Object tee tee
Write-Output echo, write echo
Get-Process gps, ps ps
Stop-Process spps, kill kill
Select-String n/a grep
Set-Variable sv, set set

Copied from Wikipedia.

Wednesday, March 2, 2011

Compacting/Shrinking virtual disk image...

Working on virtual machine with dynamic virtual disk gives an advantage to those with limited disk space. But after using it for a while (install/uninstall/copy/paste/delete), the actual size of your virtual disk image may have grown to nearly defined size, guest system reported that the disk usage was less than the size reported on host system. It should be fine provided if you have larger disk space. However, if that's not the case, than the best option would be to compact (known as shrink in VMWare) the virtual disk image.

In general, 3 steps are required to achieve this task
1) Disk cleanup / Defrag the hard drive on guest system

2) Execute "sdelete -c" to zero the free disk space before compressing the virtual disk image (sdelete tool was provided by Microsoft) on guest system
    > sdelete -c [drive letter]
3) Compact the virtual disk image

VirtualBox user
Execute VBoxManage command on host system
    $ VBoxManage modifyhd [filename] --compact
VMWare user
Shrinking needs to be done on guest system. Complete the first two steps above then:
1) Open VMWare tools by right click VM icon in system tray

2) Go to Shrink tab, under supported partitions, check the mount point checkbox

VMWare Tools Properties


3) Click "Prepare to shrink" and once ready, click "Yes" to proceed

Preparing shrink process


Ready to go


Shrinking in progress


If everything working as expected, virtual disk usage on both guest and host should be ~same

Note:
Test environment
Host: Linux Mint 10 64-bit
VirtualBox guest: Windows Server 2003 32-bit
VMWare guest: Windows 7 Profesional 64-bit