Add a PHP Post-Commit-Hook to your SVN

Snippets, Software development, Tools, Tutorials November 10th, 2009

This is just a link to a very good tutorial on how to make your own SVN post-commit hook using a PHP script. It sends the following information via email:

  • Committer name
  • Commit message
  • List of files edited
  • Diff of changes made

http://techchorus.net/writing-php-script-send-svn-commit-changeset-email-notification

Quick PHP Hack to Tidy up Trashed HTML

Snippets, Tools September 21st, 2009

I just hacked together the following quick and dirty PHP-script to use the tidy-extension from the command line. Maybe somebody else needs something like this somewhere. Check the comment for details:

<?php

//
// (a) Save this as tidy.php
// (b) Call it from commandline like this: $ php tidy.php trashed.html > tidy.html
//     to tidy the file trashed.html to a new file tidy.html.
//

// Installation and configuration see http://php.net/tidy
$config = array('indent'=> true, 'output-xhtml' => true, 'wrap'=> 200);

$tidy = new tidy;
$tidy->parseString(file_get_contents($_SERVER['argv'][1]), $config, 'utf8');
$tidy->cleanRepair();

echo $tidy;

Install PEAR on OSX

Snippets, Tools, Uncategorized September 9th, 2009

Here is how you install PEAR on Mac OSX:

sudo mkdir /usr/local/temp;
sudo chmod -R 777 /usr/local/temp;
sudo mkdir /usr/local/share/pear;
sudo chmod -R 777 /usr/local/share/pear;
curl http://pear.php.net/go-pear | sudo php;

Set /usr/local as path prefix and install.

You should then be able to use pear, e.g.: pear help.

In order to install modules you also need a temp dir:

sudo mkdir /usr/local/temp;
sudo chmod 0777 /usr/local/temp/;

You can now install PHPUnit:

sudo pear channel-discover pear.phpunit.de;
sudo pear install phpunit/PHPUnit;

Have Fun!

Consistent Development Environments using VirtualMachines

Linux, Software development, Tools July 30th, 2009

As a development team we always run into situations where we have trouble setting up a proper development environment for each of the team members to get going or add new staff on the go. It annoyed me every time since it causes a lot of unnecessary communication and friction.

I often heard of virtualization but never actually played seriously with it. The idea is:

If we could have a virtual machine for every project that contains an equivalent environment like the production system, everybody working on it…

  • … could just rely on his development environment by just starting the VM without having to set up anything half-baked themselves.
  • … could use his favourite working environment OS, IDE and tools on which they are most comfortable and thus happy and productive.
  • … could work on their own checked out working copy using version control.
  • … could immedately see what they built refreshing the local browser or starting Unittests on the VM via ssh to check their dev increments.

We used http://www.virtualbox.org. A good starting point to get to know VirtualBox better and learn how to start your first virtual machine: https://help.ubuntu.com/community/VirtualBox

