Export CSV from MySQL Query

As you might be aware that I started a "Murmur" category on my blog. I discover or learn these tips on day-to-day basis and just forget them. Sometimes those takes hours to come with one or often it boils down to just a google search. In any case, you might want to refer to these tips in future as well. So I decided to keep a log of them publicly so that it can help others too.

Many times I need to get dump of data which is output of a sql query. MySQL makes it very easy to output the query result as csv file from command line. Following command should create a names.csv file in $MYSQL_INSTALLATION/data/$DB_NAME/ directory. This command comes very handy when you're working on remote shell where you don't have any GUI tools.

SELECT first_name, last_name INTO OUTFILE 'names.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM employee;

Very useful.

Posted in Murmur | Tagged | 1 Comment

Nice utility for finding classes in Jar files

When you're working on large java code-base, its not very difficult to run in situation where you get a ClassNotFoundException. Many times we have a daunting task to find where the class is located and it is not very easy task. I found this nice utility called "jarscan" which makes life much easier.

Worked great for me today!

Posted in Murmur | Tagged | Leave a comment

Delete My Account

I have few questions for you -

  • For how many years, are you using Internet?
  • Can you remember all the sites where you created an account or shared your personal information? (Email, Phone number, Birth date etc.)
  • Although you can remember all the websites you registered, can you keep those accounts active forever?

Whenever I ask these questions to myself, I get uncomfortable. There are probably 50 websites, who have my online account and personal information. It might be more in most probability. Considering this might be similar situation for most of us, how to make sure that you can delete your account? Most of the websites like Google / Yahoo allows you to delete the account completely. Although few of my readers will love to debate about its actual process. :)

Considering our faith in these online services, I am not quite sure what does complete account removal means for these online websites (Facebook / Gmail / Yahoo etc). Even if it is not complete removal at least I have an option to go and remove my online account information. For most of the websites this option is not available at all!

I will love to make this as public awareness that we should have account removal as standard feature on all the websites who allow users to sign-up. It should be complete removal of account (including all personal information) and not limited to just un-subscribing user from their mailing list.

This will make lot of users much more comfortable to create online account.

Posted in Personal | Tagged | 4 Comments

Things to Ponder with Alfresco (Part III: WCM – Improvements)

Now days using web content management systems (WCM) is trivial. You should continuously update the website content to maintain a fresh look. It increases returning customers and popularity. Almost every major website uses a CMS to achieve this. It might be an in-house developed or an off-the-shelf product. In any case, it helps organizations to separate the content authoring team from the application development cycles.  This helps in quicker content updates without being dependent on release schedules. I am going to point out certain things about WCM feature of alfresco. You can also apply the same principles to your WCM if you are using existing one, or planning to develop a new one!

Content storage format - Alfresco provides a nice feature called "web-forms". There are two types of forms currently available i.e. WCM forms and ECM forms. Both of them capture the input data and store it as XML. You can also choose to apply content transformation using XSL. It helps to save final output as either HTML, Text or PDF etc. Not to forget, the content is actually captured and saved as XML. In my perception one of the strengths of Alfresco is its content repository. If XML is target format, it is saved in CR as a cm:content property and it defeats the whole purpose. If CR is not aware of the structure of the content, it defeats the purpose of content model definition? It is not very different from storing the content xml as plain string in database. Frankly I don't see any benefit of using CR over database in this method.

To avoid such inefficient use of alfresco, you can take some effort and write a custom form component. Use custom forms (develop forms in your application and then communicate with alfresco using API) to capture user data and store them in content repository in defined content model and schema.

This will help you in -

  • Content repository now understands the structure of your content. This is really important and if you have any doubts, please post that in comments. I might write about it later in my blog.
  • You can apply your custom content transformation logic so that content can be exported in XML / HTML / custom output format. Just generate this once every time you update the content. It improves the efficiency of content management system to deliver target content.
  • You will have a flexibility of own input format, use JSP or rails forms, its your choice!

Deployment benefits - Alfresco has another great strength, Deployment Infrastructure. I think its also one of its weaknesses. Use it wisely to improve your release management. On the release date of web application usually you come across content sanity issues, or format differences. To avoid that, setup proper environments where alfresco can sync content and test it before you push it to live. This might save you a lot of frustration.

Although its a great feature, there is a caveat to that. Generally all the code for web application is stored in CVS systems. Alfresco code (web scripts, web form definitions etc.) is stored in alfresco. Keeping the versions of alfresco code and web application code is nightmare. Develop some automated web script deployment tool and every time you release, wipe out all the previous webscripts and deploy new ones from the CVS. This always makes you keep updated code in the CVS and versioning becomes much robust.

Posted in Articles, Developer | Tagged , | Leave a comment

Ubuntu: Cisco VPN Client installation on Intrepid

Cisco VPN client for Linux installation doesn't happen out-of-the-box. There is plugin of VPNC which gets integrated with NetworkManager of Ubuntu but I didn't focus on that. Maybe somebody would like to guide the steps for it. I investigated a little and found bunch of articles / blog post about VPN issue. Some of the articles needs an update. Following steps will get VPN client working on Ubuntu Intrepid and use certificate based authentication to connect.

First get the distribution of VPNClient for Linux. This distribution is valid for 32-bit as well 64-bit installations.

wget http://tuxx-home.at/vpn/Linux/vpnclient-linux-x86_64-4.8.01.0640-k9.tar.gz
tar -xvzf  vpnclient-linux-x86_64-4.8.01.0640-k9.tar.gz
cd vpnclient
sudo ./vpn_install

This command should result in similar output below:

Cisco Systems VPN Client Version 4.8.01 (0640) Linux Installer
Copyright (C) 1998-2006 Cisco Systems, Inc. All Rights Reserved.

By installing this product you agree that you have read the
license.txt file (The VPN Client license) and will comply with
its terms.

Directory where binaries will be installed [/usr/local/bin]

Automatically start the VPN service at boot time [yes]

In order to build the VPN kernel module, you must have the
kernel headers for the version of the kernel you are running.

Directory containing linux kernel source code [/lib/modules/2.6.27-7-generic/build]

* Binaries will be installed in "/usr/local/bin".
* Modules will be installed in "/lib/modules/2.6.27-7-generic/CiscoVPN".
* The VPN service will be started AUTOMATICALLY at boot time.
* Kernel source from "/lib/modules/2.6.27-7-generic/build" will be used to build
the module.

Is the above correct [y]

Making module
make -C /lib/modules/2.6.27-7-generic/build SUBDIRS=/home/sachin/vpnsandbox/vpnclient
modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.27-7-generic'
CC [M]  /home/sachin/vpnclient/linuxcniapi.o
In file included from /home/sachin/vpnclient/Cniapi.h:15,
from /home/sachin/vpnclient/linuxcniapi.c:31:
/home/sachin/vpnclient/GenDefs.h:113: error: conflicting types for ‘uintptr_t’
include/linux/types.h:40: error: previous declaration of ‘uintptr_t’ was here
make[2]: *** [/home/sachin/vpnclient/linuxcniapi.o] Error 1
make[1]: *** [_module_/home/sachin/vpnclient] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-7-generic'
make: *** [default] Error 2
Failed to make module "cisco_ipsec.ko".

To get around this error you need to patch couple of files in the existing source. Download the patch and apply it.

wget http://projects.tuxx-home.at/ciscovpn/patches/vpnclient-linux-2.6.24-final.diff
patch < ./vpnclient-linux-2.6.24-final.diff

After successful patch of the files you can go ahead to the install procedure again -

sudo ./vpn_install

You can see all files getting compiled successfully. If it is successful you will see a message like below -

* You must run "/etc/init.d/vpnclient_init start" before using the client.
* This script will be run AUTOMATICALLY every time you reboot your computer.

Now you can copy your vpn configuration files (*.pcf) in /etc/opt/cisco-vpnclient/Profiles folder and you can start connecting the vpn network using command -

vpnclient connect

If you want to use certificate based authentication for the connection then following do following operation.

sudo cisco_cert_mgr -U -op import

This will ask you for the certificate file location and password for the file if required. Enter the passwords for importing certificates if required and try with connection.

Posted in Ubuntu | 15 Comments