Reading Gmail with Java IMAP

Posted by midhun pottmmal On Thursday, 10 July 2014 0 comments
Hai friends this code just a simple modification from our old post Php to java :)
" .Our new java code is simple code for loading gmail messages using IMAP. Here using java imap extension to use inbox. Before you proceding this project make sure about your imap setting in Gmail. 




import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store;
public class InboxReader {
public static void main(String args[]) {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "<username>", "password");
System.out.println(store);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message messages[] = inbox.getMessages();
for(Message message:messages) {
System.out.println(message);
}
} catch (NoSuchProviderException e) {
e.printStackTrace();
System.exit(1);
} catch (MessagingException e) {
e.printStackTrace();
System.exit(2);
}
}



READ MORE

MySQL Performance Monitor Tools

Posted by midhun pottmmal On Tuesday, 8 July 2014 0 comments


1. Mtop


mtop (MySQL top) monitors a MySQL database showing the queries which are taking the most amount of time to complete. Features include 'zooming' in on a process to show the complete query and 'explaining' the query optimizer information.


2. Innotop


Innotop can be really handy when you need a quick and easy tool that can provide a lot of details on what MySQL is doing – without using difficult queries to get those details manually. For our Percona Support customers, using Innotop will often be much easier then running complex SHOW statements and filtering their output in order to get some simple facts like slave replication lag, number of busy threads or InnoDB history list length. Also for us, Support engineers, it’s sometimes quicker to get a fast system overview with Innotop before we do deeper investigation using SHOW statements, Information_schema or more complex ways.



READ MORE

PHP Performance Test Tools

Posted by midhun pottmmal On Thursday, 3 July 2014 0 comments

PHPUnit

PHPUnit is the de-facto standard for unit testing in PHP projects. It provides both a framework that makes the writing of tests easy as well as the functionality to easily run the tests and analyse their results.

vfsStream

vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system.

Behat

Behat is a framework for Behavior Driven Development (BDD) that is inspired by Cucumber.

PHPLOC

phploc is a tool for quickly measuring the size of a PHP project.

PHP_Depend

pdepend can generate a large set of software metrics from a given code base. These values can be used to measure the quality of a software project and they help to identify the parts of an application where a code refactoring should be applied.

PHP Mess Detector

phpmd scans PHP source code and looks for potential problems such as possible bugs, dead code, suboptimal code, and overcomplicated expressions

PHP_CodeSniffer

phpcs tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

PHP Copy/Paste Detector

phpcpd is a Copy/Paste Detector (CPD) for PHP code. It scans a PHP project for duplicated code.

PHP Dead Code Detector

phpdcd is a Dead Code Detector (DCD) for PHP code. It scans a PHP project for code that is no longer used.

phpDox

phpDox is the documentation generator for PHP projects. This includes, but is not limited to, API documentation.

Jenkins PHP

The goal of the Template for Jenkins Jobs for PHP Projects is to provide a standard template for Jenkins (the leading open-source continuous integration server) jobs for PHP projects.

hhvm-wrapper

hhvm-wrapper is a convenience wrapper for HHVM's static analyzer, for instance.


READ MORE

A simple chat application using Node.js

Posted by midhun pottmmal On Monday, 21 April 2014 0 comments
     Node Js gives ability for JavaScript to write back end code .It is one of the perfect technologies for real time application .Now we discussing how to write a simple chat server ad client using node js .

Download code
       
Steps

  1. Install and setup node js
  2. Create a TCP server
  3. Create a TCP client
  Install and setup node

       First step on node is how to setup a node.js platform ,now i am only discussing on windows .node supports windows OS since 0.6 version ,for installing go to node.js website and from download tab download  http://nodejs.org/download/ windows .msi installer .After down loading run the installer and click next and install node ,it will show a conform message after it install properly 



now you installed node properly now we want to know node  is working properly or note 

   go to cmd and type node -v


Create TCP server 

   Node has a first-class HTTP server implementation in the form of a pseudo-class in http .Server, which descends from the TCP server pseudo-class in net.Server. This means that everything described in this chapter applies to the Node HTTP server as well.

  • You can create a TCP server using the net module
         




  now we just create a node js server and u can connect client through the port 4001 , using telnet

 



