Thursday, August 29, 2013

Checking characters in textfield in jsf with ajax

One of the cool features of JSF is its easier and simpler handling of Ajax. Oh yes have a look.
Suppose I want to check the length of the characters entered in the textfield live using jsf.


Using the following codes:

Finally we have
As an image is worth thousands words. No more comments.
Just rock !!!

Thursday, August 22, 2013

It is all about Big Data


1.   Introduction
Tim O’Reilly, by declaring in his famous article “What is Web 2.0” that “data is the next Intel Inside” made indeed a visionary declaration for data revolution. However creating intelligent values from Big Data cannot be accomplished by just aggregating large amounts of data or performing analysis. The necessity to make sense and maximize utilization of such vast amounts of data for knowledge discovery and decision-making is crucial to scientific advancement. This has led to some recent initiatives in both theory and practice in order to find some techniques to handle Big Data challenges.

2.   Research direction
Some of the active areas of research under Big Data are:
§      Text- and data-mining of historical and archival material.
§      Social media analysis, including sentiment analysis
§       Knowledge Mapping from Big Data Sources
§      Crowd-sourcing and big data
§      Privacy Preserving Big Data Collection / Analytics
§      Relationship between ‘small data’ and big data
§      NoSQL databases and their application
§      Big data and the construction of memory and identity
§      Big data and archival practice
§      Construction of big data
§      Big data in Heritage
§      Etc…

3.   Challenges
As pointed out in [1, 2, 3], applying Big Data analytics to the field of development faces several challenges. Some challenges relate to the data including its acquisition and sharing and overarching concern over privacy, and others pertain to its analysis. Privacy is the most sensitive issue, with conceptual, legal, and technological implications. Access and sharing are not the least given the reluctance of private companies and other institutions to share data about their clients and users, as well as about their own operations. Obstacles may include legal or reputational considerations, a need to protect their competitiveness, a culture of secrecy, and, more broadly, the absence of the right incentive and information structures. There are also institutional and technical challenges—when data is stored in places and ways that make it difficult to be accessed, transferred, etc.  Another key challenge is the analysis itself.  Working with new data sources brings about a number of analytical challenges. The relevance and severity of those challenges will vary depending on the type of analysis being conducted, and on the type of decisions that the data might eventually inform. The analysis challenge can be splitted into three distinct categories: (1) getting the picture right, i.e. summarizing the data (2) interpreting, or making sense of the data through inferences, and (3) defining and detecting anomalies.

4.   Applications
Big Data holds a tremendous wealth of information and, like nanotechnology and quantum computing, it will shape the twenty-first century with highly promising applications. As presented in [1, 3], Big Data if properly analyzed can offer the opportunity for an improved understanding of human behavior that can support the field of global development in three main ways:
  a) Early warning: early detection of anomalies in how populations use digital devices and services can enable faster response in times of crisis;
  b) Real-time awareness: Big Data can paint a fine-grained and current representation of reality which can inform the design and targeting of programs and policies;
  c) Real-time feedback: the ability to monitor a population in real time makes it possible to understand where policies and programs are failing and make the necessary adjustments.

5.   Conclusion
Despite the overwhelming challenges Big Data present potential growing applications and concerns ranging from government, industries to academia as illustrated in [2, 3].  Therefore the aim of this article has been to present some potential research directives on Big Data as well as its challenges and potential applications.

References:

[1] “Big Data for Development: Challenges and Opportunities”, Global Pulse, May 2012

[2] “Big data in canada: challenging complacency for competitive advantage”. Nigel Wallis, December 2012.

[3]  "Algorithm and approaches to handle large Data- A Survey", Chanchal Yadav, Shuliang Wang ,Manoj Kumar, IJCSN, Vol 2, Issue 3, 2013.

Wednesday, August 21, 2013

Store and Retrieve image from a directory using php: Part 2

 Store and Retrieve image from a directory using php: Part2

Hi !,
This is the continuation of part 1.

Create an  empty folder: upload


Create a file: upload_file_save.php 

<?php
 include 'db.inc';
 
 if (!($connection = @ mysql_pconnect($hostName,$username,$password)))
        showerror();

 if (!mysql_select_db("your dbase name", $connection))
        showerror();
        
        
        
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
//getting the prefix
$prefix=$temp[0];

