Saturday, August 1, 2015

Impact of A.P.J Abdul Kalam

27 July 2015 , a message was spreading like anything, I was outside and got a call from my sister in the evening,

She :  Did u know the news ?
Me  :  What happened ?
She :  In news channel, they are telecasting the death news of Abdul Kalam.
Me  :  ....

After few minutes, there was a complete silence  in my mind.Here silence is  some kind of pain , I don't know how to express in words.

After a long time I asked question to myself

 "What this man did and why I can't digest the news?"

 Might be because ,
   In school I studied his book content as a subject
   In school days, I had an aim of become a scientist like him
   He is the former president of India
   He is one of the man from my state I can proud about

Any form of the reason silence remains the same.I had decided to stand on his words.

 "We should not give up and we should not allow the problem to defeat us"

"The youth need to be enabled to become job generators from job seekers" 

"Mudiyaathu Endru Nee Solvathai Ellaam Yaaro Oruvan Engo Seithu Kondu thaan Irukiran" (Someone is doing what you think that you can't do)
 

   - A. P. J. Abdul Kalam



Tuesday, December 30, 2014

Man of Steel movie quote

Movie dialogue that makes me think. Man of steel 




Father Leone tells to Clark kent : "Sometimes you have to take a leap of faith first, the trust part comes later"

Yes I think..


One man was showing his 6 year old cousin their location in Google Maps.
On seeing the blue spot, child calmly asked, "Where am I here? I can't see! Where are you?" 

Saturday, October 4, 2014

Parallel::ForkManager - Parallel Processing of a Perl script

 I recently used Parallel::ForkManager  perl module in one of my project.I was quite impressed by this module.By using this module it is very easy to do parallel processing where ever it needs.

My task :  Process thousands of client profiles information and store into a Database.

Approach : Form perl data structure to each profile and pass it to a subroutine that taken care of Database insertion part.

 So Every time when a profile Data structure has been formed , it has to wait till the completion of profile insertion part.

Stub :

my @responses; 
my $total_profiles = scalar @profiles;

for ( 1 .. $total_profiles ) {
    my $profile = shift @profiles;
    # form appropriate structure of $profile
    my $response =  storeProfile($profile);
    push(@responses , $response);
}

print Dumper \@responses;

#storeProfile subroutine has DB operations.

 
How Parallel Fork Manager helps to do it parallely 

use Parallel::ForkManager;
$max_process = 5;  #carefully  choose this number;

Carefully  choose max process because if your system is busy and it has more number of applications running , choosing a big number will affect other process.Parallel fork manager will create that many number of child process so each process will try occupy the cores.There is chance of system hang.

It is the advantage of the module, your script runs parallel y and make use of all cores.So the entire operation will be faster.

 In my task subroutine storeProfile runs parallel y  by 5 child process.So the speed of process will increase by 5 times

Assume that storing one profile took 0.5s 
than 
without Parallel::ForkManager 1000 profiles will take 500s
with Parallel::ForkManager 1000 profiles will take  100s
(if max_process is 10 then 1000 profiles will take  50s



$pm = new Parallel::ForkManager($max_process);
my @responses; 
$pm->run_on_finish(    # called at the end of child_process completion 
       sub {
           my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $response) = @_; 
          # retrieve response  from child
           if (defined($response)) {   
                push(@responses , $response);
           }
       }
);

my $total_profiles = scalar @profiles;

foreach ( 1 .. $total_profiles ) {
     my $profile = shift @profiles;
     # form appropriate structure of $profile
     #FORK HERE
     $pm->start and next;
     #following code will run by child process
     my $response = storeProfile($profile);
     $pm->finish(0, $response); 
}

$pm->wait_all_children; #wait till all the child process completes
print Dumper \@responses;


Note : 
       * Before start using this module, one should be aware of selecting the number of process.

       * It is not good  to use this module when the script runs as a server that handles the request.

For example , if you try to create 5 process from the script , for each request it will create 5 process, if 10 parallel request comes than 5 * 10 process will create, Its a kind of Fork Bomb.Server will hang.

I would suggest to use Parallel::ForkManager in a stand alone script.


Reference : 
http://search.cpan.org/~szabgab/Parallel-ForkManager-1.06/lib/Parallel/ForkManager.pm


Saturday, August 16, 2014

Perl Subroutine to get random

Generate random number with given number of digits

sub getRandomNum {
     my $count = shift;
     return  join('', map {  int(rand(9)) } (1 .. $count) );
}

Generate random word with given number of characters

sub getName{
    my $count = shift;
    return join ('',map { ('a'..'z')[rand 26] } 0 .. $count);
}

Tuesday, July 8, 2014

Audio file conversion using sox

Example : 
convert a .ulaw file to .sln16 file

Command :
sox -t ul -c 1 -r 8k  file.ulaw  -D -V0 -s -r 16k -t s2 -c 1 file.sln16

Switch : 
-t type  
-c channel
-r sample rate
-D no diether (no white noise added to source file during conversion)
-V0 verbosity level set to 0 (no error or warning messages are shown) 

Reference : 



Saturday, July 6, 2013

Develop your own android application using HTML and JavaScript.



PreRequirements :
  •   Eclipse IDE
  •   AVD 
For Linux users every things comes under one zip ,just extract to home folder is enough.  
here you can get http://developer.android.com/sdk/index.html

For Windows users may be this  http://www.youtube.com/watch?v=TTrUX1kUpDo video will help or do other searches.

Steps 

1.  Creation of project..

     In Eclipse, choose file -> new -> android app project.
     give app name and choose next
     choose icon click next and create a blank activity and choose finish..


2. Creation of html file as application..

    Assume that this html file is your application.
    just close that default opened xml file.

    create a html file inside the folder assets 
    right click on assets and choose  new -> file 
    and give file name     ex)  my_app.html

