Category Archives: Software Development

How To: Move a docker container to another host

Saving this here for future reference.

If you wan’t to move a container that you’ve set up (i.e. from development to production) and you don’t yet want to push it to docker hub, here’s a way to move it:

  1. Export the container to a tarball
    docker export <CONTAINER ID> > /home/export.tar
  2. More your tarball to the new machine
  3. Import it back
    cat /home/export.tar | docker import – some-name:latest

Installing and using the AMQP PECL extension

After spending two fairly painful days refactoring some code away from PHPAMQPLib (some custom PHP classes that allow for a connection with RabbitMQ) and moving to the official PECL extension I thought I’d document. Let me know if this has helped you!

First of all you need to get a compatible version of the rabbitMQ C library, as the version shipped with Ubuntu 11.10 and 12.04 are not compatible with the PECL extension.

sudo su
apt-get install mercurial
hg clone
cd rabbitmq-c
hg clone codegen
autoreconf -i 
make install

and then it should just be a case of installing the PECL extension as-per-the-usual-way:

pecl install amqp

I’m hoping to follow this up with some AMQP examples, as the manual is pretty much “function declaration only” at this point and there are very few examples out there. Stay tuned.

Adding a custom resource type to the Zend Framework autoloader

I’m working on a new project using the latest Zend Framework. I’ve got a modular application and decided that I wanted to hold my module-specific logic classes in their own ‘logic’ subdirectory.

Setting up class to folder mappings is done inside ‘Zend/Application/Module/Autoloader.php’ in the function ‘initDefaultResourceTypes’. In here you’ve got your standard mappings like ‘Form’ => ‘forms’, ‘Model’ => ‘models’ etc.

You’ve either got the choice of overriding this class with your own implementation, or you add your own resource types by putting the following code in your application or module bootstrap:

class MyApp_Bootstrap extends Zend_Application_Module_Bootstrap
     * Add some custom resource types to the resource loader
     * @return void
    protected function _initLoaderResource()
            'logic' => array(
                'namespace' => 'Logic',
                'path'      => 'logic'

This will make the autoloader look inside the logic subdirectory for any classes with the namespace ‘MyApp_Logic’

Zend Framework Tool – project already exists here

When using the Zend Framework tool to create directory structures and some basic classes, you might come across the message “An error has occurred. A project already exists here”. A quick Google search found a couple of other people reporting this issue but no solution.

The problem occurs because by default the project provider searches all parent directories for a .zfproject.xml project configuration file. In my case I’d created a testing project further up the directory tree and neglected to delete it – this was fooling the tool into thinking a project already existed.

…which makes sense – you wouldn’t normally have a project inside a project (although you can’t rule out that somebody wants to do this)

Two solutions:

either look for a ZF project file in your parent directories:

find /path/to/htdocs -name '.zfproject.xml'

or, modify the code to search only the current directory if you have a directory structure that the tool doesn’t like

diff --git a/Zend/Tool/Project/Provider/Project.php b/Zend/Tool/Project/Provider/Project.php
index c24af5e..d3d75ea 100644
--- a/Zend/Tool/Project/Provider/Project.php
+++ b/Zend/Tool/Project/Provider/Project.php
@@ -61,7 +61,7 @@ class Zend_Tool_Project_Provider_Project
             $path = str_replace('\\', '/', realpath($path));
-        $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE, $path);
+        $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE, $path, false);
         if ($profile !== false) {
             require_once 'Zend/Tool/Framework/Client/Exception.php';

ZF create project diff

The simplest way to apply this patch in Linux is to use the command:

patch Zend/Tool/Project/Provider/Project.php < createprojectfix.txt

Note: your mileage may vary – this was the cause of my particular issue, but it’s possible this happens for other reasons.

Updating the GUI from another thread made easy


I’ve found out to my absolute horror that even simple operations done in a background thread that need to update the interface are required to force those interface calls back into the same thread as the interface was generated in…

With a bit of research, I found out that this was done with the Invoke method. Initially, I created what felt like hundreds of delegates/functions to handle each control’s update, but now, although this solution I have posted could be better, it is a decent timesaver at least for me, so hopefully it will help someone else…

Basically, what we have below is a static class (ThreadSafe.cs) that has some delegates such as SetText(Control, string) that lets you set the text of any control with some text. The following example is rather basic, but there are numerous others in ThreadSafe.cs such as adding items to listviews, changing checkbox check states etc. Give it a look.

Here is a basic example for changing the Text property of a control.


ThreadSafe.SetText(this.whateverControl, "text to change");

couldn’t be easier.

The Delegate

public delegate void SetTextDelegate(System.Windows.Forms.Control ctrl, string text);

This defines the signature of the SetText method.

The Method

public static void SetText(System.Windows.Forms.Control ctrl, string text)
    if (ctrl.InvokeRequired)
        object[] params_list = new object[] { ctrl, text };
        ctrl.Invoke(new SetTextDelegate(SetText), params_list);
        ctrl.Text = text;

There are also classes and inherited classes for other controls, listviews, buttons, comboboxes etc., that should save you time writing your thread-safe GUI code. Hope this helps someone. If it does or for help, please leave a comment!

Download Helper Class

ThreadSafe helper