Saturday, October 19, 2013

jQuery interview questions and answers



Questions 1: When Jquery founded and by whome?
Answers 1: It was released in January 2006 at BarCamp NYC by John Resig
(Jquery founder).


Questions 2: What is jQuery?
Answers 2: jQuery is fast, lightweight and feature-rich client side JavaScript 
Library/Framework which helps in to traverse HTML DOM, make animations, 
add Ajax interaction, manipulate the page content, change the style and provide 
cool UI effect. It is one of the most popular client side library and as per 
a survey it runs on every second website.


Questions 3: Why do we use jQuery?
Answers 3: 
Easy to use and learn.
Easily expandable.
Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
Easy to use for DOM manipulation and traversal.
Large pool of built in methods.
AJAX Capabilities.
Methods for changing or applying CSS, creating animations.
Event detection and handling.
Tons of plug-ins for all kind of needs.


Questions 4: How JavaScript and jQuery are different?
Answer 4: JavaScript is a language While jQuery is a library built in the 
JavaScript language that helps to use the JavaScript language.


Questions 5: Is jQuery replacement of Java Script?
Answer 5: No. jQuery is not a replacement of JavaScript. 
jQuery is a different library which is written on top of JavaScript. 
jQuery is a lightweight JavaScript library that emphasizes interaction between 
JavaScript and HTML.


Questions 6: Is jQuery a library for client scripting or server scripting?
Answers 6: Client side scripting.


Questions 7: What is the basic need to start with jQuery? 
Answers 7: To start with jQuery, one need to make reference of it's library.
The latest version of jQuery can be downloaded from 
jQuery.com.


Questions 8: Which is the starting point of code execution in jQuery? 
Answers 8: The starting point of jQuery code execution is 
$(document).ready() function which is executed when DOM is loaded.


