• Bash completion for fabric

    As I was doing a routine migration of a WordPress site this morning I was looking at the fabric menu ( fab -l ) that had grown painfully long. And I wondered: “Would’nt it be nice if I counld just be typing the first letter in he fabric task and then hit tab to get the rest of it?”

    Google next, and there on GitHub, just the thing I needed: Fabric-completion.

    Enter Salt master, edit my user state, state.highstate, and voila: Fabric bash completion 🙂

    It works for task aliases as well 😉

  • Local .vimrc for projects

    Thanks to Johan Westin that tipped me about this page 🙂
    See vimninjas.com for the whole article.

    Create a file called “vimrc-local.vim” in the ~/.vim/plugin/ directory. After that, put the following 5 lines of code in it:


  • Your Vagrant/Puppet development environment does not work on your friends pc?

    Reacently I shared a development environment with a colleague. When he started up the vm he got an error message stating that some settings where incorrect from vagrant (sorry, I don’t have the message to paste in here). When he ran the vm from the VirtualBox gui he got this error message:

    It turned out my colleatues pc did not support hardware virtualization and thus could not use 64 bit vms. No big deal, he switched to use lucid32.box instad and everything was fine 🙂

  • How to import (revert) views in Drupal 7.x

    Developing web applications using CMS like Drupal may be chalanging when there are more than one developer working on the same project. Source code is managed easily with Git (or other VCS), but the database content must be treated with care. Either you go for a relay baton method: One developer updating the database at the time and all other must get new dumps after the update, or you can export / import features stored in the database.

    I wanted to try the latter with Drupal Views, and could not find any documentation that worked out-of-the-box with my project so here is what I ended up with:

    Create a new module
    See Creating modules – a tutorial: Drupal 7.x

    Export view(s)
    Export whatever views you want to be able to import (revert). From the views list (admin/structure/views) you should be able to select “Export” on the views you want to export.
    This will display PHP code in a textarea. You should copy the contents and paste it in a file, say named view.my_exported_view.inc.
    Remember to add “<?php” on the first line.

    My example files
    Here is my modules/viewsimport/viewsimport.info file:

    Here is my modules/viewsimport/viewsimport.module file:

    Here is my modules/viewsimport/viewsimport.views_default.inc:

    Some of the articles I stumbled over:

  • Fake php time on your ubuntu server

    Some time it is necessary to fool your PHP application to test functionality related to a “current date”.

    Fooling php cli is simple using faketime:

    Say you have this PHP script:

    Rendering this script with php through faketime will give you results like this:

    The same can be achieved using the datefudge command:

    Faking time for a webapplication

    Faking time for a web application is not that simple since apache will fork a process for each request and thus create a new php processes.
    In this post I will show you how to use FakeTime Preload Library to fake time system wide while running tests on a web application.

    First I need to install faketimelib as described on the librarys homepage.
    In short:

    For the demonstration I will use a php script like this:

    Running this script should yield something like:

    Now I create a file in my home folder, faketimerc, with a new future time. I will use this file in different ways to show how I can manipulate the time.

    If you now create an environment variable, FAKETIME, give it a future time, and running the same script would yield something like this:

    As you can see, the processes you run while the environment variable is set to a future time will get a fake time. Once the variable is unset new processes will get normal time.

    This can be achieved also by creating a file. “.faketimerc” in your home folder:

    If you want to change time for a php application that runs though apache you may want to set the fake time system wide so that the php processes spowned use the faked time. To do this you need to create a file, /etc/.faketimerc, just the same as the one I created in my home folder.

    I will use w3m for this demonstration. I assume a normal ubuntu server with apache2 installed.

    As you can see, the date command and when rendering the script with php, gives me the fake time, but when rendering the script through apache I loose the fake time. This is because the environment variable LD_PRELOAD is not set for the apache process.

    To fix this I need to set LD_PRELOAD for apache by editing /etc/apache/envvars. Lets test it again:

    Fake time! 🙂

    PS! If you also want your PostgreSQL server to use fake time:

  • Veewee and ubuntu-10.04.3

    You want to create a VirtualBox with Ubuntu 10.04.3 using Veewee, but there is no ubuntu-10.04.3 template?

    Here is what you can do:

    Download (git clone) a copy of veewee from GitHub and copy the templates.

    To verify that you have the new templates:


  • Bash completion and git prompt

    Recently I discovered that the virtual server I was working on did not give me the usual bash completion I’m so used to on my Kubuntu workstations. Working on git repositories and upgrading web applications made this to an itch I just had to scratch.

    After a bit of searching it appeared that I was missing a file: /etc/bash_completion. Next I discovered that there is a /etc/bash_completion.d/ directory and under this a file named ‘git’. I copied the bash_completion file from my workstation and followed the instruction in /etc/bash_completion.d/git and suddenly I had bash completion and a prompt that gave me branch name and the status of the git repository I was currently in.

    Just to give you a hint, here is the comment from the /etc/bash_completion.d/git file: