How to setup PHP CodeSniffer on Windows machine ?

How to use CodeSniffer on Windows ? How to setup the PHP CodeSniffer on Windows ? These questions come to mind when you see various articles, tutorials which provides ways/steps to setup this on Linux. So here are simple steps to setup PHP CodeSniffer on Windows. Before going into this, for those who don’t know what is CodeSniffer? here is a simple answer.

If you are a developer or code reviewer and you want to check the code for any mistakes/if the code following particular coding standards, then CodeSniffer is a good tool to achieve that.

PHP_CodeSniffer is a PHP5 script that tokenises PHP, JavaScript and CSS files to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

Now, lets setup CodeSniffer to check if our code follows a defined coding standard. 🙂

My setup environment:

  • Windows 7 Professional,
  • XAMPP for Windows( Apache, MySQL, PHP and Perl ) and the PHP install directory is C:xamppphp
Steps:
  • Open windows command prompt by going.
    Start -> Run -> type in ‘ cmd ‘ -> press Enter
  • Go to your php install directory.
  • Then type in the command to install PHP Code_Sniffer from the pear.php.net
  • subharanjan_codesniffer_installation

  • After completion, to check successfull installation run this command.
    if everything goes well, then it should show list of coding standard definitions found.

As the CodeSniffer is installed now, you can start using this to check files by using below commands. ( To run any commands, you should be inside C:xamppphp )

Checking a single file or folder:

Sample PHP_CodeSniffer output with no warnings:

Specifying a coding standard to use:

For more usage commands: http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php

How to add a new coding standard definition into PHP CodeSniffer ?

Lets take WordPress coding standard for demo purpose found here: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards

Steps:
– If you have git installed on you machine, then run this command on git bash.

subharanjan_codesniffer_git_bash
OR

If you don’t have git on your machine, then

subharanjan_codesniffer_directory_structure
Now you can check any file for WordPress coding standard.

How to reduce 404 errors created by ++liker.profile_URL++

Are you getting lots of 404 errors in the log because of some urls having patterns like ” ++liker.profile_URL++ ” ? How to reduce 404 errors created by ++liker.profile_URL++ ? Here is the solution to stop those 404 errors and convert those urls to result in 301 permanent redirects to your homepage.

Problem:
Some days back, when I saw the log created by Better WP Security plugin installed on my blog, there were a lot of 404 errors because of some weird URLs something like this:

  1. subharanjan.com/subharanjan.com/subharanjan.com/remove-or-override-functions-attached-to-a-specified-filter-hook/++liker.profile_URL++
  2. subharanjan.com/++liker.profile_URL++

I tried to find out about this and seems like this is a link dropping spambot. I am not sure what exactly it does but here is a solution to stop this.

Solution:

  • Open you .htaccess file.
  • Add these lines below into your .htaccess file which can be found at the root of your WordPress installation.
    Add these lines before the lines( url rewrites ) added by WordPress for permalink support. It should look like this:
  • Save the .htaccess file and check by accessing one of the urls having ++liker.profile_URL++ and see if it results in a 404 Page not found error OR simply redirects to your home page.

Explanation of the above htaccess code snippet:
RewriteCond will be looking for the pattern “++liker.profile_URL++” in the requested urls. Once it finds that piece of text in the requested url, it will redirect the request to home page in place of creating a 404 error as mentioned in the RewriteRule section.

RewriteRule defines a particular rule.
The first string of characters after RewriteRule defines what the original URL looks like.
The second string after RewriteRule defines the new URL. This is in relation to the document root (html) directory. / means the html directory itself, and subfolders can also be specified.

  • ^ begins the line to match.
  • . stands for “any non-whitespace character”
  • * means that the previous character can be matched zero or more times.
    So, ^uploads.*$ matches uploads2009, uploads2010, etc.
    ^.*$ means “match anything and everything.” This is useful if you don’t know what your users might type for the URL.
  • () designates which portion to preserve for use again in the $1 variable in the second string. This is useful for handling requests for particular files that should be the same in the old and new versions of the URL.
  • [NC] matches both upper- and lower-case versions of the URL.
  • [R=301,L] – this performs a 301 redirect and also stops any later rewrite rules from affecting this URL. It’s on the same line as RewriteRule, at the end.

Source: https://kb.mediatemple.net/questions/85/Using+.htaccess+rewrite+rules#gs