//getting the extension
$picextenstion=$temp[1];

//checking
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Prefix name: " . $prefix . "<br>";
    echo "Extension: " . $picextenstion . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
    

    // Re-Check connection
         if (mysqli_connect_errno($connection))
           {
             echo "Failed to connect to MySQL: " . mysqli_connect_error();
           }
         else
           {
           echo '<br> Successfully connected';

           }
          
          
      //getting the id
       $sqlid = "SELECT testid FROM testimonial ORDER BY testid DESC LIMIT 1";
       $result = mysql_query($sqlid);
       while ($getid = mysql_fetch_array($result)){
        $newid = $getid['testid'] + 1;
       }
    
    
    if (file_exists("upload/" . $newid.'.'.$picextenstion))
      {
      echo $newid.'.'.$picextenstion . " already exists. ";
      }
    else
      {
     
      //moving to the right directory
          move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $newid.'.'.$picextenstion);
      echo "\nStored in: " . "upload/" . $newid.'.'.$picextenstion;
      
       //Saving to the database.
       
       $persname=$_POST["persname"];
       $country=$_POST["country"];
       $department=$_POST["department"];
       $message=$_POST["message"];
       $picsmane=$newid.'.'.$picextenstion;

      
       echo '<br> lastest id '.$newid.'<br> ';
       
      //query
      $sql="INSERT INTO testimonial (pers_name, country, department, message, pics_name)
          VALUES ('$persname', '$country','$department','$message','$picsmane')";
          
      // Inserting into the database
        
        
         $retval = mysql_query( $sql, $connection );
        if(! $retval )
         {
           ('Could not enter data: ' . mysql_error($connection));
          }
         echo  mysql_affected_rows()." picture successfully added\n";
         echo '<a href="view.php">View the lastest picture</a><br> ';
        

          mysql_close($connection);
      
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

Create a file: view.php
<?php
 include 'db.inc';

 if (!($connection = @ mysql_pconnect($hostName,$username,$password)))
        showerror();

 if (!mysql_select_db("testi", $connection))
        showerror();
?>
<html>
<body>

 <table>

  <?php
 
 $sql= "SELECT * FROM testimonial ORDER BY testid DESC ";
 $query = mysql_query($sql, $connection );
 ?>

<?php
 while($row = mysql_fetch_array($query)){
?>
 <tr>
 <td>
 <label for="">ID: </label>
 </td>
 <td><?php echo $row['testid']; ?></td>
 </tr>
 <tr>
 <td>
 <label for="">Name</label>
 </td>
 <td><?php echo $row['pers_name']; ?></td>
 </tr>
 <tr>
 <td>
 <label for="">Picture</label>
 </td>
 <td><img height='100' width='200' src=" <?php echo 'upload/'.$row['pics_name'];?>"/></td>
 </tr>
<?php
 }
 ?>



 </table>
<?php
 echo '<br> <a href="index.php">Enter another picture</a><br> ';
 ?>
</body>
</html>

After this point your will have the following files.

store and retrieve image from a directory using php : part 1

Store and Retrieve image from a directory using php: Part 1

If you are having trouble with the manipulation of image in php these series of tutorials are for you.
I have noticed that many people are having problem with this operation in php.

Please I hate long speeches , lets go straight to the point.

In this tutorial you will store user information in the database and the picture of user in a directory and load the information.

Mysql table:

