Saturday, August 29, 2015

How to configure mutt for gmail

mutt is a terminal-based e-mail client for Unix-like systems . For more info read this

==> install mutt as

$ sudo apt-get install mutt

==> Edit .muttrc file in home directory

$vi ~/.muttrc

## and paste the below contents and edit the necessary .

set imap_user="USER@GMAIL_APPS_DOMAIN" ##anmoldeep0123
set imap_pass="PASSWORD"
set ssl_force_tls=yes
set smtp_url="smtp://USER@GMAIL_APPS_DOMAIN@smtp.gmail.com:587/"
##set smtp_url="smtp://anmoldeep0123@smtp.gmail.com:587/"
set smtp_pass="PASSWORD"
set folder="imaps://imap.gmail.com:993"
set spoolfile="+INBOX"
set imap_check_subscribed
set hostname=gmail.com
set mail_check=120
set timeout=300
set record="+[Gmail]/Sent Mail"
set postponed="+[Gmail]/Drafts"
set beep=no
set realname="YOUR NAME"
set from="USER@GMAIL_APPS_DOMAIN" ##anmoldeep0123@gmail.com
set use_from=yes
set use_envelope_from=yes
set sort=threads
set arrow_cursor
set header_cache=~/.mail/cache/headers
set message_cachedir=~/.mail/cache/bodies
set certificate_file=~/.mail/certificates
set implicit_autoview
auto_view text/html
set mailcap_path="~/.mailcap"

bind index ' ' next-page
bind index '-' previous-page
bind index c mail
bind index g change-folder
bind index x sync-mailbox

bind pager ' ' next-page
bind pager '-' previous-page
bind pager c mail
bind pager g change-folder

color index     blue    default "~C USER"   # to or cc USER
color index     red     default ~D          # deleted
color index     green   default ~U          # unread
color index     yellow  default ~T          # tagged
color indicator black   yellow
color message   black   red
color quoted1   cyan    black
color quoted2   yellow  black
color quoted3   red     black
color quoted4   green   black
color quoted5   blue    black
color quoted6   green   black
color signature blue    black
color status    blue    black
color tree      cyan    black
 
==> Run mutt
$mutt

Wednesday, August 26, 2015

Morphia FAQ's helper links etc

JavaDoc
MongoDB javaDoc
Reference

http://www.javabeat.net/using-morphia-java-library-for-mongodb/
https://dzone.com/articles/using-morphia-map-java-objects
http://sleeplessinslc.blogspot.in/2010/10/mongodb-with-morphia-example.html

Wednesday, July 15, 2015

URL based class loading in Java and dynamically adding directories to java classpath @ runtime

1. How to load a class dynamically at runtime by using URLClassLoader .

// Main Method
        try { 
            URL url = new URL("file:///<path to my jar file>.jar");
            URLClassLoader urlClassLoader = new URLClassLoader(
                    new URL[] { url });
            Class clazz = urlClassLoader
                    .loadClass("org.sample.package.ClassName");
            Object obj = clazz.newInstance();
            System.out.println(obj.toString());
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

Explanation:

Create a URL object of the jar file 
Pass the URL object to the URLClassLoader
Call loadCLass on the URLClassLoader object , specifying the class name with the package hierarchy , as argument.
Create a new Instance of the loadedClass
Refer to newInstance()for more details.
Use the obj of the loaded class to call a method.

Exceptions to be handled:

IllegalAccessException - if the class or its nullary constructor is not accessible.

InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.

ClassNotFoundException - If the class was not found

MalformedURLException - if an unknown protocol is specified.

                                   ###########################################

2. How to dynamically add directories from a fileSystem to Java ClassPath @ Runtime 

// Main Method
        try {
            File file = new File("absolute/path/to/the/directory");
            Method method = URLClassLoader.class.getDeclared
                  Method("addURL", new Class[] { URL.class});
            method.setAccessible(true);
            method.invoke(ClassLoader.getSystemClassLoader(),
                    new Object[] { file.toURI().toURL() });
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

Explanation:

Create a file object for the directory to be added to the classpath.
Get the method object of addUrl method of the class URLClassLoader
For more details see this.
Reflected object should suppress Java language access Checking when it is used , hence the setAccessible(true).
Invoke the method , the first argument is the class invoking the method and the following arguments are sent as arguments to the invoked method in orderly fashion. 

Exceptions to be handled:

NoSuchMethodException - if a matching method is not found.

SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException 

Refer this

MalformedURLException - if an unknown protocol is specified.

I hope you learned something new today .

Saturday, July 11, 2015

How to install Sublime text editor using apt-get on Linux using PPA

Sublime Text is one of the most popular editors and my favorite for writing computer Programs in various languages . Now if you are windows user , its not pretty difficult to download and install this editor simply click here and download the required version and install.

Also this link can help you download the Linux binaries but  guess what you are not the unzip candidate who wants to keep binaries in a directory and add that to you unix / linux PATH . You are the apt-get guy .

So what to do then , simply follow these steps

So what to do then , simply follow these steps

### add sublime ppa to repository ###


sudo add-apt-repository ppa:webupd8team/sublime-text-2

Repository maintained by  webupd8 team.

### update ###

sudo apt-get update

### install ###

sudo apt-get install sublime-text

### check installed version ###

anmol@anmol-Studio-1555:~/sw$ sublime-text -v
Sublime Text 2 Build 2221

Enjoy 

How to install / upgrade to JAVA 8 (JDK 8u45) on Ubuntu & LinuxMint using PPA

Oracle JAVA 8 Stable release has been released on Mar,18 2014 and can be downloaded and installed from Oracle Java downloads . Oracle Java PPA for Ubuntu and LinuxMint is being maintained by WebUpd8 .
 
Read about the new features about Java 8 here .

This article will help you to Install Oracle JAVA 8 (JDK/JRE 8u25) on Ubuntu 14.04 LTS, 12.04 LTS and 10.04 and LinuxMint systems using PPA File.

Installing Java 8 on Ubuntu

Add the webupd8team Java PPA repository in your system and install Oracle Java 8 using following set of commands.


$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

Verify Installed Java Version

After successfully installing oracle Java using above step verify installed version using following command.

anmol@anmol-Studio-1555:~$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)  

Configuring Java Environment 

In Webupd8 ppa repository also providing a package to set environment variables, Install this package using following command.

$ sudo apt-get install oracle-java8-set-default 
 
References :

https://launchpad.net/~webupd8team/+archive/ubuntu/java
http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

Saturday, June 20, 2015

A Stock Management Software - I call it stockIT

Well this one is more of a blog which will be a memory than a web hit . Today 20-06-2015 , ohh well lets go few days back , so starting last Tuesday , i started trading on my DMAT account , invested slowly , slowly till i became all crazy about it and started investing more , and guess what 3K in 4 days , that's what i could make , with an initial investment of 40K . 

Well , well , well , which bank in this small world gives such an interests , practically none . Anyways , that;s not the point . Now i ended up buying more and more shares of different companies and i felt that i need a SHARES management system for myself local on my desktop , i don't want to login to my trading account and keep seeing my investment , reports and profits. 

So what i decide to write my own stock buying and selling management system , started early morning and i have the back end ready by now . Yet i  need to write the UX . Well who knows if this ends up great , i might end up sharing it publicly on github or somewhere.

Next is , should i write the UX as a desktop application or a web application , that decision is still to be taken . 

Ohh let me share , the backend is Java and database used is OrientDB a nosql graph database , ah i might have talked about it a lot in my previous blogs .

So as of today , as i sleep , the software i wrote in morning , add the stock i bought to the database , adds the stocks i sold to the database , keeping a relation between the bought stock and the sold stock of the same company , and well yeah it generates a report in the form of a db table / vertex here , that tells me each companies' share i bought and sold , total investment , total sales , profit or loss . 

More to be implemented . I don't know if you read this entire blog or not , but if you did i really appreciate it , keep reading .

-@nmol

Thursday, June 18, 2015

How to deal with FindBugs in your project

FindBugs is a google project which many of the companies use in their product development lifecycle to findBugs in a java project . Well this can be used as a command line tool or as a plugin to a build automation framework , lets take Gradle for example .

Well findBugs hunts your code very effectively to find stupid coding mistakes which one would not take care of much while coding .

Lets take a look at what does find bug hunt for . Well this is it : BugCodes.

I am not here to talk about findBugs , neither i am here to talk about gradle .

What i am gonna share is how i got messed up with findBugs BugCode : RV .
 
A situation  where i  had to ignore the return value of  function and also call that function for something to work in background . Well i really got fed up with findBugs to catch my error everytime and keep failing the build.

Well how to supress this warning and go ahead with the build.

-> If you are not a gradle expert do not try this , in build.gradle , in
findbugsMain  {
}

you need to give excludeFilter and a file which specifies the format of the classes and the methods and Bug Code to ignore. Well this was a nightmare and i could not achieve it. Check if you can here   .

-> Well if you are a java expert which you i hope you are , all you need to do is add  this dependecy in your project build file and use the Annotation

@SupressFBWarnings(value = "bug-code") -- well value is an array so you can send in a string array .

OR

if you are not using a build automation framework like ant , maven or gradle , all you need to do is download the annotations.jar from  - here and include it in your project library.

Well there you go and you have succeeded in suppressing findBugs warnings and your build has not failed at this point .

Happy Coding

-@nmol

Saturday, June 13, 2015

Java Virtual Machine Analysis and Debugging

Hello Folks whoever is reading this i am sharing my experience of Performance Testing i was involved in , in one of my projects in my company.

-->  Load Testing the API's written for a business model on top of a nosql graph database OrientDB . We used an open source XA transaction manager JCA adapter deployed on the Oracle weblogic server 12.1.3 . The API's were deployed as a restful web-service on the same application server as the adapter .

Client Tools used -
-> SoapUI
-> Jmeter

SoapUI and Jmeter are the best two tools i felt to fire http requests to the rest webservice , one can select the number of concurrent users / threads hitting the web service , in Jmeter and can loop such requests multiple times or forever . However SOAPUI provides the flexibility to send n number of concurrent clients and also fix the time for which the client will fire requests , also providing the lag between every next request .

Learn Jmeter @ JMeter Tutorial

However i often saw the JVM getting on slower and slower as the requests came , hence needed to get the Thread Dump periodically and analyze the thread dump , used few tools for this .

-> Jstack : This tool was used to get the thread dump , this tool can be found inside bin directory of jdk installation directory.

-> Samurai : This tool takes the thread dump and gives a gui representation of running , blocked and deadlocked threads. This tool will be helpful to analyze the threads that are going into blocked state slowing down the CPU and the JVM.

Further we found in the performance tab under Monitoring section under managed servers section of Oracle Weblogic server , that free heap percentage is growing lesser and lesser as the application serves the client requests .

-> Jmap : This tool was used to get a heap dump as and when we needed , whenever the free heap percentage went down and down. These tests were carried out on a 2GB heap so @ 5% free heap the HeapDump size came out to be 3.7G + .

Now how to analyse this heap dump , so there are a lot of tools to do that .

-> VisualVM : This is the best and free tool to anaylze the heap dump and will tell you the number of instances of each of the Objects with existing references and will also tell where the references are coming from.

-> Jprofiler : Jprofiler is not free but allows a 10 day free trial , again a great tool to analyze heap dump , provides the same details as above. However loads the entire heap initially , little slower than VisualVM.

-> MAT : Memory analyzer tool is an eclipse project , another alternative for heap dump analysis , however personally i didn't like this tool , much slower than the above two , but still worth a try.

-> Jhat : Jhat is again a tool provided in the bin directory of the jdk installation directory , its the oracle's provided tool to analyze heap dump . This will load the heap data as html and can be accessed on localhost port 7000 . A  very simple tool to use and provides the same data as Visual JM and Jprofiler.

This was all about thread dump and analysis and heap dump and analysis .

Finally we found the objects that were not garbage collected and accordingly modified the JCA adapter code to use the OrientGraphFactory and calling the getTx() method instead of manually creating OrientGraph objects which were never getting garbage collected.

Thursday, June 11, 2015

My First Blog

Dear Blogspot ,

Its 12:40 am at midnight on Thursday June 11 , 2015 when i get to write my first blog , well this is hardly a blog but an introduction to blogger.com . Hmmm how did i think of writing , well first of all i like traveling and i have traveled a lot so i thought why not write about my travel , the roads i have taken , the journey , the treks , the forests,  the company of friends and sometimes even strangers who become good friends, the memories created etc .

Also i wish to write technical blogs , things i learnt ,  technologies i have used and worked on , so i started actually using the blogger i created back in 2009.

Now this is my first blog so , not putting down a lot of stuff here . By the way i never introduced myself , I am Anmol Deep , born and brought up in small town Sarwal in the beautiful city of Jammu (J & K) . I am a Software Engineer by profession and have been working for 3 years in Bangalore . It will be seven years this September in Bangalore .

Following is the link to my fB profile , wish to meet new interesting people and learn
from a lot of people.


Facebook

and following is my linkedIn profile if you wish to hire me someday in your company , ahh i would love to join the best industry in market.

 LinkedIn

I think its time to sleep with the pc clock @ 12:50 AM asking me to crash as tomorrow is going to be a long day .

I hope you get to read many interesting blogs about my travel , my road trips , my journey , my life .

-@nmol