Search This Blog

Tuesday, February 15, 2011

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.

Thursday, December 16, 2010

How to download files in Symfony

Its very easy to download files in symfony. Create a proper action and do something like this , i have assumes that files are stored in the database and its a pdf file. But you can assign any file by storing the file type in the database.



public function  executeDownloadFile(sfWebRequest $request) {
        $yourfileData = '' // get your file data from the database
        $this->getResponse()->clearHttpHeaders();
        $this->getResponse()->setHttpHeader('Content-Disposition',
        'attachment; filename='. 'myfile.pdf');
        $this->getResponse()->setContentType('application/pdf');
        $this->getResponse()->sendHttpHeaders();       
        $this->getResponse()->setContent($yourfileData);

        return sfView::NONE;

}

If you need to set http headers 

private function setHttpHeaders($size, $fileName, $contentType='application/csv') {
        $this->getResponse()->clearHttpHeaders();
        $this->getResponse()->addCacheControlHttpHeader('Cache-control', 'private');
        $this->getResponse()->setHttpHeader('Content-Description', 'File Transfer');
        $this->getResponse()->setContentType($contentType, TRUE);
        $this->getResponse()->setHttpHeader('Content-Length', (string) $size, TRUE);
        $this->getResponse()->setHttpHeader('content-transfer-encoding', 'binary', TRUE);
        $this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename=' . $fileName, TRUE);
        $this->getResponse()->sendHttpHeaders();
    }

Tuesday, December 14, 2010

Recursively deletes subversion .svn folders in ubuntu

First we find the .svn folders, then we use rm to remove those folders . There are 2 methods to do this.Type this in shell


Method -1

$ find . -name ".svn" -exec rm -rf {} \;
Method -2

$ rm -rf `find . -type d -name .svn`

Sunday, December 5, 2010

Save new record or Update a record if it exist using Doctrine object

Are getting error when you save a doctrine object saying primary key violation?
Before you save the object you must search if its already there. When you use find it uses the primary key.

public function saveFamilyDetails($form) {

$employeeFamilyDetails = Doctrine::getTable('EmployeeFamilyDetails')->find($form['txtFamilyID']);

        if(!($employeeFamilyDetails instanceof EmployeeFamilyDetails) ) {
            $employeeFamilyDetails = new EmployeeFamilyDetails();
        }

        $employeeFamilyDetails->employee_id       = $form['txtEmpID'];
        $employeeFamilyDetails->fm_name       = $form['txtFamName'];
        $employeeFamilyDetails->relationship       = $form['txtFamRelationship'];
        $employeeFamilyDetails->date_of_birth        = $form['txtFamDob'];
        $employeeFamilyDetails->address        = $form['txtFamAddress'];
        $employeeFamilyDetails->mobile_no      = $form['txtFamMobileNo'];
        $employeeFamilyDetails->residence_no    = $form['txtFamRecidenNo'];
        $employeeFamilyDetails->workcon_no   = $form['txtFamWorkConNo'] ;
        $employeeFamilyDetails->dependent      = $form['txtFamDependant'];
        $employeeFamilyDetails->nric_fin    = $form['txtFamNricFin'] ;
        $employeeFamilyDetails->passpot_no   = $form['txtFamPassport'] ;

        return $employeeFamilyDetails->save();



    }