Questions 9: What does dollar sign ($) means in jQuery? 
Answers 9: Dollar Sign is nothing but it's an alias for JQuery. 
Take a look at below jQuery code.
$(document).ready(function(){
});
jQuery(document).ready(function(){
});
Over here $ sign can be replaced with "jQuery" keyword. Questions 10: Can we have multiple document.ready() function on the same page? Answers 10: YES. We can have any number of document.ready() function on the same page. Questions 11: Can we use our own specific character in the place of $ sign in jQuery? Answers 11: YES. It is possible using jQuery.noConflict(). Questions 12: What is jQuery.noConflict? Answers 12: As other client side libraries like MooTools, Prototype can be used with jQuery and they also use $() as their global function and to define variables. This situation creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introduced jQuery.noConflict().
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
   jQuery("div").hide();
});  
You can also use your own specific character in the place of $ sign in jQuery.
var $j = jQuery.noConflict();
// Use jQuery via jQuery(...)
$j(document).ready(function(){
   $j("div").hide();
}); 
Questions 13: Is there any difference between body onload() and document.ready() function? Answers 13: document.ready() function is different from body onload() function for 2 reasons. 1) We can have more than one document.ready() function in a page where we can have only one body onload function. 2) document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page. Questions 14: What is the difference between .js and .min.js? Answer 14: Query library comes in 2 different versions Production and Deployment. The deployment version is also known as minified version. So .min.js is basically the minified version of jQuery library file. Both the files are same as far as functionality is concerned but .min.js is quite small in size so it loads quickly and saves bandwidth. Questions 15: What is jQuery Selectors? What are selectors in jQuery and how many types of selectors are there? Answers 15: Selectors are used in jQuery to find out DOM elements. Selectors can find the elements via ID, CSS, Element name and hierarchical position of the element. Name: Selects all elements which match with the given element Name. #ID: Selects a single element which matches with the given ID .Class: Selects all elements which match with the given Class. Universal (*): Selects all elements available in a DOM. Multiple Elements E, F, G: Selects the combined results of all the specified selectors E, F or G. Attribute Selector: Select elements based on its attribute value. Questions 16: What does $("div") will select? Answer 16: his will select all the div elements on page. Questions 17: What does $("div.parent") will select? Answer 17: All the div element with parent class. Questions 18: What are the fastest selectors in jQuery? Answer 18: ID and element selectors are the fastest selectors in jQuery. Questions 19: What are the slow selectors in jQuery? Answers 19: class selectors are the slow compare to ID and element. Questions 20: Which one is faster Jquery ID selector or JavaScript getElementById()? Answer 20: JavaScript getElementById() is faster than Jquery Id ($("#elementID")) selector Questions 21: Where Jquery code execute? On client browser or server browser? Answer 21: On client browser Questions 22: Difference between $(this) and 'this' in jQuery? Answers 22: this and $(this) refers to the same element. The only difference is the way they are used. 'this' is used in traditional sense, when 'this' is wrapped in $() then it becomes a jQuery object and you are able to use the power of jQuery.
$(document).ready(function(){
    $('#spnValue').mouseover(function(){
       alert($(this).text());
  });
});
In below example, this is an object but since it is not wrapped in $(), we can't use jQuery method and use the native JavaScript to get the value of span element.
$(document).ready(function(){
    $('#spnValue').mouseover(function(){
       alert(this.innerText);
  });
});
Questions 23: How do you check if an element is empty? Answer 23: There are 2 ways to check if element is empty or not. We can check using ":empty" selector.
$(document).ready(function(){
    if ($('#element').is(':empty')){
       //Element is empty
  }
});
And the second way is using the "$.trim()" method.
$(document).ready(function(){
    if($.trim($('#element').html())=='') {
       //Element is empty
  }
});
Questions 24: How do you check if an element exists or not in jQuery? Answer 24:
$(document).ready(function(){
    if ($('#element').length > 0){
       //Element exists
  });
});
Questions 25: What is the use of jquery .each() function? Answer 25: The $.each() function is used to iterate over a jQuery object. The $.each() function can be used to iterate over any collection, whether it is an object or an array. Questions 26: What is the difference between jquery.size() and jquery.length? Answer 26: jQuery .size() method returns number of element in the object. But it is not preferred to use the size() method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call. Questions 27: What is the difference between $('div') and $('<div/>') in jQuery? Answers 27: $('<div/>') : This creates a new div element. However this is not added to DOM tree unless you don't append it to any DOM element. $('div') : This selects all the div element present on the page. Questions 28: What is the difference between parent() and parents() methods in jQuery? Answers 28: The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree. Questions 29: How To update info already in a table and Delete a row(s) from a table? Answer 29: mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y', Update_priv = 'Y' where [field name] = 'user'; mysql> DELETE from [table name] where [field name] = 'whatever'; Questions 30: Explain .bind() vs .live() vs .delegate() vs .on() Answer 30: All these 4 jQuery methods are used for attaching events to selectors or elements. But they all are different from each other. .bind(): This is the easiest and quick method to bind events. But the issue with bind() is that it doesn't work for elements added dynamically that matches the same selector. bind() only attach events to the current elements not future element. Above that it also has performance issues when dealing with a large selection. .live(): This method overcomes the disadvantage of bind(). It works for dynamically added elements or future elements. Because of its poor performance on large pages, this method is deprecated as of jQuery 1.7 and you should stop using it. Chaining is not properly supported using this method. .delegate(): The .delegate() method behaves in a similar fashion to the .live() method, but instead of attaching the selector/event information to the document, you can choose where it is anchored and it also supports chaining. .on(): Since live was deprecated with 1.7, so new method was introduced named ".on()". This method provides all the goodness of previous 3 methods and it brings uniformity for attaching event handlers. Questions 31: How to create clone of any object using jQuery? Answer 31: jQuery provides clone() method which performs a deep copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes.
$(document).ready(function(){
  $('#btnClone').click(function(){
     $('#dvText').clone().appendTo('body');
     return false;
  });
});
Questions 32: What is difference between prop and attr? Answer 32: attr(): Get the value of an attribute for the first element in the set of matched elements. Whereas,.prop(): (Introduced in jQuery 1.6) Get the value of a property for the first element in the set of matched elements. attr() gives you the value of element as it was defines in the html on page load. It is always recommended to use prop() to get values of elements which is modified via javascript/jquery , as it gives you the original value of an element's current state. Questions 33: What is event.PreventDefault? Answer 33: The event.preventDefault() method stops the default action of an element from happening. Questions 34: What is the difference between event.PreventDefault and "return false"? Answer 34: e.preventDefault() will prevent the default event from occurring, e.stopPropagation() will prevent the event from bubbling up and return false will do both. Questions 35: How to check if number is numeric while using jQuery 1.7+? Answer 35: Using "isNumeric()" function which was introduced with jQuery 1.7. Questions 36: How to check data type of any variable in jQuery? Answer 36: Using $.type(Object) which returns the built-in JavaScript type for object. Questions 37: How do you attach a event to element which should be executed only once? Answer 37: Using jQuery one() method. This attaches a handler to an event for the element. The handler is executed at most once per element. In simple terms, the attached function will be called only once.
$(document).ready(function() {
    $("#btnDummy").one("click", function() {
        alert("This will be displayed only once.");
    });
});​
Questions 38: Can you include multiple version of jQuery? Answer 38: Yes. Multiple versions of jQuery can be included in same page. Below code shows how to include multiple version of jQuery.





