Showing posts with label php problem solutions. Show all posts
Showing posts with label php problem solutions. Show all posts

Saturday 9 November 2019

Git interview questions and answers - Problem and Solutions


Git interview questions and answers - Problem and Solutions

Question: How to delete a Git branch both locally and remotely?
To remove a local branch from your local system.
git branch -d the_local_branch

To remove a remote branch from the server.
git push origin :the_remote_branch



Question: How do you undo the last commit?
git revert commit-id



Question: How to Edit an incorrect commit message in Git?
git commit --amend -m "This is your new git message"



Question: What are the differences between 'git pull' and 'git fetch'?
Git pull automatically merges the commits without letting you review them first.
Git fetch stores them in your local repository but it not merge them with your current branch.
git fetch similar to guit pull but it does not merge the changes.


Question: How do you rename the local branch?
git branch -m oldBranchName newBranchName



Question: How do I remove local files (Not in Repo) from my current Git branch?
git clean -f -n


Question: How to Checkout remote Git branch?
git checkout test



Question: How do I remove a Git submodule?
git rm the_submodule
rm -rf .git/modules/the_submodule



Question: How do you create a remote Git branch?
git checkout -b your_branch_name
git push -u origin your_branch_name



Question: How to Change the URL for a remote Git repository?
git remote set-url origin git://this.is.new.url



Question: How to Change the author of a commit in Git?
git filter-branch -f --env-filter "GIT_AUTHOR_NAME='NewAuthorName'; GIT_AUTHOR_EMAIL='authoremail@gmail.com'; GIT_COMMITTER_NAME='CommiterName'; GIT_COMMITTER_EMAIL='committergmail@gmail.com';" HEAD



Question: What is .gitignore?
.gitignore tells git which files/folder should be ignore.
Create a file with name of .gitignore in root.
temporay files, system files, hidden files or local downloaded modules we can add in .gitignore file, so that git will not added this.


Question: How do I delete a Git branch locally?
git branch -d {the_local_branch}


Question: How do I delete a Git branch remotely?
git push origin --delete {the_remote_branch}
(use -D instead to force deleting the branch without checking merged status)


Question: What is the difference between git pull and git fetch?
git pull does a git fetch followed by a git merge.



Question: How do I undo git add before commit?
git reset file.php



Question: How do I rename a local Git branch?
git branch -m oldname newname




Question: How do I discard unstaged changes in Git?
git stash save --keep-index --include-untracked

You don't need to include --include-untracked if you don't want to be thorough about it.
After that, you can drop that stash with a git stash drop command if you like.


Tuesday 13 August 2019

How do I add environment variables in Unix



Question: How to print the environment values?
printenv

OR
env



Question: How to SET the environment values For Korn shell (KSH)?
var=value
export varname



Question: How to SET the environment values For Bourne shell (sh and bash)?
export var=value



Question: How to SET the environment values For C shell (csh or tcsh)?
setenv var value



Question: What is .bashrc?
.bashrc is a shell script that Bash runs whenever it is started interactively.


Question: Can we set the environment value in .bashrc?
Yes, you can set the value in this also. like below
export PATH="$PATH:/some/addition"




Friday 23 February 2018

PHP Redirect, 301 or 302 Redirection With PHP and benefits

301 or 302 Redirection With PHP and benefits

Question: What is Redirection?
On a Web site, redirection is a technique for moving visitors to a different web page OR Different website.


Question: Why we do need redirection?
We do need redirection, because we want to tell the visitor that current page is not appropriate for you or current page have been moved to new location.

Following are different reason, we do Redirection
  1. If user already login, and try to open the login page redirect him to user dashboard.
  2. Trying to access a page which is temporary not available.
  3. If user trying to access un-authorized page, Redirect him to user dashboard.
  4. Tring to access non-exist page, redirect him sitemap page OR 404 page.
  5. Trying to access non-exist website.


Question: What are different type of redirects?
  1. 301 permanent redirects
  2. 302 temporary redirects


Question: What is 301 permanent redirect?
301 code refers to the HTTP status code.
A 301 redirect is a permanent redirect which passes between ranking power(>90%) to the redirected page.


Question: When we use 301 redirects?
  1. When a web page permanently removed, we redirect user to new page.
  2. When we want to transfer the ranking benefits(SEO point of view) to new web page.
  3. Redirect user to new web page and stopped him to access old page(not available page).
  4. If you have updated the contents to new web page, MUST USE 301 Redirects
  5. 301 indicates to both browsers and search engine bots(Google, bing, yahoo) that the page has moved permanently.



Question: What is 302 temporary redirects?
302 refers to the HTTP status code.
A 302 redirect is a temporary redirect. We have to tell user its temporary unavailable and will be available very soon.


