Friday, May 11, 2012

Working with databases in mysql

The following is a brief tutorial on how to login to mysql shell from Linux (Ubuntu 11.10).

First of all mysql-server must be installed in your system. To enter the mysql commands from the shell we need to first change into mysql shell from the default unix shell window. To do this,

  • Find the mysql directory in your local computer. (by default this is /usr/bin if you installed mysql from the terminal via apt-get install). Now we need to get into mysql shell.
  • Enter the following command in a terminal window.
         $ [mysql-directory]/bin/mysql host -u root -p
  •  In my system this is,
          $ /usr/bin/mysql mydb_1 -u root -p where host is replaced by the corresponding database name i need to connect. This tells the system to connect the database as root by demanding the password (-p). Once you get connected the following text would appear and mysql shell would be opened.

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 151
Server version: 5.1.62-0ubuntu0.11.10.1 (Ubuntu)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


Now we can enter any valid mysql command and proceed with database queries. Following are some of the common and important commands. Always keep in mind that each command must be finished with ; or \g

1. To view the 'help' entries
mysql> help;


2. To view the list of existing databases
mysql> show databases;

The output will be something like,
mysql> show databases \g
+------------------------------------+
 | Database                    |
+----------------------------------+
 | information_schema |
| mysql                        |
+-------------------------------+
2 rows in set (0.00 sec)
 


3. To create a new database
mysql> create database mynew_db;

4. To drop a database
mysql> drop database mynew_db;
The output will be like,
Query OK, 102 rows affected (23.71 sec)
 

5. To quit or exit from connection
mysql> exit; or  mysql> quit;






Monday, April 23, 2012

GSoC 2012, this summer with OpenMRS!

WoW after all the hard effort I got selected into Google Summer of Code 2012 to work with OpenMRS today. OpenMRS was the only organization i tried in this summer GSoC as i was so interested in the project as well as the support got from the community during the time of GSoC was awesome.



It was a bit struggling experience at the beginning as i had never worked with OpenMRS before so i was trying very hard in getting familiar with the project and catch up the speed. There were sometimes where i really felt to give up and pack off when i started fixing the first  ticket of the project. But anyway i never stopped trying and with a few days of killing myself (and also with great guidance got from community experts through IRC), i finally managed to understand the code a bit and could work in some introductory bugs. Life was much easier after that and it became more and more fun with the time going :) 

When going through the list my first interest was project HTML Form Entry Module Enhancements (to which i got selected at last, Yeppi :)). I felt a natural interest for that as i had formally worked with HTml,JSP etc. during my internship at WSO2 so immediately decided to begin OpenMRS with it :D. After contacting my mentor i could get some more information about the project and Mark, my mentor gave me some good  advice on how to begin and getting familiar with code. I first worked on an intro ticket with his guidance and when it was done moved onto other etc. It is really appreciated the guidance and support i got from my mentor Mark Goodrich, as he was very helpful towards me since from the beginning.

I applied for two projects in OpenMRS this summer "HTML Form Entry Module Enhancements" and "Personal Health Record Module Enhancements". I was looking forward to work in any of the two if i get selected but was extremely happy to know that i got my first choice project to work. 

"OpenMRS is a software platform and a reference application which enables design of a customized medical records system with no programming knowledge (although medical and systems analysis knowledge is required). It is a common platform upon which medical informatics efforts in developing countries can be built. The system is based on a conceptual database structure which is not dependent on the actual types of medical information required to be collected or on particular data collection forms and so can be customized for different uses." 

The HTML Form Entry module in OpenMRS allows one to create forms to enter and edit patient data within the system. The approach is very simple since user needs to know a little HTML and also about the basics of OpenMRS system. It allow users to write forms using standard HTML tags combined with a set of special tags that reference different aspects of the OpenMRS data model. The module has been improved a lot throughout the past, and my project is also to enhance the performance and feature support for the HTML Form Entry module.


Some tips for the future GSoCers  of OpenMRS from me.

  • It is never too late to start if you can commit hard and make a change. The main thing is trying your maximum and get something done, which will show the community that you are talented and committed too.
  • Join into mailing lists and IRC and discuss if you have trouble in proceeding with some point. From my experience i could solve in many issues after discussing it in IRC. Don't be hesitate to call for help :)
  • Read the documentation lot, it has almost everything regarding system and modules.
  • Try to fix at least few introductory bugs, it is the best way to get to know the code.
  • Contact your mentor, other community experts etc. in the need of a help.