By this way, for your own jQuery code use "$jq", instead of "$" as "$jq" refers to jQuery 1.9.1, where "$" refers to 1.7.2. Questions 39: Can we use jQuery to make ajax request? Answer 39: Yes. jQuery can be used for making ajax request. Questions 40: What are various methods to make ajax request in jQuery? Answers 40: Using below jQuery methods, you can make ajax calls. load() : Load a piece of html into a container DOM $.getJSON(): Load JSON with GET method. $.getScript(): Load a JavaScript file. $.get(): Use to make a GET call and play extensively with the response. $.post(): Use to make a POST call and don't want to load the response to some container DOM. $.ajax(): Use this to do something on XHR failures, or to specify ajax options (e.g. cache: true) on the fly.

Monday, October 14, 2013

Mysql interview questions and answers


Questions 1:  how to do login in mysql with unix shell?
Answers 1: By below method if password is pass and user name is root
           # [mysql dir]/bin/mysql -h hostname -u root -p pass


Questions 2: how you will Create a database on the mysql server with 
unix shell?
Answers 2: mysql> create database databasename;


Questions 3: How Switch (select or use) to a database?
Answer 3: mysql> use databasename;


Questions 4: How To see all the tables from a database of mysql server?
Answer 4: mysql> show tables;


Questions 5: How to see table's field formats or description of table?
Answers 5: mysql> describe tablename;


Questions 6: How to delete a database from mysql server?
Answers 6: mysql> drop database databasename;


Questions 7: How to delete a table? 
Answers 7: mysql> drop table tablename;


Questions 8: How we get Sum of column? 
Answers 8: mysql> SELECT SUM(*) FROM [table name];


Questions 9: how to list or view all databases from the mysql server.? 
Answers 9: mysql> show databases;


Questions 10: How you will Show all data from a table? 
Answers 10: How you will Show all data from a table.

Questions 11: How to returns the columns and column information pertaining 
to the designated table?
Answers 11: mysql> show columns from tablename;


Questions 12: How to Show certain selected rows with the value "dh"?
Answers 12: mysql> SELECT * FROM tablename WHERE fieldname = "dh";
   

Questions 13: How will Show all records containing the name "sonia" AND 
the phone number '1234567890'?
Answers 13: mysql> SELECT * FROM tablename WHERE name = "sonia" AND 
phone_number = '1234567890';
   

Questions 14: How you will Show all records not containing the name "sonia" 
AND the phone number '1234567890' order by the phone_number field?
Answer 14: mysql> SELECT * FROM tablename WHERE name != "sonia" AND 
phone_number = '1234567890' order by phone_number;
   

Questions 15: How to Show all records starting with the letters 'sonia' 
AND the phone number '1234567890'?
Answers 15: mysql> SELECT * FROM tablename WHERE name like "sonia%" 
AND phone_number = '1234567890';
   

Questions 16: Use a regular expression to find records. Use "REGEXP BINARY" 
to force case-sensitivity. This finds any record beginning with r?
Answer 16: mysql> SELECT * FROM tablename WHERE rec RLIKE "^r";
   

Questions 17: How you will Show unique records?
Answer 17: mysql> SELECT DISTINCT columnname FROM tablename;
   

Questions 18: how we will Show selected records sorted in an ascending (asc) 
or descending (desc)?
Answer 18: mysql> SELECT col1,col2 FROM tablename ORDER BY col2 DESC;
mysql> SELECT col1,col2 FROM tablename ORDER BY col2 ASC;
   

Questions 19: how to Return total number of rows?
Answers 19: mysql> SELECT COUNT(*) FROM tablename;
   

Questions 20: How to Join tables on common columns?
Answer 20: mysql> select lookup.illustrationid, lookup.personid,person.birthday from 
lookup left join person on lookup.personid=person.personid=statement to join birthday 
in person table with primary illustration id
   