How to delete chat history of a particular user/contact in Skype [Solved]

Skype, one of the most used VOIP client software for communication inside organizations. One problem with this software is that: by default you can’t remove chat history for a specific contact. To delete chat history of a particular user/contact in your Skype, you have to use a DB browser software( sqlitebrowser ) to read the local DB files and make the changes. Follow the steps below to remove any history for a specific user from your system.

Note:
This removes the history form your local system; not from the other side of the Skype contact. So, he/she can see those from his/her computer.

Caution:
Take backup of main.db file before implementing anything from these steps.

Steps:

  • Download the DB Browser( SQLite Browser ). Its free and open source.
    You can get it from here: http://sourceforge.net/projects/sqlitebrowser/
  • Signout and Quit your Skype.
  • Go to the directory below and take a backup of the file main.db file. Just copy the directory itself or the file and keep it somewhere else for safety.

    Replace ‘skype_username’ with your skype user name in the above path.
  • Extract and run the sqlitebrowser software and open the Skype DB file(main.db) located here:
    C:Users’windows_username’AppDataRoamingSkype’skype_username’main.db
    Replace ‘skype_username’ with your skype user name in the above path.
  • — Click on the browse data tab. Here you can have all the tables that are being used to store history data in Skype.
    — Search the records by the particular user and delete those records. Mainly the chat related records reside inside ‘Chats’, ‘Messages. table.
    — Go to Browse data tab -> select table Messages -> click on find icon ->
    select author -> contains -> skype profile name of user you are searching for ->
    click on one of the last results in the list and you will see the row.
    — Select the records and click on ‘Delete Record’ button.
  • At last don’t forget to click on the save changes icon.

Open Skype and see the changes… Enjoy 🙂

sqlitebrowser[ Download sqlitebrowser: http://sourceforge.net/projects/sqlitebrowser/ ]

main_db_path

Update: There is one free & open source software available for achieving all of the above manual trick. Skyperious: Skyperious is a Skype database viewer and merger, written in Python. You can open local Skype SQLite databases and look at their contents:

  • search across all messages and contacts
  • browse chat history and export as HTML, see chat statistics
  • import contacts from a CSV file to your Skype contacts
  • view any database table and and export their data
  • change, add or delete data in any table
  • execute direct SQL queries

How to display profile image in google search

May be you want to display your google profile image next to the search result for your blogs in Google search. If you google something, you can see some small images next to the search results. These are nothing but the google profile images of the blog authors. When you see that photo show up in your search results, it means Google are verifying that the blog post was written by that person. If you click on the name in the search results, it takes you to that blog author’s Google+ Profile. You can join me on Google+ here!

Thankfully its very easy to configure your site to be compatible with the new author photo snippets that show up on Google Search. However not guaranteed that your photo, or a photo of one of your authors, will appear in Google Search immediately. It is rumored that Google has enabled that feature only for selected blogs and sites based on some criterias.

How to do it ?

  1. Create an author page or “About Me” page on your blog site(same domain).
  2. Add link to this author page from your blogs.
  3. Add a link to your Google profile in the Author page.
  4. Linking Back from Google Profile to your Author page/About Page.Here we need to link back from the Google profile to the about page on the website. Open your Google Profile, click the Profile icon at the top and then the Edit Profile button at the top. Locate links on the right side and select the Add custom link option.

The idea is actually extremely simple. You link from your blog to your Google Profile – Then, from your Google Profile to your blog. This reciprocal linking verifies that the owner of that Google Profile is also the (or an) author on that blog. If you own a multi authored blog it works too. You just need your bloggers to link from their Google Profile, to their author page on your blog.

I’d like you to read the instructions from Google,Google: Adding author information in search results which I followed to add the profile image.

To summarize:
Option 1. Add your name and email to your content (recommended for sites with content by multiple authors)
Option 2. Link your content to your Google Profile, and vice versa

Testing with google’s Rich Snippets Tool:
Once you have followed the instructions, check that you have done it correctly using Google’s Rich Snippets Testing Tool. This tool will let you know if the code is working and show you what your blog will “look” like in Google’s search results, AFTER they have activated it. To use the Rich Snippets Testing Tool, simply paste the URL (address) of one of your blog posts into it and press the preview button .

Then, if everything looks OK and you see your photo in the preview, it’s a matter of waiting… I look forward to seeing your smiling faces when I’m next searching!