Friday, 21 August 2015

How to redirect http to https in Zend Framework

How to redirect http to https in Zend Framework

http to https, Follow the following:
  1. Open htaccess file in /public OR /public_html.
  2. Add following code in your .htaccess at top
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  3. Save the File .
  4. Refresh the webpage, you will see same page is opened with https.
If you are getting infinite loop, then it means you are using CloudFlare or a similar CDN. Now instead of above code, use below one.
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]



Thursday, 20 August 2015

Magento interview questions and answers for experienced

Magento interview questions and answers for experienced


Question: What is Magento?
Magento is an e-commerce platform created on open source technology, which provides online merchants with an exceptional flexibility. Magento is CMS which control content, look and functionality of their e-commerce store. It is one of the best CMS known for ecommerce website.


Question: What architecture is used by Magento?
MVC which means Model-View-Controller.


Question: What are the different edition of Magento?
  1. Magento Community Edition
  2. Magento Enterprise Edition
  3. Magento Professional Edition
  4. Magento .go



Question: What are the different features of Magento?
  1. User Management
  2. Customer Management
  3. Product Management
  4. Order Management
  5. Payment Management
  6. Site Management
  7. Search engine optimization
  8. International Support



Question: How we can enhance the Magento performance?
  1. Disable the Magento log
  2. Disable any un-used modules
  3. Magento Caching
  4. Enable Gzip compression
  5. Optimize your image
  6. Optimize your Server
  7. Use a Content Delivery Network (CDN)
  8. USE Gzip Components
  9. Put Stylesheets at the Top (CSS Files in head tag)
  10. Put Scripts at the Bottom (Js files in footer)
  11. Avoid CSS Expressions (e.g 100/2)

Look: http://www.web-technology-experts-notes.in/2013/10/14-steps-to-reduce-the-loading-time-of-website.html


Question: Which technology does mangento use?
Zend Framework (PHP), MySQL/MySQLI, CSS, javaScript and HTML


Question:In Which language, mangento is written?
PHP


Question:What is initial Release date of magento?
March 31, 2008


Question:What is initial Release date of magento?
Version: 1.9.1.1 Dated May 1, 2015


Question: What type of web application we create in Magento?
Shopping Cart Software


Question: What is the difference between Mage::getSingletone() and Mage::getModel() in Magento?
Mage::getSingletone(): finds for an existing object if not then create that a newobject but Mage::getModel() always creates a new object.


Question: What is EAV in Magento?
Full form of EAV is Entity–attribute–value model.
EAV is a data model to data model to describe entities.
In EAV data are stored in different smaller tables rather than storing in a single table.
For Example
Product name is stored in catalog_product_entity_varchar table.
Product id is stored in catalog_product_entity_int table.
Product price is stored in catalog_product_entity_decimal table.


Question: How does Magento ORM works?
ORM full form is Object Relational Mapping.
ORM is a programming technique which is used to convert different types of data to Objects and vice versa
. ORM is shown as Model (based on Zend Framework’s Zend_Db_Adapter), which further breaks down to two types of Models.
a. simple
b. EAV Model


Question: What is folder/file structure of Magento?
What is folder/file structure of Magento



Question: What are different Modules of Magento?
Core Modules
Community Modules
Commercial Modules


Question:How to add an external javascript/css file in Magento? ?
Add Css File
<action method="addCss"><stylesheet>css/yourstyle.css</stylesheet></action>
Add jS File
<action method="addJs"><script>js/yourfile.js</script></action>



Question: How to change the theme for login user?
if(Mage::getSingleton('customer/session')-&gt;isLoggedIn()):
Mage::getDesign()-&gt;setPackageName('package_name')-&gt;setTheme('themename');
endif;


Question: How to run Custom Query in Magento ?
$db = Mage::getSingleton('core/resource')-&gt;getConnection('core_write');
$result=$db-&gt;query('SELECT * FROM users where id=4');




Tuesday, 18 August 2015

How do you parse and process HTML in PHP

How do you parse and process HTML in PHP


Following are different ways to parse the HTML

Use DOM: The DOM extension allows you to operate on XML documents through the DOM API with PHP 5.
$fullHTML = file_get_contents('http://www.example.com/scrap.php');
$domObj = new DOMDocument();
$domObj-&gt;loadHTML($fullHTML);
$xpath = new DOMXPath($domObj);
$tags = $xpath-&gt;query('//div[@class="myclass"]/div');
foreach ($tags as $tag) {
    print_r(trim($tag-&gt;nodeValue));
    echo "\n";
}



Use SimpleXMLElement: The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators.
$fullHTML = file_get_contents('http://www.example.com/scrap.php');
$allData = new SimpleXMLElement($fullHTML);
print_r($allData);



Regular Expressions: It is sequence of symbols and characters expressing a string or pattern to be searched for within a longer piece of text.
$fullHTML = file_get_contents('http://www.example.com/scrap.php');
preg_match_all("/&lt;(\w+)(\s+(\w+)\s*\=\s*(\'|")(.*?)\\4\s*)*\s*(\/&gt;|&gt;)/", $fullHTML, $matches);
print_r($matches);



