Saturday, June 15, 2013

Facebook like button in blogger

Following are the steps to add facebook like button for each post in your blog.

Step-1: First of all, I recommend you to take backup of your current template to avoid any loss.

Step-2: For backup, go to your Blogger dashboard, click on template and then click on Backup/Restore on top-right side. Click on download full template and save it to your computer.

Step-3: After backup, go to edit HTML and find <data:post.body/> using CTRL+F, if it is more than one then try to finding last one.

Step-4: Copy and Paste the code given below just after the <data:post.body/> and save the template.

<div class="facebooklike">
    <iframe expr:src='"http://www.facebook.com/plugins/like.php?href=" + data:post.url +"&layout=button_count&show_faces=false&width=100& action=like&font=arial&colorscheme=light"' frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:100px; height:25px;' allowTransparency='true' />
</div> 


Step-5: Go to browser and view your blog, you can see that facebook like button for each post of your blog.

Wednesday, June 12, 2013

Amazon Tips and Tricks

Getting PHP and MySQL running on amazon EC2

http://www.alexkorn.com/blog/2011/03/getting-php-mysql-running-amazon-ec2/#note1back 



How to run PHP site using EC2 and S3

You need to start a new EC2 instance with a image (AMI) that contains the minimal configuration you need. You can use the Amazon Linux images which has nothing on it and install Apache and PHP or try to find a community image that already contains Apache and PHP.

Afterwards install your PHP application in the relevant places in the instance.

Create an S3 bucket.
Copy your static files (images, css, javascripts) to the bucket.

Update the references to images, css, js files in your code to point to the S3 bucket.

If you are not doing anything too fancy with your Javascript code they will run correctly even from S3.




To Launce an instance

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html?r=1874



Create database in amazon EC2 


Since you have an account with Amazon and EC2, you can use their console:https://console.aws.amazon.com/ec2/home.
In the console, click on Instances, then Launch Instance to create a new virtual machine. There are lots of operating systems to choose from; a good choice for a first instance would be 32-bit Ubuntu running on an m1.small instance.
If you already have a Keypair, select the one you want from the list. Otherwise, you can create a new Keypair in the Keypair dialog. When the new instance has been created, you can use the keypair to connect to it, using a command like:
ssh -i siva_keypair root@InstancePublicDNS
You can get the instance public DNS name from the console. At this point, you're basically logged on to a new machine, and can use it in any way you would use a real, physical machine.
By the sound of it, you're going to want to create some user accounts, install an FTP server and MySQL (use apt-get if you're on Ubuntu).
Note that you can lose data which you put on the local disk if an instance goes down - if you're running a database you should use EBS which is very easy to set up, and gets you persistent, fast storage which can be attached to any EC2 instance.



Load Data into Tables Using the AWS SDK for PHP



how to view php, mysql, apache2 install or not 
  • which php return /usr/bin/php
  • which mysql return /usr/bin/mysql
  • which apache2 return /usr/sbin/apache2

loginto mysql
  • mysql -u username -p

show databases

apache2 error log
  • /var/log/apache2

restart services command
  • sudo service mysql restart
get which service run in 80 port
  • sudo lsof -i:80



php setup in amazon nginx server

phpmyadmin setup in amazon nginx server


defult setting file in nginx server path
  • /etc/nginx/sites-available
Install smtp
  • sudo apt-get install sendmail



how to add cron-job in ubuntu

cron job log
  • /var/log/syslog 



How to connect amazon server using FTP
  • Open FileZilla and go to preferences.
  • Under preferences click sftp and add a new key. This is your key pair for your ec2 instance. You will have to convert it to the format FileZilla uses. It will give you a prompt for the file format conversion.
  • Click okay and go back to site manager
  • In site manager enter in your EC2 public address, this can also be your elastic IP
  • Make sure the protocol is set to SFTP
  • Write in the username its the name of ec2-user
  • Remove everything from the password field - leave it blank
  • All done! Now connect.

Tuesday, June 11, 2013

Find Prime numbers between given range

Question: We have to ask user to enter number1 and number2 he/she wants, and find the prime numbers between that range which is entered by users?

Answer: Copy the below code and paste it into "your.php" file. After done this you will just need to run "your.php" file in browser and you will get the output successfully.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Find Prime numbers</title>
    </head>

    <body>
        <h1><center>Find Prime numbers</center></h1>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">
            Enter Value1:<input type="text" name="min">
            Enter Value2:<input type="text" name="max">
            <input type="submit" name="submit" value="OK">
        </form>

        <?php
        if (isset($_POST['submit'])) {
            $min = $_POST['min'];
            $max = $_POST['max'];
            if ($min == $max) {
                echo "Enter different value ";
            } else {
                if ($min > $max) {
                    $t = $min;
                    $min = $max;
                    $max = $t;
                }

                function get_prime($min, $max) {
                    $primes = array();
                    for ($x = $min; $x <= $max; $x++) {
                        if ($x == 2) {
                            $primes[] = $x;
                        }
                        for ($i = 2; $i < $x; $i++) {
                            $r = $x % $i;
                            if ($r == 0) {
                                break;
                            }
                            if ($i == $x - 1) {
                                $primes[] = $x;
                            }
                        }
                    }
                    if ($primes == NULL) {
                        echo "No prime numbers found";
                    }  else {
                        echo "Total ". count($primes) ." prime numbers:";
                        echo implode(",", $primes);
                    }
                    
                }

                get_prime($min, $max);
            }
        }
        ?>

    </body>