Our target was to be able to startup the development VM as guest system on any developers development machine being the host system, open a browser on the host (!) and call for example http://develop/ to see the webroot of the VM. Additionally we set up samba and ssh on the VM in order to have the webserver’s webroot on the VM available via the filesystem. In order to do that you need to…

  • …start your VM with networking set to ‘Host interface’ instead of the default NAT. This is explained in detail on this page (sorry German) http://www.nwlab.net/tutorials/virtualbox/virtual-networking.html - for me it was tricky to get the guest machine available on the host and have internet access at the same time.
  • …edit the hosts file (on OSX ’sudo nano /private/etc/hosts’ and reboot) on the development machines and add something like the following line: ‘192.168.56.101 develop’. To find out the IP enter ’sudo ifconfig’ (OSX/Linux) on your host system after you have started the VM. You will see aditional adapters set by virtualbox and the IP address.
  • …configure /etc/samba/smb.conf on the VM, restart samba and connect (e.g. smb://develop/webroot). We check out a working copy of the applicaton under development directly onto the webroot and create a new PHP-Project there in our IDE. Update and commit directly from there.

If you search the web for ready-made VMs you find mostly VMware images. You can not run them directly in VirtualBox and need to convert them.

Under Linux you can convert the VMware image (.vmdk) into a VirtualBox image (.vdi) like this:

sudo apt-get install virtualbox-ose virtualbox-ose-guest-utils;
sudo apt-get install qemu;

qemu-img convert xxx.vmdk xxx.bin;
VBoxManage convertdd xxx.bin xxx.vdi

Install the required packages with apt-get install once. VBoxManage is part of VirtualBox. The last two lines do the conversion.


We ended up creating a fresh install from a Debian 5 netinstall iso. The iso-file can be mounted as CDROM on the creation of the new VM with VirtualBox. Receipes for setting up the appropriate LAMP environment with apt-get install can be found on the web. You only have to do it once. Save the state of your VM afterwards.


There are ways to generate a virtual machine from a physical server. Use Google to find receipes. I used http://www.partimage.org on a Debian Etch system with the live CDROM from http://www.sysresccd.org. This requires that you are able to umount your filesystem or rather boot into the live cd on the production/staging machine in order to generate the partimage.

You mount an external drive over the network or a usb harddrive. The partition (e.g. /dev/sda1) you would like to backup must be umounted. From the live cd you can see your partitions, including attached usb drives, with the ‘fdisk -l‘ command. Just mount the target (e.g. /mnt/usbdrive) and start partimage from the commandline. Dialogues guide you through the image creation.


In case you wonder what is meant by the ‘Host key’ to enter or leave a running VM with your mouse… it is the right (!) Strg-Button on your Keyboard.


I just installed Ubuntu Server on a VM from my MacBook. To have a usable keyboard once you logged on to the new VM, you must do the following in order to have a keymap including the pipe symbol, braces etc.:

  • sudo apt-get install console-data; #to install the keymaps
  • sudo loadkeys mac-macbook-de; #to set the keymap for German MacBook

Once you have done that, you can use your right Command-Key as ‘Alt-Gr-Key’ like on a PC keyboard. The pipe symbol is then typable with ‘Alt-Gr + >’, Braces and Brackets are typable via ‘Alt-Gr + 6,7,8,9′.


This is how you copy a virtual machine using VirtualBox tools:

$ VBoxManage clonevdi /Users/marco/MyMachine.vdi /Users/marco/MyMachine_copy.vdi
$ VBoxManage internalcommands setvdiuuid /Users/marco/MyMachine_copy.vdi

Free XSD Editor - Generate XSDs from XML

Software development, Tools, Tutorials June 28th, 2009

From an old post: To start out with XML-Schema this might be of interest to you:

XSD-Tutorial: http://www.liquid-technologies.com/XsdTutorial_01.aspx

Free graphical Tool: http://www.liquid-technologies.com/LiquidXMLStudio.aspx

[2009-06-27] Update: A very cool feature is the generation of a Schema, based on example-XML files you give Liquid XML Studio! I discovered this when I built a Schema that would not validate against my desired XML structure and I could not figure out why. I generated the XSD like this:

  • Open one of your XML examples with Liquid XML Studio.
  • Select from the menu “Tools / Infer XSD Schema”.
  • You are asked for more examples. I did it with just one XML file.
  • And bingo: You have your XSD.

As I did a diff of my handcraftet version of the XSD and the generated one, it revealed the reason for not validating nicely for me ;).

Cool tool, you can use with the 30-day trial licence.

Bulk Image Resize using Conditional Width

Linux, Productivity, Snippets, Tools April 4th, 2009

I am currently working on a project in which we have lots of images from an old CMS waiting to be migrated into a new layout. Of course there are restrictions so it should not happen that certain image types exceed a certain max. width.

OK, we have many many images… So I took a closer look at ImageMagick (also take a look at the usage examples). And I have to say: Awsome!

You can install ImageMagick on Ubuntu or Debian with a simple
# apt-get install imagemagick

In combination with a bit conditional scripting I came up with the following solution:

Console doing bulk resize.

Console doing bulk resize.

I wanted to have a shell script that, given a directory containing all our images, checks the width of each image and resizes it if it exceeded a certain width. Simple, but powerful.

Usage:

$ ./resize_image_dir.sh ../../brand_logos

And you are done with thousands of images in a minute. Do not forget to make a backup if designers change the desired width later…

You can download the shell scripts with example images ready to test:
!resize_conditional_images_bulk2

Frameworks…

Articles, Software development, Tools March 13th, 2009

Find out interesting thoughts and experiences about the selection and usage of a frameworks for your projects in this set of slides ‘Living with Frameworks‘ by Stuart Herbert, Technical Manager at www.gradwell.com.