Note : open all the files using the text editor..     

     sample html file 
----------- my_app.html--------

<html>
<head>
<script language="javascript">
function modify()
{
var obj=document.getElementById("h2");
obj.innerHTML="Using Html javascript any thing is possible !";
}
</script>
</head>
<h1 >This is Android Web Application</h1>
<h2 id="h2">Is it Possible ?</h2>
<body>
<input type="button" value="Click Me" onclick="modify()"></input>
</body>
</html> 

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


3. Creation of Webview layout..

  create an xml file "webview.xml" inside the folder
                res -> layout ->webview.xml 
  right click on the layout folder and click new -> file ..

webview.xml should contains following .. just copy and paste the following 


----------- webview.html--------


<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

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

4. Modification in MainActivity.java file..

   Open the MainActivity.java file in the folder 
    src -> com.package.yourappname ->  MainActivity.java
  
    delete the @Override public boolean onCreateOptionsMenu(Menu menu) {}  method 


    import the android.webkit.WebView package..

    type the following line on the top 

        " import android.webkit.WebView; "


     create one object for the WebView class

      type the following line after this public class MainActivity extends Activity {

"  private WebView webView;  "

   inside the onCreate(Bundle savedInstanceState) method 
    set the content view to webview layout.

    modify this "setContentView(R.layout.activity_main)" line to "setContentView(R.layout.webview)" 

   and  add the following lines after the setContentView() method

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/my_app.html");  

Note: html file name should be your file name ,in my case it was my_app.html


now your MainActivity is looking like the following

----------MainActivity.java----------------

package com.example.webapplication;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;


public class MainActivity extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/my_app.html");

}


}

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

5.Modification in the AndroidManfest.xml file..

   open the AndroidManfest.xml file and add the following line between the <uses-sdk tag > and <application tag> 

 <uses-permission android:name="android.permission.INTERNET" />



6. Run the Project..

   Save all the files and 
   Right Click on the project and choose run as -> Android Application project.



References

http://developer.android.com/guide/webapps/webview.html



Monday, April 29, 2013

Linux Booting Process

1. First BIOS runs POST (Power-On Self-Test).
  • verify CPU registers
  • verify the integrity of the BIOS code itself
  • verify some basic components like DMA, timer, interrupt controller
  • find, size, and verify system main memory
  • initialize BIOS
  • pass control to other specialized BIOSes (if and when required)
  • identify, organize, and select which devices are available for booting


2. BIOS determines boot device.
If storage device like hard disk, BIOS loads "boot loader" program from MBR of hard disk In linux, typical boot loader program is "grub" (Grand Unified Boot Loader).

3. Grub further figures out how to fetch the kernel and the initrd image.

4. kernel mounts initrd to get a temporary root file system.

5. kernel is also tells where the actual root file system is (in grub config).

6. then kernel mounts root file system and runs /sbin/init (can be overridden by
passing init=/path/to/some/other/program).

7. init is the first process and it reads /etc/init/*.conf and /etc/init/rc-sysinit.conf contains runlevel information init effectively runs all executable files in /etc/rcRUNLEVEL.d/S* and stops /etc/rcRUNLEVEL.d/K*
some of these programs run by init setup various things needed by the OS, such as pseudo-tty devices, configure network, start needed daemons, etc.,

8. Thus all the services needed for OS has been started.

OS BEGINS.