</html>

Monday, June 10, 2013

Prime number program

Question: We have to ask user to enter number he/she wants, and give output whether its prime number or not?

Answer: Copy the below code and paste it into "your.php" file. After done this you will just need to run "your.php" file in browser and you will get the output successfully.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Prime number</title>
    </head>

    <body>
        <h1><center>Prime number</center></h1>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            Enter number:
            <input type="text" name="num" />
            <input type="submit" name="submit" value="OK" />
        </form>

        <?php
        if (isset($_POST['submit'])) {
            $num = $_POST['num'];
            if ($num == 0) {
                echo $num . " is special number";
            } elseif ($num == 1) {
                echo $num . " is special number";
            } else {
                $c = 0;
                for ($i = 2; $i < $num; $i++) {
                    if ($num % $i == 0) {
                        $c++;
                        break;
                    }
                }
                if ($c) {
                    echo $num . " is not prime number";
                }
                else
                    echo $num . " is prime number";
            }
        }
        ?>
    </body>
</html>

Friday, June 7, 2013

Leap year program

Question: We have to ask user to enter year he/she wants, and give output whether its leap year or not?

Answer: Copy the below code and paste it into "your.php" file. After done this you will just need to run "your.php" file in browser and you will get the output successfully.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>leap year</title>
    </head>

    <body>
        <h1><center>leap year</center></h1>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            Enter the year in four digit:
            <input type="text" name="year" />
            <input type="submit" name="submit" value="OK" />
        </form>
        <?php
            if (isset($_POST['submit'])) {
                $yr = $_POST['year'];
                if ($yr % 4 == 0) {
                    if ($yr % 100 == 0) {
                        if ($yr % 400 == 0) {
                            echo $yr . " is leap year";
                        }
                        else
                            echo $yr . " is not leap year";
                    }
                    else
                        echo $yr . " is leap year";
                }
                else
                    echo $yr . " is not leap year";
            }
        ?>
    </body>
</html>

Tuesday, June 4, 2013

Palindrome number or string

Question: We have to ask user to enter number or string he/she wants, and give output is number/string Palindrome or not?
(abcba-Palindrome String)
(abccba-Palindrome String)
(12321-Palindrome Number)
(123321-Palindrome Number)

Answer: Copy the below code and paste it into "your.php" file. After done this you will just need to run "your.php" file in browser and you will get the output successfully.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Palindrome number or string</title>
    </head>

    <body>
        <h1><center>Palindrome number or string</center></h1>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            Enter number or string:<input type="text" name="num"/>
            <input type="submit" name="submit" value="OK" />
        </form>
        <?php
        if (isset($_POST['submit'])) {
            $num = $_POST['num'];
            $numeric = is_numeric($num);

            function is_palindrome(&$str) {
                for ($i = 0; $i < strlen($str) / 2; $i++) {
                    if ($str[$i] != $str[strlen($str) - 1 - $i])
                        return false;
                }
                return true;
            }

            if (!$numeric) {
                $result = is_palindrome($num);
                if ($result) {
                    echo $num . " is palindrome string";
                }
                else
                    echo $num . " is not palindrome string";
            } else {
                $sum = 0;
                $temp = $num;
                while ($temp >= 1) {
                    $r = $temp % 10;
                    $temp = $temp / 10;
                    $sum = $sum * 10 + $r;
                }

                if ($sum == $num) {
                    echo $num . " is palindrome number";
                }
                else
                    echo $num . " is not palindrome number";
            }
        }
        ?>
    </body>
</html>

Monday, June 3, 2013

Reverse number

Question: We have to ask user to enter number he/she wants, and number should be generated reverse accordingly.
(if user enter number 12345 then reverse should be generated i.e.- 54321)

Answer: Copy the below code and paste it into "your.php" file. After done this you will just need to run "your.php" file in browser and you will get the output successfully.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Reverse number</title>
    </head>

    <body>
        <h1><center>Reverse number</center></h1>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            Enter number more than one digit:<input type="text" name="rev" />
            <input type="submit" name="submit" value="OK" />
        </form>
        <?php
            if (isset($_POST['submit'])) {
                $rev = $_POST['rev'];
                while ($rev >= 1) {
                    $r = $rev % 10;

                    $rev = $rev / 10;

                    echo $r;
                }
            }
        ?>
    </body>