CREATE TABLE IF NOT EXISTS `testimonial` (
  `testid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `pers_name` varchar(50) NOT NULL,
  `country` varchar(25) NOT NULL,
  `department` varchar(5) NOT NULL,
  `message` text NOT NULL,
  `pics_name` varchar(20) NOT NULL,
  PRIMARY KEY (`testid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;
 Create a file: db.inc

<?php

// Mysql configurations

$hostName = "localhost";
$username = "root";
$password = "";

// Show an error and stop the script
function showerror()
{
   if (mysql_error())
      die("Error " . mysql_errno() . " : " . mysql_error());
   else
      die("Could not connect to mysql");
}


?>
Create a file: index.php

<html>
<body>

 <table>
 <tr>
 <form action="upload_file_save.php" method="post" enctype="multipart/form-data">
 </tr>
 <tr>
 <td>
 <label for="file">Filename:</label>
 </td>
 <td>
 <input type="file" name="file" id="file"><br>
 </td>
 </tr>
  <tr>
 <td>
 <label for="persname">Student Name:</label>
 </td>
 <td>
 <input type="text" name="persname">
 </td>
 </tr>
 <tr>
 <td>
 <label for="country">Country Name:</label>
 </td>
 <td>
 <input type="text" name="country">
 </td>
 </tr>
 <tr>
 <td>
 <label for="department">Department:</label>
 </td>
 <td>
 <input type="text" name="department">
 </td>
 </tr>
 <tr>
 <td>
 <label for="message">Message:</label>
 </td>
 <td>
 <textarea cols="40" rows="5" name="message">Write something here</textarea>
 </td>
 </tr>
 <tr>
  <td>
<input type="submit" name="submit" value="Submit">
</td>
<tr>
</form>
</table>
<?php echo '<a href="view.php">View all the picture </a><br> '; ?>
</body>
</html>

I stop here, please read the next part 2.

Monday, August 19, 2013

PDF report generation in java

The most common challenges faced by java programmers is handling report. Don't worry there are pretty wonderful tools and packages out there for you ready to be used. But it important to choose the right tool. Choosing the right tool preventing you from tedious and useless learning curve.
 From my little experience i will suggest you four ones: JASPER IREPORT, BIRT REPORT, PENTAHO REPERT and ITEXT.

  1.  Jasper ireport : it is my best preference. If you are using netbeans please don't think twice it will a perfect match. Ease to use like netbeans, drag and drop, tons of tutorial , dynamic community, report available in many format like pdf, xls , html, ppt, doc , etc. and more cool feature.
  2. BIRT report from IBM is cool trust me. If you use eclispse as IDE i strongly recommend you to go with Birt. 
  3. PENTAHO is another good tool but I have not got the chance to develop a full application with it except exploring but it is worth giving it a try.
  4. ITEXT oh yes if you are a coder how like to do it yourself, this package is for you. You have to build everything from scratch.  I remembered to have burnt my fingers during my undergraduate project when I was still arrogant and willing to do it all from level zero.
I hope this little post will help you to make the right choice for your next java project and save TIME.
When coding becomes fun !

How to view the LAN on linux ?

Usually newbies or newcomers tend to have problems viewing the local area network once they have completed their linux installation. If you are sure that the physical connection is done and working properly, you may check the LISA daemon. Lisa is the background process or system service that allow you to view the LAN.

Accessed from :

System Settings -> Server Settings -> Services
 

Switching between the Terminal and GUI in linux

One of the advantage of using Linux is the ability to switch bet the full screen terminal and the graphical user interface GUI. If you are using  Red Hat , fedora or other related distribution you can do this by:
  • CRLT + ALT + Fn , where n= 1,2,3,4,5,6 to navigate between the 6 different terminal sessions.
  • CRTL + ALT + F7  to return to the graphical user interface.

Friday, August 16, 2013

Rethinking the way we approach software engineering

Either your are a manager or an IT geeks, and have not heard about BPR or Business Process Reengineering please stop. Even  if you don't have time, at least google it and give it only five minutes. If you can manage and short tutorial, an ebook or attending a course or seminar on this topic, it it will be great believe me.
              During our formal education especially for those who have done their undergraduate in Computer science when we you ask them about software development; they will directly refers to programming languages, system analysis and design, software engineering , UML and more. That fine but the truth is that this mechanical approach to Software development is not always practical and productive.
               Many of those who have got the chance to develop applications and interacting directly with customers will just agree with me how much they have been disappointed. They have faced tremendous challenges. But what is the problem ?
  Software is not always about JAVA, ORACLE, .NET and so on.

 Do you know you have to deal with people ?
Are you able to conceptualize the whole operation of the organization ?
Are you  able to identify different work processes ?
 What is a Work process ? What do the client want ?
 Is your application able to  add any business value ?
 How can you evaluate that ? So many questions and simple answer is BPR ?

Please my phone is ringing, I will be back soon.