3rd Party Libraries
There are lot of 3 party libraries which can parse your HTML/XHTMl. Following are few famous libraries.
phpQuery: phpQuery is a server-side, chainable, CSS3 selector driven Document Object Model (DOM) API based on jQuery JavaScript Library written in PHP5 and provides additional Command Line Interface (CLI).
Zend_Dom: Zend_Dom provides tools for working with DOM documents and structures.
QueryPath: QueryPath is a PHP library for manipulating XML and HTML.
FluentDom: FluentDOM provides a jQuery-like fluent XML interface for the DOMDocument in PHP.



WebServices
There are different APIs are available for the scraping the website and few of them are following.
YQL:The YQL Web Service enables applications to query, filter, and combine data from different sources across the Internet. It have like SQL syntax, familiar to any developer with database experience.
ScraperWiki: ScraperWiki's external interface allows you to extract data in the form you want for use on the web or in your own applications. You can also extract information about the state of any scraper.



Monday, 17 August 2015

Edit an commit message in Github Repository - Commands

Question: How to change the Most recent commit message?
git commit --amend -m "This is updated commit message"


Question: How to change the Most recent commit message and append the files
git commit -a --amend -m "This is updated commit message"


How to display the status of files in the index versus the working directory?
git status; //;On branch test


How to create new Github directory?
git init <directory></directory>


How to get checkout from GitHub URL?
git clone /path/to/repository


Question: How to Add a files in github?
git add <files></files>


Question: How to commit the files in github?
git commit


Question: How to Push to a repository
git push origin


Question: HOw to git push in origin branch?
To push to your branch


Question: How to transfer all changes in your github?
git add file.txt
git commit  -m "We are add file.txt"
git push


Question: How to add file with commit message?
git add file.txt commit -m "We are add file.txt"


Question: How to pull all the changes ?
git pull origin


Thursday, 13 August 2015

How do you get a timestamp in JavaScript?

How do you get a timestamp in JavaScript?

Question: What is timestamp?
timestamp is the current time of an event that is recorded by a computer. In JavaScript, it gives local time (computer ).


Question: How do you get a timestamp in JavaScript?
Date.now()



Question: How do you get a timestamp in number of seconds?
Math.floor(Date.now() / 1000)



Question: How do handle exception to this is IE8 and other Browser?

if (!Date.now) {
Date.now()
}



Question: How do you get the date from the time object
new Date().getDate()



Question: What are other date-functions in javascript?
getDate(): Get the day as a number (1-31)
getDay(): Get the weekday as a number (0-6)
getFullYear(): Get the four digit year (yyyy)
getHours(): Get the hour (0-23)
getMilliseconds(): Get the milliseconds (0-999)
getMinutes(): Get the minutes (0-59)
getMonth(): Get the month (0-11)
getSeconds(): Get the seconds (0-59)
getTime(): Get the time (milliseconds since January 1, 1970)

Wednesday, 12 August 2015

How do closures work in Javascript

How do closures work in Javascript


Question: What is closures?
Whenever you defined a the function within another function, the inner function has access to variables in the outer function.


Following are Simple example of closure.
function mainFunction(outerData) {
  var mainFuncData = 3;

  function innerFunction(innerFuncData) {
    console.log(outerData + innerFuncData + (++mainFuncData)); // will alert 16
  }

  innerFunction(10);
}

mainFunction(7); //17


Question: Why it can access to variables in the outer function?
Because It is defined as var , which means it is global variable.

Tuesday, 11 August 2015

How to logout from facebook with javascritp SDK - FB.logout


How to logout from facebook with javascritp SDK - FB.logout

Following are  code snippets to logout from Facebook:
<script>window.fbAsyncInit = function() {
                FB.init({
                    appId      : "FACEBOOK_APPLICATION_ID", 
                    status     : true, 
                    cookie     : true,
                    xfbml      : true,
                    oauth      : true                    
                });
                FB.getLoginStatus(function(response) {
                if (response && response.status === 'connected') {
                    FB.logout(function(response) {
                       /** Afer logout, Refresh the Page **/ 
                       console.log('Logout Successfully.');
                       document.getElementById('currentStatus').innerHTML='Logout from facebook Successfully.';
                       //document.location.href='/';
                       /** Afer logout, Refresh the Page **/                        

                    });
                }else{
                    //document.location.href='/';                    
                    document.getElementById('currentStatus').innerHTML='You are NOT LOGIN in Facebook.';
                    console.log('You are not login in Facebook.')
                }
            });


            }; 

            (function(d){
                var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
                js = d.createElement('script'); js.id = id; js.async = true;
                js.src = "//connect.facebook.net/en_US/all.js";
                d.getElementsByTagName('head')[0].appendChild(js);
            }(document));
        </script>
        <h2 id="currentStatus">
Please wait...</h2>