now these things are working proper you finished how to set up a simple TCP server using node and how to connect that TCP port using telnet


Building a simple tcp server have flowing steps

  1. Create a tcp server
  2. Accept connection
  3. Receiving client data 
  4. Collecting all the clients
  5. Broadcasting data 

            1.Create a tcp server
    
                         

            2.Accept connection


          3 Receiving client data
       
        4.Collecting all clients

     
         5. Broadcasting



These are the steps for creating tcp chat server . in this project i am attaching a full set of working TCP server and TCP client with this post .

Download code
READ MORE

How Change MySQL Root Password

Posted by midhun pottmmal On Tuesday, 19 November 2013 0 comments
Set up MySQL password is one of the important task ,Now i am showing you how set a password for your MySQL root account using command prompt  .

Steps


  1. log in MySql from cmd.
  2. Change password
  3. flush privilege

Step1

how to login mysql from cmd

Step2

changing root password



Step 3

flush previleges




READ MORE

How Create a Zip File Using PHP

Posted by midhun pottmmal On Sunday, 17 November 2013 0 comments


     Hello friends now we are going to discus a small code for creating Zip file using PHP. Creating zip file is simple as comparing with author languages.

PHP have a very useful class called ZipArchive ,To create multiple zip files in this post i will show you how create a ZIP file 





https://app.box.com/s/2zg0c554wceby2bsa2gk



Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

<?phpfunction zipFilesDownload($file_names$archive_file_name$file_path)
{
    
$zip = new ZipArchive();
  
    if (
$zip->open($archive_file_nameZIPARCHIVE::CREATE) !== TRUE) {
        exit(
"cannot open <$archive_file_name>\n");
    }
  
    foreach (
$file_names as $files) {
        
$zip->addFile($file_path $files$files);
    }
    
$zip->close();
  
    
header("Content-type: application/zip");
    
header("Content-Disposition: attachment; filename=$archive_file_name");
    
header("Pragma: no-cache");
    
header("Expires: 0");
    
readfile("$archive_file_name");
    exit;
}
$fileNames     = array('files/file1.docx',
    
'files/file1.pdf');$zip_file_name 'myFile.zip';

$file_path     dirname(__FILE__) . '/';
zipFilesDownload($fileNames$zip_file_name$file_path);
?>

 


READ MORE

zend framework for beginners Part 1

Posted by midhun pottmmal On Tuesday, 5 March 2013 0 comments


Hello friends now we are going to discuss on Zend framework, it also known as zf. This is a A to Z step by step articles on zend .this is first one so here cover on the following three basics.
  1. 1.       What is a frame work and why they need?
  2. 2.       Installing zend framework.
  3. 3.       First zend program.



What is a frame work and why they need?

Zend Framework (ZF) is a framework for PHP 5 and it is based on object-oriented paradigm. It is an open-source framework under the BSD License.  The idea of  ZF was conceptualized in the early 2005, and it was publicly announced in October 2005 at the first Zend Conference.
Like other PHP stack zend provides a PHP stack called zend server and also zend provides a IDE for ZF.

Requirements:
To run Zend 1.7.0 we need PHP 5.2.4 or latter .ZF‘s programmer’s reference says strictly 5.2.3 due to some security reasons, for unit testing it need PHP Unit 3.0 or latter
Zend framework of PHP is basically works on MVC architecture   MVC stands for Model View and Controller.
·         Model : The model part deals with the part which is concerned with the specification of the data to be displayed  Business logic part of the program is handled by this part which involves activities like load and save to databases

·         View: Responsibility of this part is to display the content of the application to the user. Usually this section contains the HTML part

·         Controller: This part combines together the specifics of model and view section and gives the assurance of displaying correct data

Installing zend framework. (with xampp )

Now we are going to install ZF framework on our local computer, initially we need to download the zend frame work from http://framework.zend.com/download. Unzip the folder into host c:\xampp\htdocs Since most of the works in ZF is done from command prompt, so we need to do some preliminary settings, so right click on the My Computer icon, select properties, select Advanced tab, click on Environment Variables, now under the System Variables select Path and click edit button, now select the c:\ xampp\htdocs \ZendFramework\bin folder




Now you want to go command prompt (WIN key + R=Run, Window=> type cmd and press enter key). Type zf show version and press enter, it should display like this.



If it works your path variables are working perfect. After that we need create a directory stretcher that helps to reduce our work load and improve readability.Now type the following command which will create the directory structure automatically

.Here we are using XAMPP so we used root folder as htdocs. After executing above comments directory structure will like blow figure.
Now type http://localhost/myfirstproject/public/ in the address bar of the browser and press return key, the output in the browser should be like this:
go to C:\xampp\htdocs\myfirstproject\application\views\scripts\index folder and in the index.phtml and change the existing code with the following:


<?php
echo "<center><b>Hello World</b></center>";
?>





save it and reload page output will as follows
In the next applications we will learn a how connect DB using Zend. plz read some other articles and give some reviews about my personal programming blog.



READ MORE

JDBC Connection Part 1

Posted by midhun pottmmal On Saturday, 23 February 2013 0 comments

JDBC Connection


Hello friends now we are going to discuss about Java Data Base Connectivity. We heard connecting Java and DB are so difficult, etc. and blab bla bla …… :) We are going to show you much easy it is. Only want to follow some regular steps.

JDBC is application programing interface .that allow programmers to access Data Base Systems from java code .it allows to execute SQL queries on java program.it helps programmers to connect, send receive data from DB.

JDBC uses application programing technology for driver manager and Data Base specific drivers, for providing transparency and concurrency to heterogeneous Data Bases. Creating JDBC programs understanding its architecture make easier.

JDBC have layered Architecture.




When using JDBC we can follow following steps.

1.      Loading JDBC driver.
2.      Establishing connection.
3.      Executing SQL statements.
4.      Getting result.
5.      Closing connection.



There is an interface in  java.sql package that specifies connection with specific database called connection 


 Connection conn = null;
DriverManager:

It is a class of java.sql package that controls a set of JDBC drivers. Each driver has to be register with this class.

getConnection(String url, String userName, String password):

This method establishes a connection to specified database url. It takes three string types of arguments like: 

    url: - Database url where stored or created your database
    userName: - User name of MySQL
    password: -Password of MySQL 

con.close():

This method is used for disconnecting the connection. It frees all the resources occupied by the database.



SOURCE CODE.
import java.sql.*;

public class MysqlConnect{
  public static void main(String[] args) {
  System.out.println("MySQL Connect Example.");
  Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "jdbctutorial";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"
  String password = "root";
  try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  System.out.println("Connected to the database");
  conn.close();
  System.out.println("Disconnected from database");
  catch (Exception e) {
  e.printStackTrace();
  }
  }
}

READ MORE

Password strength meter

Posted by midhun pottmmal On Tuesday, 5 February 2013 0 comments

Password strength meter 

 Here we indrodusing a simple password strength meter,it measure of the effectiveness of a password in resisting guessing and brute-force attacks. In its usual form, it estimates how many trials an attacker who does not have direct access to the password would need, on average, to guess it correctly. The strength of a password is a function of length, complexity, and unpredictability


    




  Download Script                  Live Demo

HTML Code



<form name=df style='margin:0px;'>
<p class="border">
Enter Password .
<input type=password length=20 name='pwd' style="text-decoration:none;color: #dddd;"onkeyup='CheckPasswordStrength(this.value);'>
</p><div id='pwd_strength'></div>
</br>
</form>


JavaScript Code



<script type="text/javascript">

var pass_strength;

function IsEnoughLength(str,length)
{
 if ((str == null) || isNaN(length))
  return false;
 else if (str.length < length)
  return false;
 return true;
 
}

function HasMixedCase(passwd)
{
 if(passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))
  return true;
 else
  return false;
}

function HasNumeral(passwd)
{
 if(passwd.match(/[0-9]/))
  return true;
 else
  return false;
}

