Wednesday, October 5, 2011

Mangento exporting SQL issue

While exporting mySQL if you every get into the problem]

ERROR 1064 (42000) at line 688: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE,
  KEY `FK_CATALO' at line 9

and the mySQL is 
UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`) USING BTREE

You need to replace all such instance by 

UNIQUE KEY `IDX_BASE` USING BTREE(`entity_type_id`,`entity_id`,`attribute_id`,`store_id`)

Tuesday, October 4, 2011

How to making Linux multihomed to connect to 2 ISP

To make my Ubuntu Server on more robust I have connected it to 2 ISP so that I can have redundant last mile. Also one of my ISP gives me unlimited bandwidth while the other is costlier but more reliable.

To make your linux server multihomed, I am assuming that you have atleast 2 network interfaces. In my case both are ethernet (eth0 and eth1)

Make sure both the networks are working individually up by setting it on /etc/network/interface
sudo vi /etc/network/interface

auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        metric 100

auto eth1
iface eth1 inet static
        metric 200

Now if you go to your terminal, you should be able to
>ip route show dev eth1  proto kernel  scope link  src dev eth0  proto kernel  scope link  src
default via dev eth0  metric 100
default via dev eth1  metric 200

With this if your eth0 goes down, your eth1 will take over and vice-versa.
But this is still a long way from making your network multihoned where your can do load balancing.

All you need to do is to add  multihop route in your /etc/rc.local
ip route append default scope global nexthop via dev eth0 weight 5 nexthop via dev eth1 weight 1

USB for Ubuntu Server

Ubuntu Server does not come with auto-mount for USB.
You will need to install the light weight usbmount

sudo apt-get install usbmount

Tuesday, September 20, 2011

Checking what files to checkin in SVN

Coming from rational Clearcase background, I always like to check which files I need to checkin and which files I would like to revert back.

First I check all files that have been added but not necessarily been added into the svn archive.
svn status | grep "^?" | awk '{ print $2} 

For the files that need to achieved do this manually.  For all other files you should save these in a tar and delete them. Most often these are files
svn status | grep "^?" | awk '{ print $2} >not-needed.txt

At this point you may want to remove the directories which are cached or not under source control

tar cxvfa  not-needed.tgz -T not-need.txt 
cat not-needed.txt | xarags rm -rf $1

Finally for all files that are now modified, I like to make sure they are really needed. Do a diff and make sure the code is correct.

svn status | grep "^[AM]" | awk '{if ($2=="S" || $2=="+") print $3; else print $2;}'

Sunday, September 11, 2011

In magento I have been jumping over all the directories to be able to see the code. Half my life was being spent on CDing.

Then I found this easy script

Basically it allows you to do a save on any alias and then go to the alias.

The script is basically very simple and can be easily used in any bash shell by adding it to .bashrc or .bash_aliases (for sake of completion)

# Bash Directory Bookmarks
alias m1='alias g1="cd `pwd`"'
alias m2='alias g2="cd `pwd`"'
alias m3='alias g3="cd `pwd`"'
alias m4='alias g4="cd `pwd`"'
alias m5='alias g5="cd `pwd`"'
alias m6='alias g6="cd `pwd`"'
alias m7='alias g7="cd `pwd`"'
alias m8='alias g8="cd `pwd`"'
alias m9='alias g9="cd `pwd`"'
alias mdump='alias|grep -e "alias g[0-9]"|grep -v "alias m" > ~/.bookmarks'
alias lma='alias | grep -e "alias g[0-9]"|grep -v "alias m"|sed "s/alias //"'

However there is now a better script which helps you save the names in more readable format and then go to that. For that you should look up the script yourself.

Magento: How to change Title, Sescription and Keywords in static pages

Magento is fairly SEO friendly but for certain pages, it does not allow you to change the Title, Description or the keywords. Some of these pages are very important for Google crawls such as Search terms, Advanced search, Contact us, Sitemaps etc. There are other pages such as accounts etc, which also set the default keywords, however I do not care if they are crawled by Google as they are customer specific.

You can set all of these by making simple changes the layout XML files and the block functional file.
We have to create the functions setDescription and setKeywords in .../app/code/core/Mage/Page/Block/Html/Head.php  (Remember it always best to make a copy of this file in .../app/code/local/Mage/Page/Block/Html/Head.php).

     * Set description element text
     * @param string $description
     * @return Mage_Page_Block_Html_Head
    public function setDescription($description)
        $this->_data['description'] = $description;
        return $this;

     * Set Keywords element text
     * @param string $keywords
     * @return Mage_Page_Block_Html_Head
    public function setKeywords($keywords)
        $this->_data['keywords'] = $keywords;
        return $this;

Let us take Advanced Search for example and see how we can make these changes. In layout/catalogsearch.xml

 After <label>Advanced Search Form</label>
        <reference name="head">
        <action method="setForcedTitle"><title>%TITLE%Vyom search</title></action>
        <action method="setDescription"><description>%DESCRIPTION%</description></action>
        <action method="setKeywords"><keywords>%KEYWORDS%</keywords></action>

Make sure you clear your cache before checking the changes. Similarly, find the right XML file and whichever static page you want to make the changes. 

Thursday, September 8, 2011

Magento: Out of stock pushed to the end of the list

Magento allows sorting by Position, Price and Name in the toolbar.

But It does not look at the status of product and if the product is available. Under normal circumstances, I would not like to show any of the products which are not available but due to SEO reasons, it makes sense to continue showing the products. So I would like to continue showing the products based on one of the sorting method but pushing the out-of-stock product at the end.

To do this a good post is

