Search This Blog

Thursday, December 8, 2011

How to do a “git export” From Command Line


git archive

git archive master | tar -x -C /somewhere/else

If you want a compressed archive .

git archive master | bzip2 >source-tree.tar.bz2

ZIP archive

git archive --format zip --output /full/path/to/zipfile.zip master

Thursday, December 1, 2011

Setting Up Name Based Virtual Hosting In Ubuntu

1. Append the following line to your /etc/apache2/apache2.conf .
     NameVirtualHost 127.0.0.2:80
2 . Create unique files for each of my domains within the /etc/apache2/sites-available/ folder.Create a fie called mysitename.com

<VirtualHost 127.0.0.2:80>
ServerName 
mysitename.com
ServerAlias www.
mysitename.com
ServerAdmin me@ubuntu.com
DocumentRoot /var/www/mysitename/html
</VirtualHost>


3. Enable it by creating a symbolic link from one folder to the next ( etc/apache2/sites-enabled/)

sudo a2ensite mysitename.com ( to diable it anytime sudo a2dissite  mysitename.com)  

harder way to create the symbolic link 

cd /etc/apache2/sites-enabled/
ln -s ../sites-available/
mysitename.com .


4. Editing the /etc/hosts by adding the following line

127.0.0.2:80 mysitename.com 

5. Restart apache sudo /etc/init.d/apache2 restart

****

To enable mod_rewrite in Ubuntu, you just need to write this command in terminal

sudo a2enmod rewrite

Monday, November 28, 2011

Add And Update JSON Array Using Jquery

    

Tuesday, November 8, 2011

Validate numbers in JavaScript - IsNumeric()

A simple function to find if a positive number
function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

Saturday, October 29, 2011

How to create virtual host In XAMPP in windows

1.Create a folder in C:\xampp\htdocs\mysite
2. Edit your hosts file in windows  located in C:\WINDOWS\system32\drivers\etc\ and add following line
127.0.0.1 mysite.localhost
Don’t delete the existing “127.0.0.1 localhost” line
3.Open your C:\xampp\apache\conf\extra\httpd-vhosts.conf file and add the following lines

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs"
    ServerName localhost
</VirtualHost>


<VirtualHost *:80>
    ServerName mysite.localhost
    DocumentRoot C:\xampp\htdocs\mysite
    <DirectoryC:\xampp\htdocs\mysite>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
4. Reboot your computer .You should now be able to access each dev domain by way of:
http://mysite.localhost/

Wednesday, October 12, 2011

Get phpunit coverage report for a single class

If you want to get the phpunit coverage report for a single class you can use --filter setting with the --coverage option.
phpunit --coverage-html ./report --filter InsuranceStatusEligibilityFilterTest PluginAllTests.php

Wednesday, October 5, 2011

How to remove or edit external svn repositories


svn gedit svn:externals ./

Gedit is the editor that you will see the external repository information, do the nessasary change and save to change the edit external svn repositories

Sunday, September 18, 2011

JQuery Check if element is checked and make it checked

if($('#cbxEmployeeFamily_'+planId).is(':checked')){
             
             $('#cbxEmployeeFamily_'+planId).attr('checked', true);
         }

Wednesday, July 20, 2011

Easy way to get days of current quarter in php



Pass the frequency and current date to get an array of dates.

eg.
getDatesForYear(4,'2011-01-01');
the array you get will have the following dates
"2011-04-30","2011-08-31","2011-12-31"




public function getDatesForYear($monthlyFequency,$date){

$dateParts = explode("-",$date);

 $firstDayOfTheYear = $dateParts[0] . '-01-01';

 $lastDayOfTheYear = $dateParts[0] . '-12-31';
 
 $i = $firstDayOfTheYear;

for(strtotime($i);strtotime($i)<=strtotime($lastDayOfTheYear);) {
 
 $accruDate[] = date('Y-m-d',strtotime($i . " +$monthlyFequency months  -1 day ")) ;
 $i =  date('Y-m-d',strtotime($i . " +$monthlyFequency months"));
 } return $accruDate;
 }

Friday, July 8, 2011

Thursday, May 19, 2011

Print all form errors in a symfony form

foreach($form->getWidgetSchema()->getPositions() as $widgetName)
{
  echo $form[$widgetName]->renderError();
}


or you can use

$this->form->getErrorSchema();

Monday, May 2, 2011

Installing Apache, PHP, MySQL on Ubuntu


Install Apache 

Open Terminal (Application -> Accessories -> Terminal) and execute the following command:
sudo apt-get install apache2

check if the Apache is working properly by pointing your browser to http://localhost. If you see the text “It works!”, it means Apache is working.

Issue the following command to resolve following error Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

sudo  gedit /etc/apache2/conf.d/fqdn

When Gedit opens, type “ServerName localhost” inside the file and click Save

Install PHP



Inside Terminal, execute the following command:
sudo apt-get install php5 libapache2-mod-php5

execute this to restart apache

Execute the following command in Terminal:
    sudo /etc/init.d/apache2 restart

Install MySql

sudo apt-get install mysql-server



Inside Terminal, execute the following command:
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Give the root password to complete the installation