You will learn about:

  • How frameworks save you time (=money) and ensure quality but can also waste resources if applied in another way the framework was intended to be used.
  • The importance of the framework guru role.
  • That a chosen framework and architecture should be strategically introduced (top-down).
  • Introduction and proper use of a new framework has a steep learning curve.
  • Legacy code and the parallel maintenance hassle.
  • Refactor early, refactor often, perform regular code reviews with the framework guru.
  • Frameworks will not fix bad practice (specification, quality, no training).
  • Your framework should fit your overall development plan and practice.
  • Training your staff in your framework is a means of building your team.
  • Headcount on projects has increased, means more teamwork, organisation around needs to mature too.
  • Importance of upgrades and backward compatibility.

A Simple PHP Google Sitemap Generator

Read-Write-Web, Snippets, Tools, XML February 26th, 2009

I just hacked together a very simple class and CLI script to help me generate Google sitemap XML on a daily basis using PHP. If you have not yet heard of it: Google sitemaps help you promote your content if you have certain deep links that only show up if a visitor for example performs a search and clicks a result.

Check the documentation of the Google Sitemap Format

Here is the code: Google Sitemap Generator

It works like this:

$ php generate_gsitemaps.php; #will generate your standard sitemap
$
php generate_gsitemaps.php -e > my_sitemap.xml; #echo sitemap xml to another file

Example: generated_example_sitemap.xml

Have fun being found!

Etherpad

Productivity, Tools February 15th, 2009

EtherPad is a free webbsased editor which lets people remotely and simultaneously edit the same text document. Just click ‘Create new Pad‘ and you see the URL which you can send to your remote friend(s).

etherpad_screen

Use it for group development on code snippets, catch realtime meeting minutes, brainstorming ideas and many things more…

Thanks AppJet for this nice tool!

Frontend Tool- and Hint-Collections

Articles, Layout, Tools January 29th, 2009

I have just discovered the tools section of the Smashing Magazine with very interesting articles like these ones:

And there are many more!

Hippie Completion in Eclipse

Productivity, Tools January 24th, 2009

I was using a factory like this

$factory = new Object_Factory();
$curr_object = $factory->create('brand');

to generate instances of objects I needed and wondered why Eclipse could not auto-complete e.g. getters and setters in my code for me later on for the $curr_object. My productivity and my motivation to type all that stuff were seriously suffering…

So I found a very nice solution: Hippie Completion!

Instead of listing possible completion solutions like with Strg-Space the

key-combo “Alt-/” (/ on the number block!)

just completes what you started typing. You can also press Alt-/ as many times you like to page through all terms you could have meant like with the Strg-r on the console.

In case you try and wonder why it is not working like expected right away: Precondition for the hippie completion in Eclipse is, you typed the term to be completed once before!

Why didn’t anyone tell me this cool one before!

Planning Poker for better Estimates

Articles, Software development, Tools January 11th, 2009

There are many essays and articles on ‘Planning Poker’ out there. So I do not need to repeat the principles here. By checking out the recommended links (and folloups and others from your own research) you need to understand the following:

  • What a story point of a project looks like and how you generate those story points in advance. Remember, your estimation should include design, coding, testing and delivery. In Planning Poker it is your goal to come up with estimates to those those story points with your team.
  • The process of how one story point is estimated using the Planning Poker card deck and how to narrow down your team members’ estimates through discussion of the ‘played’ estimates.
  • The background of the card deck used and why there are such odd numers in it.
  • The effect all this will have to your project and the team.

The important thing is not the single estimate as such, but rather the open discussion among the the team members in advance, the mix of different perspectives and the collection of confidence in the team’s estimates. If the team is not able to get confident for an estimate you better recheck the user story in question and clarify it - possibly again with the customer. The more confident the team in one estimate is (=no big spread in single estimates of the team members), the less unclear ‘assumptions’ have been made in the estimate itself. This, in the end, reduces the overall risk (friction and interruptions) during the actual project and most importantly makes your customer happy.

Recommended articles and links:

Subversion Repository on Samba Share

Linux, Tools December 22nd, 2008