Questions 21: How to Creating a new user. Login as root. Switch to the MySQL 
db. Make the user. Update privs?
Answer 21: # mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,User,Password) 
VALUES('%','username',PASSWORD('password'));
mysql> flush privileges;


Questions 22: How to Change a users password from unix shell?
Answers 22: # [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p 
password 'new-password'
   

Questions 23: How to Change a users password from MySQL prompt. Login as 
root. Set the password. Update privs?
Answer 23: # mysql -u root -p
mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');
mysql> flush privileges;
   

Questions 24: How to Recover a MySQL root password. Stop the MySQL server 
process. Start again with no grant tables. Login to MySQL as root. 
Set new password. Exit MySQL and restart MySQL server?
Answer 24: 
# /etc/init.d/mysql stop 
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql>update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
   

Questions 25: How to Set a root password if there is on root password?
Answer 25: # mysqladmin -u root password newpassword
   

Questions 26: How to Update a root password?
Answer 26: # mysqladmin -u root -p oldpassword newpassword
   

Questions 27: How to allow the user "sonia" to connect to the server from 
localhost using the password "passwd". Login as root. Switch to the MySQL 
db. Give privs. Update privs?
Answers 27: # mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to sonia@localhost identified by 'passwd';
mysql> flush privileges;
   

Questions 28: How to give user privilages for a db. Login as root. Switch to the 
MySQL db. Grant privs. Update privs?
Answers 28: # mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,
Delete_priv,Create_priv,Drop_priv) VALUES 
('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges; 
or 
mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;
   

Questions 29: How To update info already in a table and Delete a row(s) from 
a table?
Answer 29: 
mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',
Update_priv = 'Y' where [field name] = 'user'; 
mysql> DELETE from [table name] where [field name] = 'whatever';
   

Questions 30: How to Update database permissions/privilages?
Answer 30: mysql> flush privileges;
   

Questions 31: How to Delete a column and Add a new column to database?
Answer 31: mysql> alter table [table name] drop column [column name];
mysql> alter table [table name] add column [new column name] varchar (20);
   

Questions 32: Change column name and Make a unique column so we get 
no dupes?
Answer 32: 
mysql> alter table [table name] change [old column name] 
[new column name] varchar (50);
mysql> alter table [table name] add unique ([column name]);
   

Questions 33: How to make a column bigger and Delete unique from table?
Answer 33: mysql> alter table [table name] modify [column name] VARCHAR(3);
mysql> alter table [table name] drop index [colmn name];
   

Questions 34: How to Load a CSV file into a table?
Answer 34: 
mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE 
[table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' 
(field1,field2,field3);
   

Questions 35: How to dump all databases for backup. Backup file is sql 
commands to recreate all db's?
Answer 35: 
# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
   

Questions 36: How to dump one database for backup?
Answer 36: # [mysql dir]/bin/mysqldump -u username -ppassword --databases 
            databasename >/tmp/databasename.sql
   

Questions 37: How to dump a table from a database?
Answer 37: # [mysql dir]/bin/mysqldump -c -u username -ppassword databasename 
            tablename > /tmp/databasename.tablename.sql
   

Questions 38: Restore database (or database table) from backup?
Answer 38: # [mysql dir]/bin/mysql -u username -ppassword databasename < 
            /tmp/databasename.sql
   

Questions 39: How to Create Table show Example?
Answer 39: 
mysql> CREATE TABLE [table name] (firstname VARCHAR(20),
middleinitial VARCHAR(3), lastname VARCHAR(35),
suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),
username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), 
groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));


Questions 40: How to search second maximum(second highest) salary 
value(integer)from table employee (field salary)in the manner so that 
mysql gets less load?
Answers 40: By below query we will get second maximum(second highest) 
salary value(integer)from table employee (field salary)in the manner so 
that mysql gets less load 

SELECT DISTINCT(salary) FROM employee order by salary desc limit 1 , 1 ; 