</html>

Sunday, June 2, 2013

Fibonacci Series

Question: We have to ask user to enter the no. of terms he/she wants, and series should be generated accordingly.

Answer: Copy the below code and paste it into "your.php" file. After done this you will just need to run "your.php" file in browser and you will get the output successfully.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Fibonancy series</title>
    </head>
    <body>
        <h1><center>Fibonancy series</center></h1>
        <?php
            $a = 0;
            $b = 1;
            $sum = 0;
        ?>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">
            Enter number of terms:<input type="text" name="name">
            <input type="submit" name="submit" value="OK"><br>
        </form>
        <?php
            if (isset($_POST['submit'])) {
                $term = $_POST['name'];
                echo "$a,$b,";
                while ($term - 2) {
                    $sum = $a + $b;
                    $a = $b;
                    $b = $sum;
                    $term--;
                    echo $sum . ",";
                }
            }
        ?>
    </body>
</html>

Saturday, June 1, 2013

Ubuntu Tips and Tricks











change apache phpmyadmin password


mysql -h your_host(localhost) -u root

SET PASSWORD FOR root@localhost = PASSWORD('yourpassword');




rabbitvcs for gui base svn in ubuntu
http://www.webupd8.org/2011/01/rabbitvcs-perfect-tortoisesvn.html
sudo add-apt-repository ppa:rabbitvcs/ppa && sudo apt-get update
sudo apt-get install rabbitvcs-core rabbitvcs-nautilus3 rabbitvcs-cli
sudo apt-get install rabbitvcs-gedit
gconftool-2 --set /desktop/gnome/interface/menus_have_icons --type bool true


uninstall rabbitvcs from ubuntu

sudo apt-get purge rabbitvcs-cli rabbitvcs-core rabbitvcs-gedit rabbitvcs-nautilus





Install taskbar cairo dock like mac
sudo add-apt-repository ppa:cairo-dock-team/ppa
sudo apt-get update
sudo apt-get install cairo-dock cairo-dock-plug-ins





install netbeans 7.2.1 with php and install java environment
http://technicalworldforyou.blogspot.in/2012/08/how-to-install-netbeans-ide-in-ubuntu.html





ubuntu speed up with preload
http://techhamlet.com/2012/12/linux-preload/
sudo apt-get install preload





install pidgin for lan chat and other chat
http://www.itworld.com/software/304624/install-pidgin-instant-messaging-client-ubuntu-1210
sudo add-apt-repository ppa:pidgin-developers/ppa
sudo apt-get update
sudo apt-get install pidgin pidgin-data pidgin-plugin-pack pidgin-themes
sudo apt-get install pidgin-lastfm pidgin-guifications msn-pecan pidgin-musictracker









Install wine for exe file
http://www.noobslab.com/2012/08/install-wine-1511-in-ubuntu.html
sudo add-apt-repository ppa:ubuntu-wine/ppa
sudo apt-get update
sudo apt-get install wine1.5
sudo apt-get install winetricks










sudo apt-get purge google-chrome-stable






Install filezilla
sudo add-apt-repository ppa:n-muench/programs-ppa
sudo apt-get update
sudo apt-get install filezilla









changing hostname in ubuntu
http://www.tech-recipes.com/rx/2732/ubuntu_how_to_change_computer_name/
also change the file /etc/hosts with the ip address to point to the hostname





changes for php.ini present under
(error reporting, display errors, max_upload_file, max_post_size)
 /etc/php5/apache/php.ini





allowing users without password to login into phpmyadmin
(comment out  $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;)
/etc/phpmyadmin/config.inc.php





for .htaccess rules (set AllowOverride All)
/etc/apache2/sites-available/default
also allow the use of url rewriting module in apache through command
sudo a2enmod rewrite













changing permission of a folder to current user
sudo chown -R $USER [directory or file name]
sudo chmod -R 755[directory or file name]





restart apache service
http://www.cyberciti.biz/faq/ubuntu-linux-start-restart-stop-apache-web-server/
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 stop


restart mysql
sudo service mysql restart





ROR mysql configuration for socket (symbolic linkage)
http://www.davideisinger.com/article/getting-started-with-ubuntu





install php curl
sudo apt-get install php5-curl




lamp start on boot system
http://www.linuxhomenetworking.com/forums/showthread.php/18872-start-LAMP
sudo vi /etc/init.d/rc.local
/opt/lampp/lampp start




play playonlinux(install windows s/w)
sudo apt-get install playonlinux




install httrack s/w for offline donwload website
sudo add-apt-repository ppa:upubuntu-com/web
sudo apt-get update
sudo apt-get install webhttrack httrack






install java in ubuntu


sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer





install ubuntuTweak 0.8.2


sudo add-apt-repository ppa:tualatrix/ppa

sudo apt-get update

sudo apt-get install ubuntu-tweak



when ubuntu not boot