sudheer's blog

Generate Lines Of Code And Comment Statistics Using phploc

You have been writing a lot of PHP code and want to generate statistics about the number of comment and code lines in your application. Maybe you want to generate statistics about some PHP project. You can do it with just one command.

phploc helps you quickly generate numbers about the size of a PHP project.

You can install phploc from the PEAR installer. The PHP PEAR package itself is most likely available from your distribution vendor.


Tip Of The Day: Avoid Forgetting Adding Files To SVN Repository

If you are using subversion (SVN) for your source code management you may have come across this situation.

  1. You add some files to your working copy
  2. You use the command 'svn add ' to add files to the be versioned
  3. You commit using the command 'svn commit -m "message"'
  4. When other users of your project update their working copy they find some files missing

You forgot to add certain files to the repository. It happens every now and then.


Tip Of The Day : Use A Data Generator

While developing applications creating test data can be a tedious process to the developers. You don't have to do the same things like creating a user for testing over and over again.

Use a data generator. There are numerous tools freely available online that can provide the test data for you.


Tip Of The Day : Use dict

Have you fallen in love with the command line? Do you use a graphical browser to visit dictionary sites like wiktionary.org?

Use dictd.

What does dictd do?

[sudheer@localhost ~]$ yum info dictd
Loaded plugins: fastestmirror, refresh-packagekit
Installed Packages
Name       : dictd
Arch       : i386
Version    : 1.10.11
Release    : 3
Size       : 728 k
Repo       : installed
Summary    : DICT protocol (RFC 2229) command-line client
URL        : http://www.dict.org/
License    : GPL+ and zlib and MIT


How To Configure Yum To Exclude A Mirror

Many of us have suffered from failing package repository mirrors. Some are slow, some won't have updated content, etc. You might want to remove/blacklist a particular mirror in your yum configuration.

Before trying to remove a mirror, install the fastest mirror plugin.

yum install yum-fastestmirror -y

The fastest mirror plugin is capable of determining mirror speeds and cache it. If that works for you well and good.


How To Set SVN_EDITOR Environment Variable To Vim

Problem: You are trying to use the command svn propedit svn:externals and you are receiving the error:

svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found

Solution: Set vim as your SVN_EDITOR

Command:

export SVN_EDITOR=vim

To permanently set this environment variable put the below line in your ~/.bash_profile file.

export SVN_EDITOR=vim

Did it solve your problem?


How To Print The PHP Version In A PHP Script

Somebody recently asked me how to print the PHP version from within the PHP script. The answer is very simple and requires only two words to print the PHP version. Here is the script


<?php
echo PHP_VERSION;
?>

PHP_VERSION is a predefined constant. It contains the value of the PHP version.

A sample output is as follows.

[sudheer@localhost cli]$ php php_version.php 
5.2.6
[sudheer@localhost cli]$ 


PHP Script To Shorten URLs Using short.ie

We all know about the URL shortening service offered by many websites. Most notable among them is tinyurl.com. There are also other free URL shortening services available on the Internet.

In this post, I will show you how to generate a short URL link to any URL from a PHP script using the short.ie URL shortening service. The actual code is only about ten lines. We will make use of the Zend_Http_Client component of the Zend Framework.


OpenOffice.Org Won't Launch

I encountered this annoying issue today. OpenOffice.Org won't lunch at all. Clicking the OpenOffice.org icon from the GNOME panel application menu and clicking on a ODS file in nautilus had the same results. I could see the window information 'starting openoffice.org' on the bottom GNOME panel. It would soon disappear.

To troubleshoot the issue, I updated the system. There were new OpenOffice.org-* packages available. Updating the packages didn't fix the issue.


Exporting MySQL Data To CSV In PHP

Do you want to export data stored in a MySQL database to CSV file?

The solution is damn easy if you already know how to connect to MySQL database and read or display data from a PHP script. Let's start working on it.

Let us first create a sample table. In our example scenario, let us create a table to store contact information.

CREATE TABLE `contacts` (
`first_name` VARCHAR( 50 ) NOT NULL ,
`middle_name` VARCHAR( 50 ) NOT NULL ,
`last_name` VARCHAR( 50 ) NOT NULL ,
`email` VARCHAR( 320 ) NOT NULL ,
`phone` VARCHAR( 20 ) NOT NULL
) ENGINE = MYISAM;


Syndicate content