(This way we will able to find out 3rd highest , 4th highest salary so on 
just need to change limit condtion like LIMIT 2,1 for 3rd highest and 
LIMIT 3,1 for 4th 
some one may finding this way using below query that taken more time 
as compare to above query.

SELECT salary FROM employee where salary < (select max(salary) from employee) 
order by salary DESC limit 1 ;

Monday, August 12, 2013

oDesk Readiness Test Answers

1.  Which of the following are NOT permitted on oDesk?
    
    a. Sharing a single account between multiple people
    b. Opening more than one account on oDesk
    c. Using a logo or clip art as your profile portrait
    d. Using a fake name
    e. All of the above (answer)
 
2.  Which of the following actions are NOT allowed when applying   to job postings? 

    a. Misrepresenting your skills, experiences, portfolio, etc.
    b. Submitting boilerplate, placeholder or generic bids or other spam
    c. Disclosing direct contact information 
    d. Applying when you are not truly qualified
    e. All of the above (answer)

3. Can I start my own agency on oDesk?

    a. Yes! You can create an agency and earn money by selling the services of your agency contractors.(answer)
    b. No, oDesk is for independent contractors only

4. What happens when a contract ends?

    a. You lose access to the Work Diary 
    b. Both users can leave feedback
    c. The feedback system is double blind, so your employer cannot see the feedback you
    left them until after they have left feedback for you
    d. Hours will be billed (and disputes may be filed) according to the usual weekly payment schedule
    e. All of the above (answer)
  
5. Which of the following are TRUE about your oDesk Work Diary?

    a. Allows employers to see when and what their contractors are working on
    b. Enables automatic billing for hourly contracts
    c. The oDesk Team application auto-tracks time which can be reviewed in the Work Diary
    d. Manual time can be added, but isn't guaranteed payment
    e. All of the above(answer)

6. Which of the following are TRUE about the oDesk dispute process?

    a. The dispute process only applies to Hourly contracts 
    b. If you fail to respond, oDesk will refund the employer and suspend your account
    c. If you reject the dispute, oDesk specialists will review your Work Diary and
    evaluate it against the criteria of the payment guarantee 
    d. Disputed hours ruled in the employers favor are refunded
    e. All of the above(answer)

7.  Which of the following is FALSE about weekly limits on hourly contracts?

    a. Hours in excess of the weekly limit will not be billed to the employer 
    b. You should discuss any need to work beyond your limit with your employer
    c. The weekly limit can be changed by the contractor(answer)
    d. The weekly limit can be changed by the employer
    e. Hours in excess of the weekly limit are not guaranteed payment

8. The oDesk Team application Time Tracker records which of the following

    a. Screenshot of the active screen once per billing segment
    b. Number of keystrokes
    c. Number of mouse clicks
    d. Memo entered by the contractor
    e. All of the above(answer)

9. Which of the following statements about oDesk fees is FALSE?

    a. The oDesk fee is 10% of the employer's payment to oDesk 
    b. ODesk is free to join
    c. ODesk is free for contractors to apply and work on jobs
    d. The ODesk fee is $2/hour for hourly contracts  (answer)
    e. All of the above

10. Which of the following is TRUE about fixed-price contracts?

    a. Employer billed automatically each week 
    b. How much to pay and when to pay is at the employer's discretion(answer)
    c. Hours worked will show on your profile
    d. Time-tracking required
    e. Qualify for the oDesk payment guarantee

11. Which of the following are required to qualified for guaranteed payment.

    a. An hourly contract.
    b. Tracking your time with the oDesk team application.
    c. Entering relevant memos.
    d. An employer with a verified payment methods.
    e. All of the above (answer)

Wednesday, July 17, 2013

Get selected value of dropdownlist

<!DOCTYPE html>
<html>
    <head>
        <script>
            function selectedValue()
            {
                var index = document.getElementById("myValue").selectedIndex;
                var value = document.getElementById("myValue").options[index].text;
                alert(value);
            }
        </script>
    </head>
    <body>
        <form>
            Select your favorite Subject:
            <select id="myValue">
                <option>PHP</option>
                <option>HTML</option>
                <option>JQuery</option>
                <option>Javascript</option>
            </select>
        </form>
        <button type="button" onclick="selectedValue()">Selected Value</button>
    </body>
</html>

Thursday, July 4, 2013

convert stdClass Object to Array in php

<?php

/**
 * Convert an stdClass object to an array
 *
 * @param    stdClass object  $varObj The object to convert
 * @reeturn  array
 *
 */
function convertObjectToArray($varObj) {
    if (!is_object($varObj) && !is_array($varObj)) {
        return $object;
    }
    if (is_object($varObj)) {
        $varObj = get_object_vars($varObj);
    }
    return array_map('objectToArray', $varObj);
}
/** convert the object to array **/
$resultArray = convertObjectToArray( $obj );

/** Display the result array **/
print_r( $resultArray );
?>

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