A more elegant solution is to make changes in .../Mage/Catalog/Model/Layer.php at line #102
$collection->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id','is_in_stock>=0', 'left')->setOrder('inventory_in_stock', 'desc');

This will effect both the listing as well as the results page.

Another things is to remember to copy this file from core to code/local//Mage/Catalog/Model/Layer.php so that the core files remain as it is.

Ricardo Martins has made this into a github project and posted the code on 

I have not checked the code but it will be helpful for lot of folks. Thanks Ricardo

Wednesday, September 7, 2011

Putty screen freeze due to CTRL-S

Over the last couple of day, I faced a problem of getting screen freezes while I was working on vi. It became very frustrating as I had to restart my putty and also remove the swap file.

I finally realised that the reason was I was pressing CTLR-S for saving a file out of sheer habit. CTLR-S on bash generally means XOFF (output off) and you need to do a CTLR-Q to turn it back on.

Instead of that a simple addition to .bash_profile can save you the trouble.
stty -ixon

However even with this I was getting a statment such as i-search when I would type CTLR-S.
For that I removed the binding from my bash shell. 
bind -r '\C-s'

So all in all the changes need in your .bash_profile is
bind -r '\C-s'
stty -ixon

Wednesday, July 27, 2011

MySQL: Copy / clone database in MySQL

I needed to create a exact replica of my existing MySQL Magento database so that I could use it for my development.

A elegant solution was


- SRC_DB_* is the source database
- DST_DB+* is the destination Database

If you wanted to create a datavase also, you could have used

mysqladmin create  -u DST_DB_USER --password=DST_DB_PASSWORD -h DST_DB_HOST DST_DB_NAME && \
mysqldump -u SRC_DB_USER --password=SRC_DB_PASSWORD -h SRC_DB_HOST SRC_DB_NAME \

SVN help: Easy way to delete .svn folders

If you need to delete .svn in folders, here is a simple Linux command
rm -rf `find . -name .svn`

This can come very useful if you have made a copy/backup of the folder.
Another use is if the folder is copied from one project to another project. In which case, you will not be able to add the folder into SVN as it will tell you that this directory already exist under svn. It is best if you delete all the .svn and then do a 'svn add'

Thursday, June 9, 2011

RIP iphone: reteiving the Messages, call histroy and contact list

After giving me good service for 3 and half years the touch screen of my iphone finally gave away. It happened at night when it refused to turn itself off and there was no way for me to reset it.

By now, I knew my iphone was on its last breaths and it was living on borrowed time. I did not loose too much of sleep on this but my immediate concern was to retrieve my last few days messages, address books and call history.

I knew I had the lastest backup, as the iPhone was still syncing with the iTunes. So all i needed to do was to read the backup. Also from my previous experience I knew these files would be mostly stored as sqllite files.

After a bit of search on my machine the files were backed on my Vista up @ /user/AppData/Apple Computer/Roaming/MobileSync/Backup/adb3eaadbe258e41f1a045ae15ccb7d3cf66ee6b directory. Just check the latest directory on your computer.

Next was to figure out which files were the ones needed. Here after some search I found these files to be here.
ff1324e6b949111b2fb449ecddb50c89c3699a78.mddata Call history 3d0d7e5fb2ce288813306e4d4636395e047a3d28.mddata SMS Log
740b7eaf93d6ea5d305e88bb349c8e9643f48c3b.mddata Notes database
31bb7ba8914766d4ba40d6dfb6113c8b614be442.mddata Contact List

992df473bbb9e132f4b3b6e4d33f72171e97bc7a.mddata Voicemail list

I used the Sqllite manager, a firefox extension (which can be found here) to be able to read these files.
Most of the files are easy to read and does not really need any SQL query as such.

However the Contact list is more complicated with multiple tables and for that I used the query to build a flat file.
select p.first, p.last, p.middle, p.Organization, p.Department, p.note, p.JobTitle, p.Prefix, d1.value as mobile, d2.value as Home, d3.value as Work, d4.value as WorkFAX, d5.value as Other, d6.value as Main, d7.value as HomeEmail, d8.value as WorkEmail, a1.value as Street,a2.value as State,a3.value as CountryCode,a4.value as City,a5.value as Country,a6.value as Zip from abperson p
left outer join ABMultiValue d1 on d1.record_id=p.ROWID and d1.label=1
left outer join ABMultiValue d2 on d2.record_id=p.ROWID and d2.label=2 and
left outer join ABMultiValue d3 on d3.record_id=p.ROWID and d3.label=3 and
left outer join ABMultiValue d4 on d4.record_id=p.ROWID and d4.label=4
left outer join ABMultiValue d5 on d5.record_id=p.ROWID and d5.label=5
left outer join ABMultiValue d6 on d6.record_id=p.ROWID and d6.label=6
left outer join ABMultiValue d7 on d7.record_id=p.ROWID and d7.label=2 and
left outer join ABMultiValue d8 on d8.record_id=p.ROWID and d8.label=3 and
left outer join ABMultiValueEntry a1 on a1.parent_id=p.ROWID and a1.key=1
left outer join ABMultiValueEntry a2 on a2.parent_id=p.ROWID and a2.key=2
left outer join ABMultiValueEntry a3 on a3.parent_id=p.ROWID and a3.key=3
left outer join ABMultiValueEntry a4 on a4.parent_id=p.ROWID and a4.key=4
left outer join ABMultiValueEntry a5 on a5.parent_id=p.ROWID and a5.key=5
left outer join ABMultiValueEntry a6 on a6.parent_id=p.ROWID and a6.key=6;

Now too search for an iPhone alternative :-)