Monday 24 February 2014

Installing Apache Maven on Mac OS X

Well, all new Mac machines loaded with Lion and above, come pre-installed with Maven. In order to find out which version is installed on your machine by default, just type the following in terminal :

mvn -version

Mine came pre-loaded with v3.0.3 and the default Maven Home was set at /usr/share/maven

However you if want to upgrade the version or configure the Maven Home to a different location, perform the following steps :

  • After downloading, unzip it and copy the entire folder to some other directory. Let's say for instance - /usr/lib/apache-maven-3.2.1
  • We now need to a couple of environment variables to our bash profile. In terminal, type vi ~/.bash_profile and insert the following variables to it ( i for insert ).
  • Now lets add the environment variable M2_HOME so type export M2_HOME=/usr/lib/apache-maven-3.2.1
  • Also define the M2 environment variable so type export M2=$M2_HOME/bin
  • Next type export PATH=$M2:$PATH and save .bash_profile and quit ( :wq )
  • Finally type source ~/.bash_profile. Note that when you close and open a new shell, the same settings will be intact.
Confirm the new settings by typing mvn -version to see the updated Maven version and home.
Congratulations, you just customised Maven on your machine. 

Just as am writing this post, am thinking about some stuff about Nexus repository manager which will enable you to manage your Maven repositories. Never mind, I'll cover Nexus in another upcoming post. Stay tuned :)

Sunday 23 February 2014

Disable Google Chrome Notifications on Mac OS X

All Mac OS X users using Google Chrome browser might have recently noticed a new Google Notification icon ( a grey bell ) on the OSX menu bar.

You'll quickly notice that it's settings menu does not provide any intuitive way to exit or disable it.

In order to disable it, do the following :

Open Google Chrome browser.

In address bar, type chrome://flags

Now search for the option "Enable Rich Notifications" and change "Default" to "Disabled" from its drop down menu. Hope it helps.


Saturday 22 February 2014

Luxury Uber launches in Mumbai

Uber - the luxury pickup company has launched its operations in Mumbai. The current car fleet will feature Audi A8 and Mercedes E-class as well.

Signup now at this link and enter the promo code UberMumbaiLaunch to avail 2 free rides, valid till March 31 '14. Make sure you own an iPhone or an Android fone.

Costs : 

Base price : INR 100

For every kilometer : INR 17

Per minute surcharge : INR 2




Friday 21 February 2014

Getopts Tutorial - Command line options in Perl

In Perl, if we want the user to pass certain options at command line, we can define the switches in the program code using Getopts. Following is a brief tutorial underlying it's usage with a practical example.

First of all, search the CPAN for Getopt and you'll see a lot of available modules - each with a slightly distinct functionality. All serve the same purpose though - providing a framework for passing user-defined command line options.

Now, install either the Getopt::Long or Getopt::Compact or Getopt::Lucid module from CPAN. I assume you know how to install modules from the terminal. If not, dig in through this blog. You'll get the answers.

In this example, I'll use the highly rated Getopt::Long module. Make sure you refer the module's official documentation link for more details. The following illustration is about it's simple basic usage, just to give you a feel. I'll cover an advanced usage tutorial for this module in another post.

Ok guys, enough talk. Lets code some stuff. Here we go...

use strict;
use warnings;
use Getopt::Long;

my $name;
my $location;

GetOptions (

               'name=s' => \$name,
               'location=s' => \$location,
);

if ($name) {
          print "Welcome $name \n";
}

if ($location) {
          print "Hows the weather at $location \n";

}

Here, "name" and "location" are the options to which we pass an argument. Note that we have mentioned name=s and location=s. The alphabet 's' implies the switch will be of string type. If you want the switch to be of integer type, use i. ( Eg : 'age=i' => \$age ).

Also, the equal sign = indicates that it is a mandatory option. If you want an option to be optional, use the colon : sign ( Something like - 'help:h' => \$help ).

Save the program as Getopts_Ex.pl and now open the terminal. From the command line, run the program as follows :

perl Getopts_Ex.pl -name "IronCladZone" -location "New York"

The output would be as follows :


Note that you have to pass an argument for each mandatory option. If you don't pass an argument, you will get an error. You can also play around by defining a separate function with customized error messages or switches' usage. This can be extremely helpful to a newbie or a layman, informing him how to run the program and how to use the custom switches defined in the script.

The above code contains print statements within the "if" block. You can instead tweak the "if" block to call custom user-defined functions a.k.a subroutines from here and put the print codes in the subroutine. The output will be the same, but the below structure makes it more graceful and secure. In fact, I plan to cover the topic of subroutines in another fresh post. Stay tuned for that as well.

use strict;
use warnings;
use Getopt::Long;

my $name;
my $location;

GetOptions (

               "name=s" => \$name,
               "location=s" => \$location,
);

if ($name) {
          func_name();
}

if ($location) {
          func_location();

}


sub func_name()  {
            print "Welcome $name \n";
}

sub func_location()  {
            print "Hows the weather at $location \n";
}

Folks, do let me know your comments about this post and suggestions on how to improve the quality of the content. Ciao.

Tuesday 18 February 2014

Repeat last run command in Linux, Unix, OSX

In order to repeat the last run command on Linux, Unix, Apple OS X machines, type the following in terminal :

!!

Yes. That's precisely 2 exclamation marks.

Monday 17 February 2014

Perl Message Box Tutorial

Previously, we covered the Perl Listbox example using the Tk module. In this post, we will discuss about using Tk to create a simple Message Box.

First of all, install the Tk Msgbox module from the command line as follows:

sudo cpan Tk::MsgBox

Then consider the following code snippet : 

---------------------------------------------------------

use Tk;
use Tk::MsgBox;

my $m = MainWindow->new;

my $x = $m->MsgBox(
-title=> 'Perl MsgBox Example'
-message=> "Welcome to Tk Message Box"
-type=> 'okcancel'
);

my $button = $x->Show;

---------------------------------------------------------

The output window will be as follows :


In above example, we've used the okcancel box type. The msgbox type can be changed to one of the following : ok, okcancel, yesno, yesnocancel, retrycancel, abortretrycancel.

Even the info icon can be changed to error, warning types if needed.


List all Perl CPAN modules installed on the system

In order to list all the CPAN modules installed on a system, use the following command :

instmodsh

Now you'll see the following menu : 

Available commands are:
   l                      - List all installed modules
   m <module>   - Select a module

   q                     - Quit the program

cmd? l

On entering option l, it will display the complete list of modules installed on the system.

Eg: 

   Net::HTTP
   PDF::API2
   PDF::Report
   PDF::Report::Table
   PDF::Table
   Params::Validate
   Parse::CPAN::Meta
   Perl
   Perl::Destruct::Level
   Perl::OSType
   Probe::Perl
   SOAP::Lite
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker