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

JavaScript love calculator

Posted by midhun pottmmal On Friday, 18 January 2013 0 comments

JavaScript love calculator


Hello friends now we presenting a simple java script love calculater .Its the first tutorial that having live demo on our blog . its simple funny and use some mathematics functions ,so it will help to understand how works java script functions and button click listeners..

Live demo                                    

Love Tester

-->
+ =
Scriptime.blogspot.in


Source

function calc() {

first = document.loveform.name1.value.toUpperCase();
firstlength = document.loveform.name1.value.length;
second = document.loveform.name2.value.toUpperCase();
secondlength = document.loveform.name2.value.length;
var LoveCount=0;

for (Count=0; Count < firstlength; Count++) {
letter1=first.substring(Count,Count+1);
if (letter1=='L') LoveCount+=2; 
if (letter1=='O') LoveCount+=2; 
if (letter1=='V') LoveCount+=2; 
if (letter1=='E') LoveCount+=2; 
if (letter1=='Y') LoveCount+=3; 
if (letter1=='O') LoveCount+=1; 
if (letter1=='U') LoveCount+=3;
}

for (Count=0; Count < secondlength; Count++) {
letter2=second.substring(Count,Count+1);
if (letter2=='L') LoveCount+=2;
if (letter2=='O') LoveCount+=2; 
if (letter2=='V') LoveCount+=2; 
if (letter2=='E') LoveCount+=2;
if (letter2=='Y') LoveCount+=3;
if (letter2=='O') LoveCount+=1;
if (letter2=='U') LoveCount+=3; 
}

amount=0;
if (LoveCount> 0) amount=  5-((firstlength+secondlength)/2)
if (LoveCount> 2) amount= 10-((firstlength+secondlength)/2)
if (LoveCount> 4) amount= 20-((firstlength+secondlength)/2)
if (LoveCount> 6) amount= 30-((firstlength+secondlength)/2)
if (LoveCount> 8) amount= 40-((firstlength+secondlength)/2)
if (LoveCount>10) amount= 50-((firstlength+secondlength)/2)
if (LoveCount>12) amount= 60-((firstlength+secondlength)/2)
if (LoveCount>14) amount= 70-((firstlength+secondlength)/2)
if (LoveCount>16) amount= 80-((firstlength+secondlength)/2)
if (LoveCount>18) amount= 90-((firstlength+secondlength)/2)
if (LoveCount>20) amount=100-((firstlength+secondlength)/2)
if (LoveCount>22) amount=110-((firstlength+secondlength)/2)

if (firstlength==0 || secondlength==0) amount= "Err";
if (amount < 0) amount= 0;
if (amount >99) amount=99;

document.loveform.output.value=amount+"%";
}

Download Source

                              
READ MORE