Archive for the ‘Tech’ Category

Conditional tasks in Ant

Thursday, February 28th, 2013 | Programming, Tech

If you’re using Ant build scripts, there is a good chance that you will want to do some tasks conditionally – for example, if you’re using CI you will want to run your unit tests every time some code is committed – but you might only want to regenerate documentation or update a stakeholders’ preview build every night.

There is a lot of talk about conditional tags, but all these really allow you to do is set even more variables. You can use if/then/else from Ant-Contrib but that involves adding extra libraries and complicating the issue.

Actually, it turns out it is really simple to set up conditional tasks in your build process. All you need to do is call the task, but in the task header use the if attribute.

For example, I have a build task which calls all the other tasks.

<target name="build" depends="clean,checkout,nightly,phpunit,documentation" />

Even though I’m running this every time, I’m calling the “nighty” task. Below shows how I define that.

<target name="nightly" if="${env.NIGHTLY}">

Finally, in my Jenkins CI install, I make the project a parameterised build, and add a boolean called NIGHTLY that defaults to false. I can then also trigger a build by cron that specifies the NIGHTLY parameter as true, so that when it runs on a night, it runs the additional tasks as well.

MacPorts mysql5-server not working on boot

Friday, February 22nd, 2013 | Life, Tech

If you’ve installed MacPorts’ mysql5-server, you may find that it doesn’t work after a restart.

This can be resolved by running the following commands to make sure you’ve killed off everything MySQL related.

sudo port unload mysql5-server
ps -ax | grep mysql
sudo kill 

Once you have done this, load it again.

sudo port load mysql5-server

Not it should be working. This is fine, but quickly gets very annoying every time you restart your computer! A common cause is that you have a MySQL sock file in your tmp directory. Removing this may allow it to start automatically.

cd /tmp
rm -f mysql.sock

Once removed, restart your computer and see if MySQL works first time – hopefully, it will.

Install an MSI from a user account

Wednesday, February 20th, 2013 | Life, Tech

Sometimes you might want to install an MSI on your Windows system, without being logged in as an administrator. Normally, you would just right click and select “Run as Administrator” but this option is not available on MSIs.

Instead, right click on “Command Prompt” in the start menu, then select “Run as Administrator”. Once this is running, use the msiexec command to execute the MSI.

msiexec /i Filename.msi

This will then run the installer using administrative privileges.

Twitter spam

Monday, February 18th, 2013 | Tech

I’m drawing a line across the emails that Twitter continue to send me.

For months and months they have continued to send me updates on what is going on, what people have saying, stuff that isn’t even an interaction with me. Every single time I get such an email, I click the unsubscribe found at the bottom of the email, and Twitter.com appears to tell me I will no longer receive that kind of notification.

But I continue to get them.

No matter how many times, no matter how many different notifications I turn off, they find some new category to send me emails. So enough is enough. Any future emails are getting forwarded to MailFoundry’s spam monitor address and flagged as spam in my own email client.

Hack Day

Sunday, February 17th, 2013 | Tech

Recently, Sky did a hack day – the idea was that you could take a day to work on any project you wanted, as long as it was vaguely business related. Then at the end of the day, everyone came together to demo what they had done.

It was a cool idea, and most people really enjoyed it, though I was fairly non-plussed. I couldn’t get my project working, on a number of angles, so didn’t really have much to show by the end of it (I had a demo, but as I couldn’t integrate it into the product, I didn’t think it worth showing). I think if I had actually worked for Sky though, I would have been far more motivated by such an event.

Data missing from MySQL replication due to column mismatch

Saturday, February 16th, 2013 | Life, Tech

If you are running MySQL replication, you may find that the structure of a table is brought over, but not the data. You can troubleshoot this by logging into the slave MySQL and showing the status.

SHOW SLAVE STATUS \G;

You may find an error similar to the following.

Table definition on master and slave does not match: 
Column 1 size mismatch - master has size 150, example_db.test_table 
on slave has size 50. Master's column size should be <= the slave's column size.

This is usually caused because you are using different character sets. In the example above, the master is set to UTF8 (utf8_general_ci) while the slave database is set up in Latin1. You can fix this in two ways (and should probably do both).

First, to change the database, log into phpMyAdmin and go to the operations tab. Here you change it from the dropdown and then hit save.

Secondly, you should change the default charset in MySQL to be UTF8 (you could also change it to Latin1 if that is what your master is running but in this day and age, everything should really be running UTF8). You can do this by editing your my.cnf.

[mysqld]
default-character-set=utf8

After editing it, you will need to restart MySQL. Any databases created from then on will default to UTF8.

Installing Imagick on Ubuntu 12

Sunday, February 10th, 2013 | Programming, Tech

To install Imagick, you would normally do this via PECL.

sudo pecl install imagick

However, when trying this on Ubuntu 12.04 LTS, you may get an error similar to the following.

checking ImageMagick MagickWand API configuration program...
configure: error: not found. Please provide a path to MagickWand-config or Wand-config program

You can resolve this by installing a few extra packages.

sudo apt-get install libmagickwand-dev libmagickcore-dev

Now try re-running the original command and it should be successful.

No acceptable C compiler found on Mac

Monday, February 4th, 2013 | Programming, Tech

If you’re trying to compile from source, you may get an error similar to the following.

mac configure: error: no acceptable C compiler found in $PATH

This may be because you haven’t installed Xcode. If you have, something has broken, and you need to reinstall it. First, remove it with the following command.

mac configure: error: no acceptable C compiler found in $PATH

Now restart your system and once it has started again, go to Applications and select Install Xcode. This will reinstall it.

Gregory

Wednesday, January 30th, 2013 | Limited, Tech

gregory

To solve the problem of lots of different scrums wanting to release at the same time, we recently introduced a “release token” – some item that you had to have in your possession to allow you to release – and if you didn’t have it, you couldn’t release anything, thereby preventing conflicts.

Enter Gregory, the Release Bear.

Unfortunately, it was soon felt that tracking down a bear every time you wanted to do a release was too tiresome. So, after only a few days in the job, Gregory was retired in favour of a digital token. Unlucky, Gregory.

Restarting Apache on Gentoo

Tuesday, January 29th, 2013 | Life, Tech

Normally, you can restart Apache using the restart command for the init.d script.

/etc/init.d/apache2 restart

However, you may encounter the following error.

chris@server /root $ sudo /etc/init.d/apache2 restart
 * Stopping apache2 ...[ ok ]
 * Starting apache2 ...
 * start-stop-daemon: /usr/sbin/apache2 is already running 

This is due to a bug in the init.d script. You can resolve this with a one line change.

vim /etc/init.d/apache2

Change line 105 for the one below (they should look very similar).

while ( test -f "${PIDFILE}" && pgrep -P ${PID} apache2 >/dev/null ) \

Save it and run the restart command again to check it has worked.

chris@server /root $ sudo /etc/init.d/apache2 restart
 * Caching service dependencies ...                                                                              [ ok ]
 * Stopping apache2 ...                                                                                          [ ok ]
 * Starting apache2 ...

If you get an output like the above, you’ll know it’s worked.