PhpUnit and XDebug

If you would like to debug one of your command line scripts using PHPUnit then you need to export one of the XDEBUG_CONFIG values. I read one post about this (unfortunately lost the link and cannot place it here as a reference) the general idea was to export the configuration for XDEBUG and then run phpunit as you would normally do.
So, let’s say that you are using PHPStorm as your IDE then the script would be:

#!/bin/bash

export XDEBUG_CONFIG="idekey=PHPSTORM";
phpunit $@

If you name the script phpunitx then the only thing that you would need to do to run PHPUnit from the command line with XDEBUG enabled would be to invoke phpunitx instead of phpunit.

Postgres clusters and cluster upgrades

Postgres has the ability to create clusters of databases that run on the same machine concurrently. One thing that I did not know about postgres is that you can also run multiple versions of postgres at the same machine concurrently along with the mutliple clusters mentioned earlier. But how can one view information about all these instances and clusters and how can we connect to each of them and how can one upgrade the clusters running on one version to another?

I am running Debian on my personal computer and the rest of this post is going to be a very brief description of how I managed to upgrade and tidy up after my postgres instances running on my local computer. Please note that this is not an in depth post nor I suggest in any way this approach for a live / production upgrade of postgres.

So let’s get started!

First of all let’s see which versions of postgres are running on our box. As a super user execute the following command

Continue reading “Postgres clusters and cluster upgrades”

How to start Chromium with specific user

As you may already know it is possible to create different profiles for Chromium. You can find out more information about that in http://www.chromium.org/user-experience/multi-profiles.

What I was really interested to find out was how can I start Chromium with one of these profiles, instead of using the last one that was loaded. The answer can be found here: http://superuser.com/questions/377186/how-do-i-start-chrome-using-a-specified-user-profile. Unfortunately the man page for chromium does not list the specified option so it was really nice to find this question in superuser.com! But let me just give an example of how to use it under Linux.

Continue reading “How to start Chromium with specific user”

Phing CopyTask

Phing is a PHP build tool that you might be familiar with or you might be already using. The official Phing website can be found at http://www.phing.info/ and the initials stand for PHing Is Not GNU make. You can download or install it as a PEAR package and as long as you are a bit familiar with XML it is really easy to learn how to use. So, if you are reading past this point it means that you have actually used Phing before and that you are familiar with its CopyTask for copying individual files or filesets from one location to another.

Recently I was trying a new build file with Phing and came accross an interesting issue. The result of building a target that included copying a previously defined fileset from one location to another had a somewhat unexpected  result. An empty folder that was contained in the source location for which all users had read, write and execute permissions on, was copied accross but the permissions were not kept. I was not receiving any errors and the folder was actually created in the destination folder. As it turns out the version of Phing that I was using did not support copying an empty folder with its permissions to a new location. So if you are having a similar issue do upgrade your  package to the 2.5.0 version of Phing (as of the time of writting this is the latest stable release of Phing on PEAR). You can perform the upgrade quite easily as you would with any other PEAR package.

JQuery textarea text limit counter

This is slightly different implementation of the jquery textarea text limit counter found at: http://www.scriptiny.com/2012/09/jquery-input-textarea-limiter/. The main difference is that the user is not cutoff when he reaches the limit of the allowed characters but he is notified via the counter that his text is longer than expected.

The idea behind it is to have a textarea that accepts user input and there is  a limit in the characters that you want you are allowed to type in the textarea. While you type in characters in the textarea a counter is updated that shows the remaining characters. The number is correct even when you reload the page and the area is pre-populated with text. This particular demo uses jquery 1.5.1

Continue reading “JQuery textarea text limit counter”

How to set/unset options in Vim

Vim is a very powerful text editor and as such it has lots of options which allows you to configure it “just right” for you! In order to configure it you can set up values to its various options either in the current window you are working on or in configuration file so that every new instance launched will have common settings. This file is usually called vimrc and is located under your home catalog.

But what happens if you wish to reset the value of an option you have configured in this configuration file for just this window that you are currently working in? I found that to be more difficult than expected so, here is how you can:

  1. Start a clean instance of vim with all its default options that ignores all the settings in all the user defined configuration files
  2. Get the currently set options and their values
  3. Disable/reset options that I will call switches
  4. Reset any option to each default value (whatever that might be)
Continue reading “How to set/unset options in Vim”

How to disable the pager in PostgreSQL

PostgreSQL uses a pager to display the results of an operation you performed when you are using the command line tool (psql).

You can disable the pager by issuing:

pset pager off

with which you specifically request that the pager is disabled. You can re-enable the pager by issuing:

pset pager on

with which you specifically request that the pager is enabled. Alternatively you can toggle the status of the pager by issuing

pset pager

which depending on the current status of the pager will either enable or disable it.

PHP: The Scope Resolution Operator (::)

In PHP the Scope Resolution Operator (which is actually the double colon or Paamayim Nekudotayim as it is its official name) has many uses. From the PHP manual pages (Manual) I quote

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class. When referencing these items from outside the class definition, use the name of the class.

So, I recently decided to go ahead and test this operator in a bit more detail and discovered something I did not know about the way PHP decides to give you access to its public methods.
Let us consider the following php class

Continue reading “PHP: The Scope Resolution Operator (::)”

Vertical display output in MySQL and Postgresql

When using the command line clients of MySQL or Postgresql it is often the case that the output of some select statement does not display very well, either because the query returns too many columns or the contents of a column are too long. In such cases it would be really nice to display the query results line by line in a vertical listing instead of the horizontal listing. A similar display can be found in both MySQL and Postgresql. So, let’s assume that you have a table that was created with the following SQL statement:
Continue reading “Vertical display output in MySQL and Postgresql”

How to add Captcha verification in the comments of the Yii blog demo

This post is about adding captcha verification in the comments section of the Yii demo blog. This post was triggered from two comments posted on the page of the tutorial (Comment 1 and Comment 2). In order for you to follow through the current post you need to have the Yii framework in place and you need to have followed all the steps of the Blog Tutorial up untill the “Creating and Displaying Comments” section. So, let’s start:

If you have followed the tutorial you should by now have a working Leave a comment form in place that is displayed underneath each individual post of your blog web application. The form should contain the Name, Email, Website and Comment fields that will populate the corresponding properties of your Comment model. The Post ID should be set on submit, the Status of the Comment should also be set on submit and the Time Created should be set just before saving the Comment (if this is a newly created comment).

Continue reading “How to add Captcha verification in the comments of the Yii blog demo”