That's all for now. But looking for more excitement to come in the next few days.

Happy GSoC to all my fellow OpenMRS interns as well as to others too!

Monday, March 26, 2012

Remote debugging maven jetty with IntelliJ Idea in Ubuntu 11.10

Jetty web server is an open source http server/client container which can be used to run and test webapps.  Jetty server provides a plugin to integrate with apache maven and it can be used to run a webapp in a maven project. To do this we need to add jetty-maven-plugin into our <plugins> section by adding it into webapp pom.xml file.

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.10</version>
            <configuration>
               <webXml>${project.build.directory}/jetty/WEB-INF/web.xml</webXml>
               <webAppConfig>
                  <contextPath>/${webapp.name}</contextPath>
                  <!--enable reloading static resources -->
                  <overrideDescriptor>src/test/resources/override-web.xml</overrideDescriptor>
               </webAppConfig>
               <scanIntervalSeconds>10</scanIntervalSeconds>
            </configuration>
         </plugin>


Now add the following Maven Options line into your .bashrc file.

For JDK 1.3 or above :
export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"

For below JDK 1.3:
export MAVEN_OPTS="-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"

Goto the webapp folder from terminal and enter,
 mvn jetty:run
Jetty server will start on debug mode and will listen on port 8000 now. The following info will be appeared in terminal.




Goto IntelliJ Idea project and create a remote debug confiruation giving following parameters. (to do this follow the path Run --> Edit Configurations. Click on the + button followed by Remote and you will see remote configuration window appears)


Host = localhost
Port = 8000

Run the remote debug and it will also listen on port 8000 now.

Tuesday, March 6, 2012

Configuring proxy settings for Apache Maven

Ever wondered how to build your project with Apache Maven via a proxy server? This is a brief tutorial on how to do so.

Environment : Ubuntu 11.10 Oneiric
                        Apache maven 2.2.1

Apache maven holds all the configuration data in a single file called settings.xml file inside the 'conf' directory in the main directory of maven. The file includes configuration details regarding the proxies therefore we need to edit that section in order to enable the proxy server for a maven build.

This is how to do it.
  • Download the maven binary distribution from Apache Maven downloads page. The newest version is 3.0.4 however the stable version is 2.2.1 for the existing projects which are not upgraded into maven 3.
  • Extract the binary distribution into somewhere in your hard disk. apache-maven-2.2.1 directory will be visible now. Browse to the 'conf' directory inside 'apache-maven-2.2.1' main directory.
  • The 'settings.xml' file is inside the 'conf' directory. Open the file with a text editor and uncomment the section between <proxy> </proxy> tags. Edit the <proxy> entry as follows.
<proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     | -->
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>MYHOST.LK</host>
      <port>3200</port>
      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    </proxy>
   
  </proxies>
  • Replace the MYHOST.LK address with the host address of your proxy server and replace the port number with relevant proxy port too. Save and close the file, now and you are ready to build via a proxy :)

Sunday, January 22, 2012

How to set up Apache Subversion to be accessed via a proxy (With Ubuntu))

I was going to access a subversion repository from my university network proxy for the first time and it was then that i realized that it is not possible with the usual subversion configuration. There are many options can be used in overcoming this  but the following simple solution worked for me very well.

Apache Subversion uses the 'servers' file to keep track of its' server configurations. If we need to use subversion through a proxy server the proxy-host and the port must be first configured in this file as it is not enabled by default. The simple steps to do this is;

1. We have to add the proxy server configuration into the 'servers' file in both locations.
  • /etc/subversion directory in our root directory 
  • .subversion directory in our home directory. 
However it would be sufficient only changing the 'servers' file in  .subversion directory to make this works.
2.However we can't edit the 'servers' file in etc/subversion directory since it demands root permission to edit it. So we have to open file as the root.
Open a terminal window by using ctrl+alt+T keys and enter the following command.

isha@pc:~$ sudo su
[sudo] password for isha: 

This will demand you for the password before providing root privileges.Enter the password and now we have root access in our computer. Go to the directory and open 'servers' file in text editor now.
root@isha-pc:/home/isha# cd /etc/subversion 
root@isha-pc:/etc/subversion# gedit servers
The 'servers' file will be opened now in the text editor. Look for the [global] settings section you will see some lines like this.