Setting up phpunit in ubuntu



  1. Install PEAR . Issue the command sudo apt-get install php-pear.
  2. Make sure PEAR is up to date. Issue the command sudo pear channel-update pear.php.net
  3. Upgrade the PEAR elements. Issue the command sudo pear upgrade-all.
  4. Tell PEAR where to find the PHPUnit code. Issue the command sudo pear channel-discover pear.phpunit.de
  5. Install PHPUnit. Issue the command sudo pear install -a phpunit/PHPUnit. The -a makes sure all dependency packages are also installed.
  6. Issue the command phpunit --version. You should have version 3.3.17 or newer installed.
  7. Install XDebug. Issue the command sudo apt-get install php5-xdebug. This is needed if you want the HTML based coverage reports. 
  8. Restart the web server after installing this package. (sudo /etc/init.d/apache restart ).
reference 

Saturday, April 30, 2011

Best way to create a CSV file in PHP

I have seen many php scripts trying to create CSV's using strings and adding commas inside a for loop. But this method is prone to errors since it doesn't work properly with special characters like comma and quotation. This function use php fputcsv to create a CSV file in the server memory rather than the disk making its faster to retrieve the CSV file.

$headerArray = array('Mon','Tue','Wed') ;
$bodyArray = array(array(1,2,3),
array(4,5,6));


function makeCsv($headerArray,$bodyArray) {    

        $headerIncluded = false;
        $fp = fopen('php://temp/maxmemory:' . (5 * 1024 * 1024), 'r+'); // 5MB of memory allocated 

        $content = $bodyArray;

        foreach ($content as $row) {

            if(!$headerIncluded) {
                $headerIncluded = true;
                fputcsv($fp, $headerArray); // create the csv file in the memory
            }
                fputcsv($fp, $row);
        }

        rewind($fp);

        $output = stream_get_contents($fp); // get csv file from the memory

        fclose($fp);        

        return $output;
    }


Get terminal in right click context menu in ubuntu

If you want to get the open a folder in terminal by just right clicking on a folder run this command as the super user.
sudo apt-get install nautilus-open-terminal

Wednesday, March 16, 2011

Find Year difference in SQL


YEAR(CURRENT_DATE)-YEAR('1971-01-01') as years_now


Find Future Date from PHP

date("Y-m-d", strtotime(date('Y-m-d') . " +6 month"));

Tuesday, February 22, 2011

How to Exclude a tag from css class

form#frmBilling  label:not(.formRadio){
 width: 140px;
}


The above width will be applied to all the labels in the form except
labels with the class formRadio.

Tuesday, February 15, 2011

How to get svn diff file and apply patch file

Get as a patch file

>svn diff -r 6738:6739>mychange.diff

apply the patch file

>patch -p0 -i mychange.diff

How to get a svn diff form a specific revision

If you want to get the changed file list

>svn diff -r REVNO:HEAD --summarize

example

>svn diff -r 6738:6739 --summarize

Get as a patch file

>svn diff -r 6738:6739>mychange.diff

apply the patch file

>patch -p0 -i mychange.diff

Monday, February 7, 2011

How to Export and Import MySQL Db dump from command line

Go to the command line as root or admin user


Export the database

mysql -u UserName -p password databaseName > dbdump.sql


Import the database

mysql -u UserName -p password databaseName < dbdump.sql

Sunday, January 30, 2011

Command To Show the enabled modules in apache

sudo apache2ctl -l

Enable mode rewrite in apache2 ubuntu

This command works fine in ubuntu ,login as the root and type the following command to enable mode_rewrite.

sudo gedit /etc/apache2/sites-available/default


In the following section change AllowOverride None to AllowOverride All.


 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 allow from all
 # Uncomment this directive is you want to see apache2's
 # default start page (in /apache2-default) when you go to /
 #RedirectMatch ^/$ /apache2-default/



use rewrite rules

sudo a2enmod rewrite



Restart Apache


sudo /etc/init.d/apache2 restart

Friday, January 28, 2011

Wednesday, January 5, 2011

Date validation Java Script

function isValidDate(txtDate) {
           var objDate;  // date object initialized from the txtDate string
           var mSeconds; // milliseconds from txtDate

           // date length should be 10 characters - no more, no less
           if (txtDate.length != 10) return false;

           // extract day, month and year from the txtDate string
           // expected format is YYYY-mm-DD
           // subtraction will cast variables to integer implicitly
           var day   = txtDate.substring(8,10)  - 0;
           var month = txtDate.substring(5,7)  - 1; // because months in JS start with 0
           var year  = txtDate.substring(0,4) - 0;


          // third and sixth character should be /
           if (txtDate.substring(2,3) != '-') return false;
           if (txtDate.substring(5,6) != '-') return false;

          // test year range
           if (year < 999 || year > 3000) return false;

           // convert txtDate to the milliseconds
           mSeconds = (new Date(year, month, day)).getTime();

           // set the date object from milliseconds
           objDate = new Date();
           objDate.setTime(mSeconds);

           // if there exists difference then date isn't valid
           if (objDate.getFullYear() != year)  return false;
           if (objDate.getMonth()    != month) return false;
           if (objDate.getDate()     != day)   return false;

           // otherwise return true
          return true;

    }

Sunday, January 2, 2011

Bring a HTML Div to the center of the page


This is an easy way of making a div center of the screen. Width and margin-top will make it properly at the center of the screen.