Sunday 14 June 2015

Parse YouTube Time Code PHP

Parse YouTube Time Code PHP





I am sharing my PHP code to parse YouTube time.


<?php

function covtime($youtube_time)
{
    $start = new DateTime('@0'); // Unix epoch
    $start->add(new DateInterval($youtube_time));
    return $start->format('g:i:s');
}
echo date("H:i:s");
echo "<br>";
echo covtime('PT2H34M25S'); // => 2:34:25
echo "<br>";
echo date("H:i:s");
echo "<br>";
preg_match_all('/(\d+)/', "PT2H34M25S", $parts);
echo "<br>";
echo date("H:i:s");
echo "<pre>";
print_r($parts);

?>

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

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...