[global]
# http-proxy-exceptions = *.exception.com, www.internal-site.org
# http-proxy-host = my.proxy.domain.com
# http-proxy-port = 7000
# http-proxy-username = defaultusername
# http-proxy-password = defaultpassword

Change the 'http-proxy-host' with the address of your proxy server (excluding http:// part) and enter the port number into 'http-proxy-port' line. If you need edit the username and password settings too.

Important: Remove # symbol and all the spaces in front of the line you changed as additional spaces will result errors in the configuration. 

After editing it will look like,

[global]
# http-proxy-exceptions = *.exception.com, www.internal-site.org
http-proxy-host = my.proxy.lk
http-proxy-port = 3100

Save the file and close it.

3.We need to add the same configuration into the 'servers' file in .subversion directory. However it doesn't need root access to edit this file. Therefore open the file as a normal user and add the above details. Save and close.

4. Open a new terminal tab and access subversion repository back.

A useful thread to know additional options will be, svn-over-http-proxy

Saturday, January 21, 2012

Install Flash Player in Ubuntu 11.10 (Oneiric Ocelot)

Flash player is one of the first applications you install after installing your operating systems. Most online media applications requires flash player in order to run various animations,clips and programs, therefore this post is purposed on installing flash in Ubuntu 11.10.

There are three ways to install flash player in Ubuntu.
1. Downloading  flash player package from the Adobe website and manually installing it. Before downloading select the .tar.gz package in the selection box.

2. Installing flash player through Ubuntu Software Center.

3. Installing flash player from Synaptic Package Manager.

Here i am describing how to install flash by using synaptic package manager. Open the synaptic package manager and type 'flash' in the search bar. You will see a list of packages is shown as the results.

 
Select the 'flash-plugin-installer' and mark it for installation. Now click the 'Apply' icon.

Synaptic Manager will now display the list of packages to be installed, description of the sizes of the packages etc. and will ask you whether you would like to install the program. Click 'Apply' now.


Flash player will be installed into your computer now. We can get this confirmed by again opening 'Synaptic' and searching for flash player. This time it will show the green mark on the flash-plugin-installer package which says that you have an existing flash player now.


















Friday, January 20, 2012

How to Install Eclipse Indigo 3.7 in Ubutnu 11.10

This is a brief tutorial on how to install Eclipse Indigo IDE 3.7.0 in Ubuntu 10.10. Downloading and installation is straight forward but many users might have difficulties in opening and running eclipse as not setting the JRE/JDK path correctly. Let's see how this can be done.

1. First download the Eclipse IDE (I selected Eclipse IDE for Java EE Developers) from http://www.eclipse.org/downloads/ page. Download either 32 bit or 64 bit version from a suitable mirror from the selection.

2.This will download 'eclipse-jee-indigo-SR1-linux-gtk-x86_64.tar.gz' package into your computer. Extract the package to a location in the hard drive.You will see that 'eclipse' directory is being created after the extraction. 

3.Open 'eclipse' directory and there will be following files and directories. Click the 'eclipse' executable icon. 

Fig.1: contents in the eclipse directory
4.If all the configurations are correct, the IDE will be started by clicking this icon and you can just start coding etc. But in most of the cases it will not start at first time and you will see the following error message. 

"A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations:[SOME PATH IN YOUR COMPUTER] java in your current PATH" 

Fig.2: JDK or JRE path missing in eclipse

5. This error occurs mainly because of the IDE can't find the correct path to the JDK or JRE in our computer. Therefore we have to explicitly configure the path to JDK or JRE in the IDE configuration file. 'eclipse.ini' is the initialization file which carries out important configurations to run eclipse. This file can be found in our eclipse_home directory (See the figure 1 to identify eclipse.ini file).

6. Open the file in a text editor and add the following lines to the beginning of file. Replace the '/usr/lib/jvm/jdk1.7.0/bin' path with the PATH to JDK_HOME/bin in your local computer. Then save the file.
 -vm
/usr/lib/jvm/jdk1.7.0/bin


7. Now we have configured JAVA path for the Eclipse IDE. Click the 'eclipse' icon back and this time it will start the IDE successfully. Happy coding :)
Fig.3: Eclipse Indigo 3.7.0