Tuesday, January 14, 2014

Ok, Google. Extraordinary feature by Google

World is becoming lazy so am I :-)

Welcome to the world of Google Now. This app works on Android 4.0+.  I recently purchase Nexus 5 phone and found Google bar on my homepage raising curiosity. It is having mike icon prompting me to say something.  It activates by simply saying "Ok Google" and now wonder starts.

What all things you can do with Google Now. Here are the various commands you can try.

Phone Calls 

To place the call simply tell "Call ". If there are more than one contacts found then it will prompt you to select one of them.  If there are more numbers associated with any contact then again it will prompt you to select one. Amazing.

SMS

Again if you want to send sms to any contact in phone's address book simply say "Text " for example "Text wife I will be late for home" and you will be amazed.

Getting Directions

Many times I found it irritating to stop my car to search for the driving direction to the place I am visiting.  Now google has made it easy.  You just need to tell Google Now where you are headed by saying something like "Driving direction to Pune Airport" or "how to get to Pune Airport" and it will give directions from your current location to Airport in just few seconds. How convenient.

Launching Installed Apps

 To launch any installed app in your phone you give command like "Open Temple run 2" and if it finds this app then it will launch this app for you. To launch particular webpage you need to tell "go to www.espncricinfo.com" and it will open browser with this website.

Setting Alarms

 If you want to set alarms then you just need to say "Set Alarm for 6.00 AM" to set alarm for particular time or you can say "Set alarm to 5 hours from now" and alarm would be set from 5 hours from current time. How easy.

Events and Reminders

You can set events by just telling Google Now "Create an calendar event for 8 to 8.30" and it will precisely set it for you.  If you want to Schedule meeting event then you can say "Schedule meeting with Client at 3 to 4".

You can set note for yourself by telling "note to self " and note will be created in Google Keep.

To set reminders you just need to tell Google Now "remind me to " for example "remind me to feed my fish today evening" or even more advanced reminders can be set like "remind me to call the boss when I reach home".  For this to work properly you have set location of your home or your office or grocery store, etc. Mind blowing.

Writing Emails

To send emails you command it "send email to subject message " for example "send email to Rinku subject hi message I am coming to pune this weekend.  Will you be available?" and it will send email as commanded.  Similarly you can post on Google+ by saying "post to google+".

Ask Questions

 Everyone knows Google is Pantomath and it knows everything.  So you can consider Google Now as Google Search and ask any question and it will do search for you.  For example "Find Petrol pump" and it will find all petrol pumps in 1KM area.

Enjoy...




Sunday, November 17, 2013

Configuring VNC server to display Gnome/KDE desktop when connected through VNC client

We all are tired and irritated with the default UI shown by VNC client and would love to have UI showing more menu's and user friendly UI when connected through VNC client.  Here are the simple steps which will show you user friendly Gnome desktop when connected through VNC.

Few basic assumptions:
  • VNC server is already installed on the machine 
  • User can find xstartup file of VNC in /root/.vnc folder on Redhat Linux boxes. User needs to find corresponding folder for other operating systems.

Steps to change the Desktop
  • Go to .vnc folder
  • Edit xstartup file using editors like vi
  • Initial xstartup file will look something like:
    #!/bin/sh

    # Uncomment the following two lines for normal desktop:
    # unset SESSION_MANAGER
    # exec /etc/X11/xinit/xinitrc

    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    vncconfig -iconic &
    xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    twm &
  • Change it to below to start gnome desktop
     #!/bin/sh

    # Uncomment the following two lines for normal desktop:
    # unset SESSION_MANAGER
    # exec /etc/X11/xinit/xinitrc

    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    vncconfig -iconic &
    xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    #twm &
    exec gnome-session &
  • Change it to below to start KDE desktop
     #!/bin/sh

    # Uncomment the following two lines for normal desktop:
    # unset SESSION_MANAGER
    # exec /etc/X11/xinit/xinitrc

    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    #xsetroot -solid grey
    #vncconfig -iconic &
    #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    #twm & 
    startkde &
  • Kill all the VNC server sessions which are running using command
    vncserver -kill :1
  • Start VNC server 

Tuesday, October 9, 2012

Array to Hash

my @arr = ("Hundred", 100, "Ten", 10, "Thousand", 1000);
my %denomination = map { $_->{key} => $_->{value} } @arr;

while (($key, $value) = each(%denomination))
{
     print "$key, $value\n";
}

Output:
Thousand, 1000
Hundred, 100
Ten, 10 

Wednesday, September 26, 2012

Deletes property in property file if property value matches the given value

