Easy way to install PHPUnit

Unit Tests are the living description on how the Unit should work, and ensure that your own Creation is working in that way you wanted to. To write unit test cases in php, I would recommend you to go for PHPUnit. I will tell you an easy way if you are going for a manual installation.

The way of manual installation mentioned in PHPUnit manual is as follows:

  • Download a release archive from http://pear.phpunit.de/get/ and extract it to a directory that is listed in the include_path of your php.ini configuration file.
  • Prepare the phpunit script:
    • Rename the pear-phpunit script to phpunit.
    • Replace the @php_bin@ string in it with the path to your PHP command-line interpreter (usually /usr/bin/php).
    • Copy it to a directory that is in your PATH and make it executable (chmod +x phpunit).

I was bit confused while going through above steps as they mentioned :p.

Easy Method (in linux & mac):

  1. Download a release, extract it (no matter where). And find the phpunit.php inside the extracted folder.
  2. In terminal, change directory to /usr/bin then create symbolic link to phpunit.php and name it phpunit.In case you don't know here is the syntax,

sudo ln -s <absolute_path-to-phpunit.php> phpunit

Happy coding!

Sql and cache tracking in local development for django

While developing django applications, did you ever get confused about the unexpected result by the query generated by ORM and wished to check that query? There is a good solution. I have a habit of watching #django at times and thats how I got to know about this. Its django-devserver. Package is available here - http://github.com/dcramer/django-devserver/. After installing(with dependancies) you need to include devserver in INSTALLED_APPS in your settings file as:

INSTALLED_APPS = (
    'devserver',
)

and also you have to add a new tuple in settings as DEVSERVER_MODULES. This is for specifying which all modules to load.

DEVSERVER_MODULES = (
    'devserver.modules.sql.SQLRealTimeModule',
    'devserver.modules.sql.SQLSummaryModule',
    'devserver.modules.profile.ProfileSummaryModule',

    # Modules not enabled by default
    'devserver.modules.ajax.AjaxDumpModule',
    'devserver.modules.profile.MemoryUseModule',
    'devserver.modules.cache.CacheSummaryModule',
)

You will have to use python manage.py rundevserver instead of python manage.py runserver to run your development server. Then you will get additional informations like real-time SQL-Loggings and a summary of your cache calls

Go through the Read Me file before installing.

NB:- Beware - your terminal may get spammed by the sql-logs :p

Happy coding!

The script

I am not gonna tell about some scripting languages, but script.

script is a GNU project which is a simple terminal application which can log the activities in a terminal with their outputs. To start script, you just have to give script in your terminal. Then you will see a message saying Script started, file is typescript (If you have to mention filename, then give script <filename> ). Once you finished up with everything which needs to be logged, just press ctrl-d or exit and that will exit script with a message script done, file is typescript(or filename you seleced). For the better view of the log, use cat or more.

It is helpful to show somebody a log about what you have done in terminal. This terminal logger is quite a simple and useful application right?

Script

GNU screen: The Terminal Multiplexer

Are you a terminal/konsole freak? Then you might be knowing it else you will love it.

At times most of us used to face the worst scenario that a single terminal window with hell lot of tab opened or multiple terminal windows itself. Do you need anything else to hang urself?

A simple & humble solution - screen :) Most of the linux distros comes with screen installed by default. 

Most effective usages - The basic usage I have already told you. And another interesting one is here. Did you ever think about terminal sharing? screen can be used somewhat like desktop sharing.

To start screen, all you have to do is just type screen On your terminal. You can create any number of windows in a single screen. To create new screen, you have to give ctrl-a c and a simple ctrl-d (logout) will end the current window. ctrl-a n & ctrl-a p to switch between next & previous windows. ctrl-a N will give you an option to enter window number & switch to that window. ctrl-a " will list all the windows, you can use arrow keys to select.

Terminal Sharing: start screen from machine A, from machine B ssh to A and then use screen -x to get into the already started screen. From both machines it is able to use the same screen in real time just like VNC for remote desktop.

In short it is a terminal application which allows any number of terminal application in single terminal window & single screen can be accessed from multiple terminals ;)

other options for screen is shown in the image:

Screen

What the FSCK!

"Oh god! My filesystem gone mad... Hey linux can U do any FSCK?"
Hey its just FSCK! that is File System Check.
Only unix could give an FSCK. It is used to repair unix filesystems. A bit more intelligent than chkdisk in windows. Advantage is it will run on multiple physical drives in parallel to reduce time consumption. It runs automatically at the boot time. But in some cases a super user may have to manually run it. It will automatically fix the errors on your filesystem or let the user know what & where the problem is. You have lots of options to run fsck. Check FSCK manpage for the detailed description on its features/options to run it.We can run it to check the whole filesystem in different partitions or you can even mention the partition. fsck --help output is here in the image.

Fsck