Life runs on code

Month: February 2014

[Fixed] MacBook Pro built-in webcam not working ?

[Fixed] MacBook Pro built-in webcam not working ?

So many times its happens with my mac that Skype, Chrome other applications are not able to access built in webcam. After googling i came up with following solution. Usually it’s not a macbook problem. It’s software problem. open a terminal and type sudo killall […]

Run Multiple instance of Skype on Mac OS X

Run Multiple instance of Skype on Mac OS X

Run following command in terminal to start second instance of Skype sudo /Applications/Skype.app/Contents/MacOS/Skype

Generic autoloader for classes named in WordPress coding style

Generic autoloader for classes named in WordPress coding style

if ( ! class_exists( 'RT_WP_Autoload' ) ){
 /**
  * Generic autoloader for classes named in WordPress coding style.
  */
  class RT_WP_Autoload {
    /**
     * @var string Current directory absolute path
     */
    public $dir;

    /**
     * @param string $dir optional, default value is current
     */
    function __construct( $dir = '' ) {
      if ( ! empty( $dir ) ){
        $this->dir = trailingslashit( $dir );
      } else {
        /** __DIR__ is actually equivalent to 
         * realpath(dirname(__FILE__)) and Added in PHP 5.3.0
         * Bellow line will also work 
         * for php  5.2.4 (WordPress required php  5.2.4 or greater )
         */
        $this->dir = trailingslashit( ( @__DIR__ == '__DIR__' ) && define( '__DIR__', realpath( dirname( __FILE__ ) ) ) );
      }
      spl_autoload_register( 
          array( $this, 'spl_autoload_register' ) );
     }

    /**
     * @param string $class_name
     */
    function spl_autoload_register( $class_name ) {
      $class_path = $this->dir . strtolower( 
       str_replace( '_', '-', $class_name ) ) . '/class-' 
       . strtolower( str_replace( '_', '-', $class_name ) ) . '.php';
      
      if ( file_exists( $class_path ) ){
        include $class_path;
      }
    }
  }
}

/**
 * Initiate Loader class
 */

$obj_rt_wp_loader = new RT_WP_Autoload();
Add admin to glotpress

Add admin to glotpress

Following is the script to add admin to glotpress php scripts/add-admin.php user-name Before run script, check you have configured database properly.

PHP readdir() return false even if permission are right

PHP readdir() return false even if permission are right

Today (So many times ) i face directory read issue using php. If you are trying to read a directory and readdir function is returning false even if php user have right permission (At least read permission) to that directory mainly while your server is […]

register_taxonomy reserved terms

register_taxonomy reserved terms

There are some reserved word for register taxonomy. If you are passing the term through the $_GET or $_POST array. Doing so can cause WordPress to respond with a 404 error without any other hint or explanation.

Following is the code snippet to check reserved terms.


//Forbidden attribute names
//http://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms
$reserved_terms = array(
            'attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and', 'category__in', 'category__not_in', 'category_name', 'comments_per_page', 'comments_popup', 'cpage', 'day', 'debug', 'error', 'exact', 'feed', 'hour', 'link_category', 'm', 'minute', 'monthnum', 'more', 'name', 'nav_menu', 'nopaging', 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm', 'post', 'post__in', 'post__not_in', 'post_format', 'post_mime_type', 'post_status', 'post_tag', 'post_type', 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 's', 'search', 'second', 'sentence', 'showposts', 'static', 'subpost', 'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id', 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'type', 'w', 'withcomments', 'withoutcomments', 'year',);

if ( in_array( $taxonomy_name, $reserved_terms )){
    $error = sprintf( __( 'Slug “%s” is not allowed because it is a reserved term. Change it, please.' ), $taxonomy_name );
}
PHP CodeSniffer – Coding standards

PHP CodeSniffer – Coding standards

PHP CodeSniffer scan PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. To install phpcs on ubuntu pear install PHP_CodeSniffer To list all installed coding standards phpcs -i I found great article on rtCamp site. you can read it […]

12 String guitar String gauge

12 String guitar String gauge

String Gauge 1st .010 2nd .010 3rd .014 4th .014 5th .023 6th .009 7th .030 8th .012 9th .039 10th .018 11th .047 12th .027