# Function Name    :: deleteParameterForValue($$$$)
# Input            : 1. name of the property file
#                  2. Parameter name
#                  3. Parameter Value
#                    4. Delimiter
# Output        : none. Deletes the given parameter from a given file based on value
# Description    : Deletes given property from a given file if its value matches the given value
sub deleteParameterForValue($$$$)
{
    my ($file, $parameter_name, $parameter_value, $delimiter) = @_;
    $parameter_name = &trim($parameter_name);
    $parameter_value = &trim($parameter_value);
    $delimiter= &trim($delimiter);

    $file = &convertSlash(&trim($file));
    my $new_str = "";
    open (FI, $file) or do {  return -1;  };

    while ()
    {
        my ($str) = $_;
        chomp ($str);
        $str = &trim($str);

        unless (($str eq "") || (substr($str, 0, 1) eq "#"))
        {
            my $key = &trim(substr($str, 0, index($str, $delimiter)));
            my $value = &trim(substr($str, index($str, $delimiter) + 1));
           
            if (($key eq $parameter_name) && ($value eq $parameter_value))
            {
                next;
            }
            $str = join($delimiter, $key, $value);
        }
       
        $new_str .= "$str\n";
    }
    close (FI);

    open (FO, ">$file") or do { return -1 };
    print FO $new_str;
    close(FO);
}

Deletes property in property file if property name matches the given parameter

# Function Name    :: deleteParameterForKey($$$)
# Input            : 1. name of the property file
#                 2. Parameter name
#                 3. Delimiter
# Output        : none. Deletes the given parameter from a given file
# Description    : Deletes given property from a given file
sub deleteParameterForKey($$$)
{
    my ($file, $parameter_name, $delimiter) = @_;
    $parameter_name = &trim($parameter_name);
    $delimiter= &trim($delimiter);

    $file = &convertSlash($file);
    my $new_str = "";
    open (FI, $file) or do {  return -1;  };

    while ()
    {
        my ($str) = $_;
        chomp ($str);
        $str = &trim($str);

        unless (($str eq "") || (substr($str, 0, 1) eq "#"))
        {
            my $key = substr($str, 0, index($str, $delimiter));
            my $value = substr($str, index($str, $delimiter) + 1);
           
            if ($key eq $parameter_name)
            {
                next;
            }
            $str = join($delimiter, $key, $value);
        }
       
        $new_str .= "$str\n";
    }
    close (FI);

    open (FO, ">$file") or do { return -1 };
    print FO $new_str;
    close(FO);
}

Update value of a parameter in a property file

# Function Name    :: updateDataFile($$$$)
# Input            : 1. name of the property file
#                 2. Parameter name
#                 3. Parameter value
#                 4. Delimiter
# Output        : none
# Description    : Opens the given property file and update the value of given prameter
sub updateDataFile($$$$)
{
    my ($file, $parameter_name, $parameter_value, $delimiter) = @_;
    my $found_flag = 0;

    $file = &convertSlash($file);
    my $new_str = "";
    if (not -e $file)
    {
        open (FO, ">$file") or do { return -1 };
        close (FO);
    }
    open (FI, $file) or do {  return -1;  };

    while ()
    {
        my ($str) = $_;
        chomp ($str);
        $str = &trim($str);

        unless(($str eq "") || (substr($str, 0, 1) eq "#"))
        {
            my $key = substr($str, 0, index($str, $delimiter));
            my $value = substr($str, index($str, $delimiter) + 1);
           
            if ($key eq $parameter_name)
            {
                $value = $parameter_value;
                $found_flag = 1;
            }
            $str = join($delimiter, $key, $value);
        }
        $new_str .= "$str\n";
    }
    close (FI);

    if ($found_flag == 0)
    {
        my $str = join($delimiter, $parameter_name, $parameter_value);
        $new_str .= "$str\n";
    }

    open (FO, ">$file") or do { return -1 };
    print FO $new_str;
    close(FO);
}

Reading complete property file and return hash

# Function Name    : readInputFile
# Input                    : 1. Input file name
#                              2. Delimiter.  if not specified then = will be used
# Output                : None
# Description            : This subroutine will parse input file having key-value pair and create hash.  # as first character in file will be ignored
sub readInputFile($$)
{
    my ($file, $delim) = @_;
    $file = &convertSlash(&trim($file));
    $delim = &trim($delim);

    my %list;

    if ($delim eq "")
    {
        $delim = "=";
    }

    open (FI, $file);
    while()
    {
        my $line = $_;
        chomp $line;
        $line = &trim($line);

        unless ((substr($line, 0, 1) eq "#")  || ($line eq ""))
        {
            my ($key, $value) = split($delim, $line);
            $key = &trim($key);
            $value = &trim($value);

            if (exists $list{$key})
            {
                $value =  $list{$key}."::$value";
            }

            $list{$key} = $value;
        }
    }
    close (FI);
    return %list;
}