Tailing the latest Apache error log

•January 5, 2011 • 2 Comments

When debugging web server errors, my first instict is to check Apache’s error logs.
After navigating to the apache error log directory, I just tail the error log.
While this should be relatively simple, when Apache rotates the logs it can be a
little more cumbersome because we have to find which log is the most recent.
This usually involves the following steps (assuming we are in the directory that
contains the Apache error logs):
Continue reading ‘Tailing the latest Apache error log’

PHP Remove Empty Array Elements

•December 3, 2010 • Leave a Comment

I’ve had multiple occasions when I encounter an array with empty elements that need to be skipped or removed before further parsing can continue.
A simple for loop will work, but that seems a little excessive since PHP has a ton of array functions.

Lets start off with a sample array:
Continue reading ‘PHP Remove Empty Array Elements’

Ubuntu Force Kill App

•November 11, 2010 • 1 Comment

We all have the frustrating moments when an app isn’t responding, and you have to force it to close.
Most of the time the app can typically be found in the System Monitor:
Continue reading ‘Ubuntu Force Kill App’

CodeIgniter Query with Single Result/Single Row

•November 4, 2010 • 1 Comment

I’ve been asked this question more than once, so I decided to post it just in the case it can help some one out.

There are many occasions where you have a method that does a single row database query through CodeIgniter and just needs to return a single scalar value.
Continue reading ‘CodeIgniter Query with Single Result/Single Row’

PHP 5.3 Anonymous functions as iterators

•October 29, 2010 • Leave a Comment

In my recent experimentation of the new 5.3 anyonymous functions, I’ve come up with a custom iterator as a proof of concept:

Continue reading ‘PHP 5.3 Anonymous functions as iterators’

Digging into the PHP 5.3 SplDoublyLinkedList (part 2)

•October 28, 2010 • 7 Comments

After our first entry, I wanted to take some time to show some example usage of the SplDoublyLinkedList since the documentation is very minimal at the present time.

Lets start with following code:
Continue reading ‘Digging into the PHP 5.3 SplDoublyLinkedList (part 2)’

Digging into the PHP 5.3 SplDoublyLinkedList (part 1)

•October 27, 2010 • Leave a Comment

During my recent adventures of exploring the new offerings of PHP 5.3, I dug into the SplDoublyLinkedList class.

It appears as if the main strength of SplDoublyLinkedList is the memory usage, with all the nifty functions as an extra benefit. I decided to write some quick tests to compare the memory usage with the standard array population techniques.

Our first tests use the standard array population techniques:
Continue reading ‘Digging into the PHP 5.3 SplDoublyLinkedList (part 1)’

Currying with PHP 5.3

•October 26, 2010 • 2 Comments

In my recent adventure of exploring the new anonymous functions of PHP 5.3, I started experimenting with currying.

Here is my implementation:

function curry(){
    $args = func_get_args();
    $func = array_shift($args);
    $want_array = array_shift($args);
    return function() use ($func,$args,$want_array) {
        return $want_array === TRUE
            ? $func(array_merge(func_get_args(),$args))
            : call_user_func_array($func,array_merge(func_get_args(),$args)); 
    };
}

Continue reading ‘Currying with PHP 5.3’

Solaris gzip directory (5.10)

•October 16, 2010 • Leave a Comment

I know there is more than one way to skin a cat, but this one worked for me and its easy to understand.

To gzip the foo directory in Solaris:

tar cpf - foo > foo.tar && gzip foo.tar

Oracle PL/SQL 10g MD5 String

•October 15, 2010 • 1 Comment

I had the need for a MD5 signiture using PL/SQL, and couldn’t find any definite answers without tedious searching (maybe I’m looking in the wrong places).

Here is how to use the DBMS_CRYPTO package to MD5 a string in 10g:

 SELECT dbms_crypto.hash(utl_raw.cast_to_raw('foobar'), 2) FROM dual;