function HasSpecialChars(passwd)
{
 if(passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))
  return true;
 else
  return false;
}


function CheckPasswordStrength(pwd)
{
 if (IsEnoughLength(pwd,14) && HasMixedCase(pwd) && HasNumeral(pwd) && HasSpecialChars(pwd))
  pass_strength = "<b><font style='color:olive'>Very strong</font></b>";
 else if (IsEnoughLength(pwd,8) && HasMixedCase(pwd) && (HasNumeral(pwd) || HasSpecialChars(pwd)))
  pass_strength = "<b><font style='color:Blue'>Strong</font></b>";
 else if (IsEnoughLength(pwd,8) && HasNumeral(pwd))
  pass_strength = "<b><font style='color:Green'>Good</font></b>";
 else
  pass_strength = "<b><font style='color:red'>Weak</font></b>";

 document.getElementById('pwd_strength').innerHTML = pass_strength;
}
function ctck()
{
     var sds = document.getElementById("dum");
     if(sds == null){
        alert("You are using a free package.\n You are not allowed to remove the tag.\n");
     }
     var sdss = document.getElementById("dumdiv");
     if(sdss == null){
         alert("You are using a free package.\n You are not allowed to remove the tag.\n");
     }
}
document.onload ="ctck()";
</script>



Don't Forget To Comment ...!
scriptime.blogspot.in
READ MORE

JavaScript Embedding YouTube videos from links

Posted by midhun pottmmal On Wednesday, 23 January 2013 0 comments

JavaScript Embedding YouTube videos from links

Embedding video to a webpage make a real change in the early day’s web. It  can make a multimedia interaction with web user and author .so feel of that website become more realistic .most of users have broadband connection so they are flexible with video contents .one of the most  common used method  is  using a flash player and flv videos those hosted in an external server ,like YouTube .
Embedding YouTube

Code

 function linkToYoutube(link, ops) {
         var o = $.extend({
         width: 480,
         height: 320,
         params: ''
         }, ops);
  
          var id = /\?v\=(\w+)/.exec(link)[1];

          return '<iframe style="display: block;"'+
         ' class="youtube-video" type="text/html"'+
         ' width="' + o.width + '" height="' + o.height +
         ' "src="http://www.youtube.com/embed/' + id + '?' + o.params +
          '&amp;wmode=transparent" frameborder="0" />';
         }

      $('a').each(function(){
      var link = $(this).attr('href');
     $(this).html( linkToYoutube(link, { params: 'theme=light' }) );
    })

Download & Live Code Edit

READ MORE

Password Hashes in PHP

Posted by midhun pottmmal On Sunday, 20 January 2013 0 comments

Password Hashes in PHP

Hello friends now we are discussing about some simple security tricks in php, mainly on handling passwords using php. This section explains why password hashing and how can we use hashing.




Why

Every god programmer’s know storing password in form of clear text is bad method of programing .this make user and programmer at risk. This is the main reason why password hashing is used .password hashing are working on the basics of cryptography.
In cryptography, a cryptographic hash function is a transformation that takes an input and   returns a fixed-size string, which is called the hash value.”
                                                                                                                                                Wikipedia
By applying hashing algorithm’s they make user’s password’s strong.it make difficult to Attackers. PHP offers so simple inbuilt methods to create hashes, such as md5 (), sh1 (), ssha () etc.


                  

How hashing in PHP

  
There are different algorithm’s for creating a hash of a test most popular are md5() and sha()now we disusing about those two first.
                       
             <?php
                $str = "Hello";
                echo md5($str);
             ?>
 The output of the code above will be:

                    8b1a9953c4611296a827abf8c47804d7 

             <?php
                $str = 'Hello';
                 echo sha1($str);
              ?> 
 The output of the code above will be:

                  f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0

In the above example md5 can create a 128 bit of hash from given text, and second one is sha1. It can make 160 bit hash from given password text. But md5 and sha algorithms can decrypt easly with help of rainbow tables.so we need to use next level algorithms.


   
READ MORE