Question: When we use 302 redirects?
  1. If user already login, and try to open the login page redirect him to user dashboard.
  2. Trying to access a page which is temporary not available.
  3. If user trying to access un-authorized page, Redirect him to user dashboard.


Question: How to make 301 redirect with php (Permanent)?
header('Location: http://www.example.com/new-web-page.php', true, 301);exit;



Question: How to make 302 redirect with php (Temp)?
header('Location: http://www.example.com/new-web-page.php', true, 302);exit;

OR
header('Location: http://www.example.com/new-web-page.php');exit;

Both are same and works same.


Question: Can we use regular express in Redirection?
Yes, See Example:
if(preg_match("/^\/old\./", $_SERVER['REQUEST_URI'], $m)){
    header('Location: http://www.example.com/new-web-page.php', true, 301);exit;
}
URL start with /old will be redirect to http://www.example.com/new-web-page.php


Question: Give an URL to check 301 redirects?
http://www.aboutcity.net/youtube/videos/watch/wEVPkxFC0NI


Question: Where can I test redirect online? http://www.redirect-checker.org/index.php
(Check Your Redirects and Statuscode 301 vs 302, meta refresh & javascript redirects)


Question: How to make 301 redirect with htaccess?
Add following code in htaccess
Redirect 301 /old/ /new/

Make Sure "RewriteEngine On" and installed "mod_rewrite" on server.


Question: How to make 302 redirect with htaccess?
Add following code in htaccess
Redirect 302 /old/ /new/

Make Sure "RewriteEngine On" and installed "mod_rewrite" on server.

Question: What are different HTTP status code used in web?
301 - Permanent movement(redirection)
302 - Temporary movement(redirection)
400 - Bad request
401 - Authorization Required
For More details http://www.web-technology-experts-notes.in/2014/02/htaccess-code-snippets-example.html


Wednesday 6 September 2017

jQuery multi column sorting with jQuery - Live Demo

jQuery multi column sorting with jQuery


tablesorter is a jQuery plugin used for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes also no ajax call. tablesorter can successfully parse and sort many types of data including linked data in a cell. It has many useful features including:
  • Multi-column sorting
  • Parsers for sorting text, URIs, integers, currency, floats, IP addresses, dates (ISO, long and short formats), time. Add your own easily
  • Support secondary "hidden" sorting (e.g., maintain alphabetical sort when sorting on other criteria)
  • Extensibility via widget system
  • Cross-browser: IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+
  • Small code size


Demo


Documentation


How to Select / Deselect All Checkboxes using jQuery

How to Select / Deselect All Checkboxes using jQuery
If you are developer and looking for a jQuery code-snippet that selects and de-selects multiple checkboxes by clicking “Select All” checkbox, like in Gmail.com, rediffmail.com and yahoo.com. Then you are at right place. 

This is very simple and most commonly used in web application and specially its used where there is multiple record listing. 

In Admin section,  this functionality is needed in every page, like User Listing, Product Listing, Album Listing  & images listing etc. 

When selected "Select All" checkbox, It will select all the checkbox under the main checkbox. 
If you de-select the "Select All", It will de-select all the checkbox under this main checkbox.



You can use below code and do the modification as per your requirement. This code is very useful not just in current web application but also for future.

select all checkbox jquery DEMO


 
Select All
Name2
Name3
Name4
Name5
Name6
Code Snippet
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script type="text/javascript"> 

jQuery(document).ready(function() {

    jQuery('#checkbox_all').click(function(){ 
        
        if($(this).is(":checked")){ 
            jQuery('input[type="checkbox"].chk').each(function(){ 

                jQuery(this).prop("checked",true);

            });         

        }else{ 

            jQuery('input[type="checkbox"].chk').each(function(){ 

                jQuery(this).prop("checked",false);

            });                 

        } 

     

    }); 

}); 

</script> 
<table border="1" rules="groups" style="width: 200pxpx;">
<tbody>
<tr> 

        <th><input id="checkbox_all" name="checkbox" type="checkbox" /></th> 

        <th>Select All</th> 

    </tr>
<tr> 

        <td><input class="chk" name="checkbox" type="checkbox" /></td> 

        <td>Name2</td> 

    </tr>
<tr> 

        <td><input class="chk" name="checkbox" type="checkbox" /></td> 

        <td>Name3</td> 

    </tr>
<tr> 

        <td><input class="chk" name="checkbox" type="checkbox" /></td> 

        <td>Name4</td> 

    </tr>
<tr> 

        <td><input class="chk" name="checkbox" type="checkbox" /></td> 

        <td>Name5</td> 

    </tr>
<tr> 

        <td><input class="chk" name="checkbox" type="checkbox" /></td> 

        <td>Name6</td> 

    </tr>
</tbody></table>