Saturday 19 May 2012

Make bootable pendrive for ubuntu(in windows platform)


It is very easy.
First download Universal-USB-Installer.
Just fix the locations of pendrive and ISO image.
Click create button.
That's it.

Download Universal- USB-Installer from here
                                                                            

Thursday 17 May 2012

A method to make one click buttons in php

Here is a method to make buttons which will disabled automatically after click. This is useful when you dealing with php scripts.There also other methods for this. Here is only the logic not complete code.

<?php
mysql_select_db("sample", $p);
$z1=$z2=0;
$r=mysql_query("SELECT * FROM sampletable");

while($rows=mysql_fetch_array($r))
{
$take=$rows['samples2'];


if($take=='a1')
$z1=1;
if($take=='a2')
$z2=1;
}

if($z1==1)
echo "<input type='submit' value='a1'  name='opt' disabled >";
else
echo "<input type='submit' value='a1'  name='opt' >";




if($z2==1)
echo "<input type='submit' value='a2'  name='opt' disabled >";
else
echo "<input type='submit' value='a2'  name='opt'>";


mysql_close($p);

?>







Validation of name fields using javascipt

The following code can be used for validating name like fields.(Useful when dealing with html forms)

This code uses two built in functions
1)charAt()
2) indexOf()

charAt()- Returns the character at the specified index in a string.

Ex: charAt(5)-->  character at 6th position(Starting with 0)

indexOf() - Returns the position of the first occurrence of a specified value in a string and return -1  if  not found.


Bellow code has a variable not_needed. You can simply specify the unwanted character inside the double quotes.


<script type="text/javascript">

function validate()
{
var not_needed = "!@#$%^&*()+=-[]\\\';,./{}|\":<>? 1234567890";


if(document.myform.name1.value =="")
{
alert("Invalid name");
return false;
}

for (var i = 0; i < document.myform.name1.value.length; i++)
{
  if (not_needed.indexOf(document.myform.name1.value.charAt(i)) != -1)
 {
  alert ("Invalid name");
  return false;
  }
}
}
</script>
Form

<form action="sample.php" name="myform" method="post" onsubmit="return validate()">
Name:  <input type="TEXT" name="name1">



Wednesday 2 May 2012

Sorting of matrix elements-C++ program


#include<iostream>
using namespace std;
#include<conio.h>
int main()
{
    int a[20][20],n,b[20],m,i,j,k=0,t;
    cout<<"Enter the order\n";
    cin>>m>>n;
    cout<<"Enter the elements\n";
    for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
    {
    cin>>a[i][j];
    b[k++]=a[i][j];
     }
     }
     for(i=0;i<(m*n);i++)
     {
     t=b[i];
     j=i;
     while(j>0 && b[j-1]>=t)
     {
               b[j]=b[j-1];
               j--;
               }
               b[j]=t;
               }
             
               cout<<"\n";
               cout<<"Before sorting\n";
               for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
   
    cout<<a[i][j]<<"\t";
    cout<<"\n";
}
               cout<<"After sorting\n";
               k=0;
    for(i=0;i<m;i++)
   
    for(j=0;j<n;j++)
   
    a[i][j]=b[k++];
   
   
    for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
   
    cout<<a[i][j]<<"\t";

cout<<"\n";
}

    getch();
}





Sample Output
Enter the order
 3 3
9
8
7
4
5
2
1
3
6
Before sorting
9   8   7
4   5   2
1   3   6
After sorting
1   2   3
4   5   6
7   8   9



No third variables and pointers-C++ swapping program


#include<iostream>
using namespace std;
#include<conio.h>
int main()
{
    int a,b;
    cout<<"Enter two number:\t";
    cin>>a>>b;
    cout<<"\nBefore swapping:\t";
    cout<<a<<"\t"<<b;
   
    a=a+b;
    b=a-b;
    a=a-b;
    cout<<"\nAfter swapping:\t";
    cout<<"\t"<<a<<"\t"<<b;
    getch();
}

Twitter Delicious Facebook Digg Stumbleupon Favorites More