Sunday 14 June 2015

Common GIT Commands for New Developers

Common GIT Commands for New Developers

GIT commands

I am sharing my knowledge about some common GIT commands which may helpful for someone.

* initialize git instance
git init 

*  add origin
git remote add origin [GIT-URL]

*by default branch 
master

* pull direct from url
git pull url master

* create new branch branch1
git checkout -b branch1

* push new branch to origin
git push -u origin branch1

* see current branches
git branch

* see all branches
git branch -a

* reset code to previous pull
git reset --hard

* reset code to specific commit hash
git reset --hard [COMMIT-HASH]

* fetch all branches
git fetch --all

My suggestions to new developers, make habit using GIT GUI to push any code on the repository instead of directly using command line commands. If you very expert of GIT commands then only use command line otherwise you may any such code which can break production environment and put you in trouble.


For more information on GIT branches check GIT Website.

Sunday 7 June 2015

GTMetrix Settings For Website Speed

GTMetrix Settings For Website Speed

I am sharing some website performance optimization information by quickly editing .htaccess file on the server to speed up faster website pages and rapid improve website performance issues.

Make sure mod_deflate and mod_expires modules are enabled.

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType text/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

Go to GTMatrix website and verify your website speed.

PHPMD Code Review Tool Command WAMP

PHPMD Code Review Tool Command WAMP

I am sharing my code review command to verify PHP syntax and code using PHPMD tool. May this be helpful for someone.

To install PHPMD from GIT, use below command:

~ $ git clone git://github.com/phpmd/phpmd.git

Below command takes PHP file to review and outputs review file

~ $ phpmd [PHP FILE PATH] codesize,unusedcode,naming --reportfile [OUTPUT-FILE]

My Example Command is below: 

C:\wamp\www\phpmd\vendor\bin> phpmd D:\\modules\ xml codesize,unusedcode,naming --reportfile c:\wamp\www\phpmd\code-review

Monday 1 December 2014

How to Fast Loading Websites

How to Fast Loading Websites

I am sharing some rules or tips to make website loading faster and improve website performance and decrease bandwidth.
  • Rule 1 - Make Fewer HTTP Requests – image mapping, css sprite, inline css, inline images, inline css images
  • Rule 2 - Use a Content Delivery Network  - images, css, and scripts on CDN
  • Rule 3 - Add an Expires Header  - it really helps
  • Rule 4 - Gzip Components - its really make website speed double faster
  • Rule 5 - Put Stylesheets at the Top
  • Rule 6 - Put Scripts at the Bottom
  • Rule 7 - Avoid CSS Expressions
  • Rule 8 - Make JavaScript and CSS External
  • Rule 9 - Reduce DNS Lookups
  • Rule 10 - Minify JavaScript
  • Rule 11 - Avoid Redirects
  • Rule 12 - Remove Duplicate Scripts
  • Rule 13 - Configure ETags
  • Rule 14 - Make AJAX Cacheable

Sunday 30 November 2014

Mailchimp Integration CodeIgniter


Codeigniter MailChimp API v2 Wrapper

I am sharing my Codeigniter Code regarding Mailchimp integration. May this small code can be helpful for someone.

Reference - https://github.com/benbowler/codeigniter-mailchimp-api-v2



<?php 

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or - 
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */

    public function __construct() {
        parent::__construct();
        $this->load->library('Mailchimp_library');
    }

    public function index()
    {       
        $list_id = '';
        $lists = $this->mailchimp_library->call('lists/list');
        if(isset($lists["data"][0])) {
            $list_id = $lists["data"][0]["id"];
        }
        if(!empty($list_id)) {
            $result = $this->mailchimp_library->call('lists/subscribe', array(
                'id'                => $list_id,
                'email'             => array('email'=>'sourabhgupta3838@gmail.com'),
                'merge_vars'        => array('FNAME'=>'Sourabh', 'LNAME'=>'Gupta'),
                'double_optin'      => false,
                'update_existing'   => true,
                'replace_interests' => false,
                'send_welcome'      => false,
            ));
            print_r($result);
        }
        $this->load->view('welcome_message');
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

MySQL Stored Procedure Tutorial

MySQL Stored Procedure Tutorial

I am sharing an example of MySQL stored procedure.

DELIMITER $$

USE `company`$$

DROP PROCEDURE IF EXISTS `update_t`$$

CREATE DEFINER=`root`@`%` PROCEDURE `update_t`(OUT last_id INT(11),OUT last_url 
VARCHAR(200))
BEGIN    
    SELECT company_id,company_url INTO last_id,last_url FROM company 
    ORDER BY id ASC LIMIT 0,1 LOCK IN SHARE MODE;
    UPDATE company SET cc=1 WHERE company_id = last_id;
    END$$

DELIMITER ;

Sphinx Search Engine installation WAMP

Sphinx Search Engine installation WAMP



 Here is my environment:

  • Windows
  • WAMP
  • Apache 2.2.11
  • MySQL 5.1.36
  • PHP 5.3.0
  • Sphinx 1.10
First of all download Sphinx for Windows which can be found (http://sphinxsearch.com/downloads/beta/).

Sphinx creates a separate index of the table you want to search. Your PHP scripts calls the Sphinx API to search connecting to a specific port where Sphinx is listening to. Sphinx then searches its own index and does the search returning the result. Yes, the index has to be updated every time your update your original table. 

Once you have created sphinx.conf in the bin folder copy the content from c:\sphinx\sphinx-min.conf.in (this is their provided sample file). It looks like:
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
 type   = mysql

 sql_host  = localhost
 sql_user  = test
 sql_pass  =
 sql_db   = test
 sql_port  = 3306 # optional, default is 3306

 sql_query  = \
  SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS
  date_added, title, content \
  FROM table

 sql_attr_uint  = group_id
 sql_attr_timestamp = date_added

 sql_query_info  = SELECT * FROM table WHERE id=$id
}

index test1
{
 source   = src1
 path   = @CONFDIR@/data/test1
 docinfo   = extern
 charset_type  = sbcs
}

index testrt
{
 type   = rt
 rt_mem_limit  = 32M

 path   = @CONFDIR@/data/testrt
 charset_type  = utf-8

 rt_field  = title
 rt_field  = content
 rt_attr_uint  = gid
}

indexer
{
 mem_limit  = 32M
}

searchd
{
 listen   = 9312
 listen   = 9306:mysql41
 log   = @CONFDIR@/log/searchd.log
 query_log  = @CONFDIR@/log/query.log
 read_timeout  = 5
 max_children  = 30
 pid_file  = @CONFDIR@/log/searchd.pid
 max_matches  = 1000
 seamless_rotate  = 1
 preopen_indexes  = 0
 unlink_old  = 1
 workers   = threads # for RT to work
}
These settings should cover most of what you're looking for in terms of setting up Sphinx.

Code in PHP script:
require_once('sphinxapi.php');
//Sphinx
$s = new SphinxClient;
$s->setServer("localhost"9312);
$s->setMatchMode(SPH_MATCH_EXTENDED2);


Sphinx commands:

C:\wamp\www\sphinx-2.2.3-beta-
win32\bin>indexer.exe --config c:\wamp\www\sphinx-
2.2.3-beta-win32\sphinx.conf.in test1

C:\wamp\www\sphinx-2.2.3-beta-win32\bin>searchd.exe --install --config c:\wamp\w
ww\sphinx-2.2.3-beta-win32\sphinx.conf.in --servicename SphinxSearch

Create .ICS file using PHP code

Recently worked on creating a .ics file in PHP after a very long time, code so thought to share with everybody. Please find below the comple...