2012
08.18

While applying some (550) changesets I needed some good tools to show me the differences between files and revisions.

The first one I found very useful was:

svn diff --diff-cmd diff -x -uw -r REV1:REV2 FILE;

which is even better in combination with colordiff:

apt-get install colordiff;
svn diff --diff-cmd diff -x -uw -r REV1:REV2 FILE | colordiff;

An other great tool is vimdiff, which starts Vim as usual, and additionally sets it up for viewing the differences between files. Here’s how I use it:

sudo apt-get install vim;
vimdiff -O -c 'set diffopt+=iwhite,filler' FILE1 FILE2;

Some of you will probably prefer Meld, which is a visual diff and merge tool.

To combine the powers of all three I created a simple (Bash) wrapper. It downloads two revisions (svn) of a file and compares them using a diff tool of choice:

#!/bin/bash
#
# set -x;
#
if [ -z "${1}" ] || [ -z "${2}" ] || [ -z "${3}" ]; then

  echo "";
  echo "Use the script as discribed below:";
  echo "$0 [ filename ] [ revision1 ] [ revision2 ] [ diff tool (optionally) ]";
  echo "";

else

  pid=$$;

  filename="${1}";
  revision1="${2}";
  revision2="${3}";
  diff_command="${4}";

  temp1="/tmp/${pid}.${revision1}.${filename}";
  temp2="/tmp/${pid}.${revision2}.${filename}";

  trap trap_function 0 1 2 15;

  trap_function()
  {
    if [ -f "${temp1}" ]; then

      rm "${temp1}";

    fi

    if [ -f "${temp2}" ]; then

      rm "${temp2}";

    fi
  }

  svn cat "${filename}" -r "${revision1}" > "${temp1}";
  svn cat "${filename}" -r "${revision2}" > "${temp2}";

  if [ "${diff_command}" == "vimdiff" ]; then

    vimdiff -O -c 'set diffopt+=iwhite,filler' "${temp1}" "${temp2}";

  elif [ "${diff_command}" == "meld" ]; then

    meld --diff "${temp1}" "${temp2}";

  else

    diff -uw "${temp1}" "${temp2}" | colordiff;

  fi

fi
2012
08.18

Recently I needed to install PHPUnit to write some test for an application I was working on. Here I will describe how I installed it on Ubuntu.

First of all, you’ll need to install PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0.

apt-get install php5-dev php-pear

Subsequently you’ll install PHPUnit through the PEAR installer. To do that run the following:

pear upgrade PEAR
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit

After the installation you can find the PHPUnit source files inside your local PEAR directory; the path is usually /usr/lib/php/PHPUnit.

2012
08.18

Because deleting rules in UFW can be a little bit annoying this little trick will make your life much easier. Instead of using this syntax:

ufw delete allow 80/tcp

use this syntax:

ufw delete ####

where #### is the number of your firewall rule.

The numbers of your firewall rules can listed using:

ufw status numbered

A possible output could be:

Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 80/tcp                     ALLOW IN    Anywhere
[ 2] 443/tcp                    ALLOW IN    Anywhere