I use a Subversion repository which sits on a Samba share in our LAN. Most of the times I used it from Windows machines where I simply assigned a drive letter (N:\) to the filesystem of the network share (//TERASTATION2/share) hosting the repository. A SVN checkout including URL looked like this:

  • svn co file://N:/_repos/projectname/trunk .

Now I have my new Ubuntu/Linux notebook and asked myself how I could use the repository from there too. I tried using smb://terastation2/share/_repos/myproject/trunk - but this did not work in combination with file://.

The solution looks like this:

  • Create a dir to mount the share to: $ sudo mkdir /mnt/terastation2;
  • Mount the filesystem: $ sudo smbmount //TERASTATION2/share /mnt/terastation2 -o lfs;
    (You can create a launcher to do that for you in the future)
  • Then you can do your desired operations: $ svn co file:///mnt/terastation2/_repos/projectname/trunk .;

Alternative du - gt5, visual harddisk usage

Linux, Tools October 29th, 2008

gt5 is a handy shellscript that extends the linux command du (disk usage). It can be run from the console or remotely over ssh. Nothing to be installed. It uses GNU tools like head, sed, awk and lynx. It generates html which is then passed to lynx to be displayed.

You can install it via: sudo apt-get install gt5

You will also find screen shots at: http://gt5.sourceforge.net

Browsershots

Software development, Tools October 27th, 2008

Browsershots loads a given URL, using different browsers on different OSses and generates a screenshot for each one. You can also specify window size, JavaScript-ing and Flash version. Simply enter your URL and wait until your ‘job’ has been processed. Finally you will see a screen like the one on the left.

http://browsershots.org

Import .dbf File Contents into MySql

Snippets, Tools October 23rd, 2008

I had a bunch of .dbf (source was Lotus Approach) files, at which I wanted to shoot SQL-like queries to generate some meaningful reports. So there were 2 tasks to be accomplished:

  1. Read the data into a tool or database and
  2. formulate and perform the queries to generate results to base your reports on.

As of opening and saving, I first tried MS Access. But some of the tables could not be imported (reasons unknown). Then I tried to open those files with MS Excel. It worked, but I had more than 65536 records per table, so I could not actually use Excel. After some investigation I came across dbftools which promised to help me converting the data into a text-based format.

I simply unpacked the C source and typed ‘make’ from the console and I had a working dbf2txt binary. I created a directory with all the dbf-files in it and hacked together the following simple shell script: convert.sh

#!/bin/bash
for i in data/*.dbf
do
dbf/src/dbf2txt -v "$i" > "$i.txt";
done

It supplied me with all txt-files each containing a table with fieldnames in line 1 and the data in tab-separated format. Nice!

To get this data into MySql, I hacked this little tab2sql script which converts the txt-files into SQL statements. It is called like this:

$ php tab2sql.php data/my_table.dbf.txt > sql/my_table.dbf.txt.sql;

You can then dump all sql-files in the sql-dir into MySql via:

$ for dir in data/*.sql; do mysql dbf_import -h localhost -u root < “${dir}”; done;

Thanks Frank Koormann for the dbftools!

Sidenote: If you have big tables and you plan to work with joins… Do not forget to set field-types and indices properly after the import! This could otherwise stress your machine.

Subversion: Revert to a Previous Revision

Snippets, Tools October 15th, 2008

On one of my current projects, I had the problem that I had done several commits to the repository and suddenly changed my mind and wanted to go back to a certain point in the revison history where I started with my changes. How would you do that?

Let’s say you started your changes at revision 901 with your first commit and the current revision (HEAD) is 910.

To your working-copy you could just do:

svn up -r 900 .

But that would bring back the unwanted changes to you as soon as you update again and would not affect other people working on the code when they update their workig copies to the current revision. What you really have to do in this case is to ‘merge back’ your working-copy and then commit the changes with a comment:

svn up;
svn merge -r HEAD:900 .;
svn commit -m "Reverted back to rev 900. Sorry, changed my mind.";

Be careful! This only works if ALL revisions (901-910) have been committed by yourself.

Generate Random Passwords

Linux, Tools July 25th, 2008

Here is a tool which generates loads of random passwords: pwgen.

On Debian you can install it with ‘apt-get install pwgen’.

Google Shell

Tools July 17th, 2008

For those who like working on the terminal, this wrapper for Google-Search is a must: http://goosh.org

Help of Goosh

It emulates a shell-like interface in your browser.

Short intro:

  • ’s webdev-notepad’ - performs a search
  • ‘m’ - shows more results after you searched for something
  • ‘video pigor’ - searches for videos of pigor
  • ‘gmail’ - lets you log into GMail
  • it even saves a history of your commands

Play with it!

Tool: Convert Type1 Mac-Fonts into OpenType

Layout, Mac, Tools June 25th, 2008

Case: Build a dynamic template from a PSD file including graphical text headlines and navigation. The PSD was originally built on Mac containing Mac Type 1 fonts, which I could not use on my Windows machine to edit the text in the layout. After a bit of searching I found a tool to do the conversion into TTF/OTF:

FrossFont: http://www.asy.com/sharecf.htm