Latest Publications

Creating custom gesture recognisers for iOS

A custom gesture recognisers allows you to simplify the job of detecting specific touch patterns on a iPhone or iPad. Although some basic gestures (long tap, double tap, pinching and zooming, and so on) are already available from Apple out of the box, more complex finger movements must be detected by yourselves. By implementing your detection logic as a gesture recogniser, you make that logic much more easily reusable within UIKit. So here’s how to do it. (more…)

SQL JOIN: inner and outer

When joining two tables in an SQL statement, there are two options. You can use an inner join, or you can use an outer join. Let’s see what the differences are. (more…)

Multiple SSH/SCP invocations

In writing shell scripts sometimes you want to be able to execute several SSH or SCP commands in a row. Unless you have set up authorised keys on the server, each one of the commands executed in the script will require that the user enter their password for the connection to be established. Or you can use a nice feature of SSH whereby you open a “master connection”. The master connection passes your user’s credentials to the server and then allows several “slave connections” to perform operations through itself without the need for reauthenticating. (more…)

Get 10% off at freeagentcentral.com

FreeAgent Central is a great online application that keeps accounts in order for freelancers and small businesses. If you use a referral code, both you and the referrer get a 10% discount. I have been using FAC for the past two years and am greatly satisfied with it. If you want to use it too, use my referral code and we can both benefit ;-)

My Referral Code:

365afsjd

Or follow this link:

http://fre.ag/365afsjd

 

Remove all subversion info from a working copy

If you want to make a plain directory out of a working copy, you could use the svn export command and then delete the working copy. But if you’re running under a *NIX system with a bash shell, it might be quicker to just go

find . -name ".svn" -type d -exec rm -Rf {} \;

inside the top level folder of your working copy. This goes through every subfolder of your working copy and gets rid of the .svn directory that makes your files a subversion working copy.

Objective-C load and initialize

These two static methods of an ObjC class allow you to run initialization logic where you can set up any static state. Both methods are only invoked if implemented and do not need to be declared in the interface of your classes. The differences between them are as follows:

  • In an application, or in a framework that links to an application, the +load() method is executed before the main(). In a loadable bundle, that same method is executed during the loading process. Instead, the +initialize() method is executed lazily before the first use of the class it belongs to.
  • There is no autorelease pool in place when the +load() method is executed, so if using any autoreleased objects you will have set one up yourselves. The +initialize() method runs in the same context as the first call you make to the enclosing class, so there will most likely be an autorelease pool present.
  • Because the +load() method is executed so early, you have to be careful because not all classes you rely on might have been loaded. All frameworks you link to are guaranteed to be loaded first, though, so you can rely on the classes they define. No such concern is necessary when using classes from within the +initialize() method.
  • Unlike all other cases (including the +initialize() method), when redefining a +load() method in a category, you will end up with all defined loaders being executed when an application starts or a bundle is loaded.

Mail and Calendar in Android apps

While there isn’t a dedicated API in the Android SDK for sending email messages or adding events to a user’s calendar, there is a way to perform either task using specially constructed intents. (more…)

Ports and processes in Ubuntu

This command will show what processes are currently listening on what ports on your Ubuntu box:

Result of netstat

The result of netstat


sudo netstat -lntp

If you have installed nmap (sudo apt-get install nmap), you could also run

sudo nmap -A -T4 localhost

Result of nmap

The result of nmap

to try and find out the name and version of the services running on each port.

The output of netstat above will give you the number of the process (pid) as well as the name. You can then use

sudo ps -f -p

to find out more about the process (for example the command line arguments passed to it) and this

sudo kill -9

to kill the process brutally (if you have no other means) and release the port in question.

Custom configuration for Plesk domains

If you ever change your web server configuration files under Plesk manually, your changes will be overwritten the next time you use the administration console and apply any settings through it. This can be solved by adding a configuration file to your domain config folder

/var/www/vhosts/<yourdomain.com>/conf/vhost.conf

or subdomain config folder

/var/www/vhosts/<yourdomain.com>/subdomains/<subdomain>/conf/vhost.conf

depending on which element you need to apply custom configuration to.

In order to make these files effective, you need to run a Plesk command that will detect the presence of the new files and include them in your domain’s main config file (they are not by default). You can do this at the specific domain level

/usr/local/psa/admin/sbin/websrvmng -u --vhost-name=<yourdomain.com>

or just reload all domain configurations at once

/usr/local/psa/admin/bin/websrvmng -a

You can now safely keep on using the Plesk administration console and be sure that your custom configurations will not be overwritten or affected in any way. This information definitely applies to Plesk 8.2 where it has been tested, but should work equally well on previous and possibly later versions.

iPhone apps and device language setting

Though it is possible and even relatively easy to create an iPhone app that uses a different language to the one set in the device settings, the feature is not very well documented and it can take a while to work out how to use it properly. (more…)