iCal 502 error when syncing with Yahoo! Calendar

In the last few days, my iCal has been giving me the following error message when trying to access my Yahoo! Calendar via CalDAV:

The request for account "Yahoo! Calendar" failed.

The server responded with
"502"
to operation
CalDAVAccountRefreshQueueableOperation.

iCal error message when syncing with yahoo! calendar

Yahoo! have acknowledged this is a problem on their side:

We are aware of a Calendar (Proxy error) and our engineering team is working to resolve this issue. We apologize for the inconvenience and hope to have it resolved soon.

(source: Syncing / Mobile Sync | Yahoo! Calendar Help)

update 2nd November 2011: I am no longer seeing this error message, and Yahoo! have removed the notice from their help page. Looks like the issue has been resolved!

update 3rd November 2011: Seems like I spoke too soon, the error is back!

Camera and photo improvements in iOS5

iPhone Camera

The camera functionality in the iPhone has always been one of my most used features. iOS5 brings some enhancements, which are listed below:

Camera improvements

  • Double-click the Home button when device is asleep to bring up a camera shortcut on iPhone 4S, iPhone 4, iPhone 3GS and iPod touch (4th generation)
  • Volume Up button to take a picture
  • Optional grid lines to line up shots
  • Pinch to zoom in the preview screen
  • Swipe to camera roll from preview screen
  • Tap and hold to lock focus and exposure; iPad 2 and iPod touch (4th generation) only support exposure lock

Photo improvements

  • Crop and rotate
  • Red-eye removal
  • One-tap enhance
  • Organise photos into albums

This list was taken from the official release notes, which were accessible via iTunes pre-installation.

Getting started with MongoDB and PHP on Mac OS X

NYみやげのMongo goods貰った!

Introduction

MongoDB is a document-orientated database written with scalability and high-performance in mind. It is one of a growing number of NoSQL systems - a database that does not rely on SQL or relational theory at all.

Getting a MongoDB server working with PHP on Mac OS X is relatively straightforward, and this tutorial shows you how.

Installing the MongoDB Server

The first step requires you to download and install the actual MongoDB system. The example shown below downloads v2.0.0 64 bit binaries for OS X. For other binaries, please check out the MongoDB Downloads page.

cd /tmp
curl -O http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.0.tgz
tar zxvf mongodb-osx-x86_64-2.0.0.tgz
sudo mv mongodb-osx-x86_64-2.0.0 /usr/local/mongodb
mkdir /usr/local/mongodb/data

Configuring the MongoDB server

We need to create a small configuration file so that MongoDB knows where its data files reside. Create the file /usr/local/mongodb/mongod.conf and add the following line:

dbpath = /usr/local/mongodb/data

Starting MongoDB

To manually start the MongoDB server, use the following command:

/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongod.conf

This will start the server and will by default log all output to STDOUT.

Installing the MongoDB PHP Extension

Installing the PHP extension is simple:

sudo pecl install mongo

Once this has completed, add the following line to your /etc/php.ini file:

extension=mongo.so

Restart apache using sudo apachectl restart, and the extension should be available. This can be verified with the phpinfo call:

MongoDB extension for PHP

Example PHP script

To test your setup, the following simple script can be used to create a new collection and add two new records:

    <?php

    // connect
    $m = new Mongo();

    // select a database
    $db = $m->comedy;

    // select a collection (analogous to a relational database's table)
    $collection = $db->cartoons;

    // add a record
    $obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
    $collection->insert($obj);

    // add another record, with a different "shape"
    $obj = array( "title" => "XKCD", "online" => true );
    $collection->insert($obj);

    // find everything in the collection
    $cursor = $collection->find();

    // iterate through the results
    foreach ($cursor as $obj) {
        echo $obj["title"] . "\n";
    }

    ?>

The script should output the following:

Calvin and Hobbes
XKCD

And that's it! You now have a working MongoDB setup on Mac OS X.

For more information on the PHP extension for MongoDB, please see the following pages in the PHP Manual:

PHP: Mongo - Manual

Steve Jobs, 1955 - 2011

For me, it wasn't the iPod, iPhone or iPad but the Mac that was Steve Jobs' greatest success. After buying an indigo iMac in 2000, it reignited my passion for computing and I never looked back. The Mac made computing pleasurable, and for that I will be eternally grateful to Steve's vision and passion. A truly inspiring man.

Thanks, Steve.

Steve Jobs on Apple homepage

Going Freelance - Part 2

Look after the pennies and the pounds will look after themselves

In the first part of this post, I looked at a few essentials that need to be considered when moving to a freelance role, including motivation, company structure, banking and marketing. This time we look at the slightly less glamourous, but just as important, subjects of tax and record keeping, invoicing and useful software. Again, I hope this post is useful for any other software developers considering going freelance.

Tax and record keeping

Whether you decide to use an accountant or not, it's essential to keep records relating to your incoming and outgoing transactions. The Business Link site has an excellent guide on setting up a basic record-keeping system, and have some sample spreadsheets that you can use as a starting point. The records include:

  1. Cash sales and purchases/expenses book
  2. Sales ledger
  3. Purchase ledger

These records will give you a thorough overview of any money going into, and out of, your business account.

When you open your business account, it is likely that you will also have the option to open a deposit account at the same time. This can be used to set aside money to pay your tax bill each year. For sole traders, income tax will be calculated when you fill in the annual Self Assessment form.

You can reduce your tax bill by claiming tax relief on business expenses. Business expenses could include advertising, travel costs and legal fees. If you work from home, it can also include part relief on costs such as broadband and even electricity. The following links on the HMRC site give further details:

Invoicing

If you're not invoicing, you're not going to get paid. Therefore, you must keep on top of your invoice management. Freelance Advisor has a set of invoice templates that can be used as a starting point for creating your own. Make sure you issue invoices promptly, and be clear about your payment terms. Standard terms are 28 days, but you may wish to shorten this if you are just starting so you can get money into your business more quickly. Don't be afraid of chasing late or non-payment of invoices.

As your business grows, you may wish to consider using a software package that manages both accounts and invoicing. Currently topping freelancesupermarket's league table of accountants is Crunch. Crunch can handle both accounting and invoicing for a flat monthly or yearly fee. If you are a sole trader you need to switch to a limited company to use their service, a task which they will advise you on.

Useful software

There is a plethora of free software available to make freelance life easier.

Google Docs is an excellent way of organising documents, spreadsheets and databases for your business. One big advantage of using this is that your documents will be available from any machine that has internet access. The screen grab below shows a simple collection that I have put together to organise my documents. The top level collections are Accounts, Invoices and Quotes.

Google Docs for business record keeping

Skype is a great way of keeping in touch with your clients by instant messenger, voice or video call.

Ta-da List is a simple list manager, great for managing your "to do" list of day-to-day tasks.

SlimTimer is a simple browser-based application for tracking time spent on tasks. If you are billing by the hour, this is an excellent way of recording time spent working on a client's project.

SlimTimer popup window recording time spent on a

Summing up

One of the major challenges of freelancing is being able to juggle the actual work with the business administration side of things. As long as you are able to set aside a few hours each week to keep on top of the administration, you will have no problems. I hope that my experiences thus far can be of use to others setting out on the freelance path.

Going Freelance

Freedom

I have reached a natural fork in the road of my career as a software developer. Having been a full-time employee for the last 11 years, I have decided to take the plunge and start offering my services on a freelance basis.

After spending the last couple of years managing an engineering team, I am going back to hands-on development. The following post captures the experiences of my first month of freelancing, which I hope will be helpful to anyone else considering moving in the same direction.

Motivation

It's worth considering the main motivating factors behind my move into the freelance world. There have been two major life events that have led me into choosing this path:

  1. Being made redundant from my last job
  2. The birth of my first child

Being made redundant has given me the opportunity to try freelancing for the first time: I now feel that I have the experience necessary to venture out on my own. I also want to spend as much time around my newborn son, so the option of working from home is very appealing. Furthermore, I wanted increased flexibility of my working hours, rather than being tied to a 9 to 5 routine -- if baby is not sleeping, then I don't want to worry about having to wake up early for work!

Company structure

After deciding to freelance for a living, I had two immediate decisions to make:

  1. Choosing a business name
  2. Deciding upon a business structure - sole trader or limited company

To keep things simple, I have decided to trade under my own name and set up as a sole trader. Setting up as a sole trader is very simple, and has less administrative overhead than a limited company. However, some larger companies may not hire freelancers that are self-employed.

Details on registering as being self-employed can be found on the HMRC website:

HM Revenue & Customs: First steps to register as self-employed

Banking

It's essential to separate your personal and business finances, and that means getting a business account. Most high street banks offer business facilities for start-ups, usually without any fees for a certain period of time. Many also offer other perks such as free accountancy software or free business training. The most popular business accounts from the high street branches are:

I went for an account with Natwest as they were offering 2 years with no fees, and also one years access to Regus business lounges which may come in handy for client meetings.

Marketing

Marketing is all about bringing in work. I am in a fortunate position to already have a few contacts that require my services. However, it is crucial to be able to bring in new clients, and this is where marketing comes in. One thing that I have kept in mind as a freelancer is this golden rule:

Everyone you meet as a freelancer is a potential client

Potential clients could be your previous company, your friends, your family, your neighbours -- the pool really is vast!

Another important point to remember: as a freelancer, you are marketing your skills. So, it's important to highlight these whenever you come into contact with potential clients. Get business cards with your details and hand them out to everybody! Moo do a great range of designs, and are priced at a reasonable £10.99 per 50.

Spread the word via social networks. Updating your profile on sites such as LinkedIn, Facebook and Twitter can help market your skills for free.

Make sure you have a website with, at the very least:

  • Details of the skills you have
  • Examples of the kind of projects you have worked on, or are able to work on
  • How people can contact you

I have started with a simple page containing the above details, that I expect to expand over time:

Glen Scott - Freelance Software Development

If you can, start a blog. Writing posts can be an excellent way of highlighting your own skills and attracting new clients. Make sure that it's clear from your blog posts that you are available for hire. For example, I have inserted the following small ad on all of my existing blog posts:

advert for freelancing services

If you have specialised in a particular area, make sure that you are clear about this. For example, is there a particular language that you prefer to work with? A favourite framework?

Useful resources

One book I can thoroughly recommend is Brilliant Freelancer by Leif Kendall. This covers all the main aspects of freelance life, and is written in a very accessible manner. The author also uses some many real-life experiences from other freelancers to highlight various aspects which is very useful.

Many sites are available to help freelancers: here are a few that I've found useful:

Summing up

Going freelance is a huge change from what I have been used to, but a challenge I am already thoroughly enjoying.

Next time, I'll look at these aspects of freelancing:

  • Tax and record keeping
  • Invoicing
  • Useful software

Read part two of this post.

Install mcrypt PHP extension on Mac OS X Lion

If you have a need to install the mcrypt extension for PHP, for example if you need to use phpMyAdmin, then these instructions are for you.

Thankfully, it is becoming simpler to install PHP extensions than with previous versions of OS X.

Xcode

The Xcode package installs the necessary versions of tools like autoconf which is needed during the PHP extension compilation process. Make sure you have at least Xcode v4.1 installed; the install package ("Install Xcode") is available in your "Applications" folder.

If you are running Xcode 4.3 or above, please check you have the command line tools installed before proceeding.

libmcrypt

libmcrypt is the library that provides the encryption functions. We need to install this before building the PHP extension.

  • Open up Terminal.app
  • Download libmcrypt from sourceforge
  • Unpack the archive somewhere
  • cd libmcrypt
  • ./configure
  • make
  • sudo make install

PHP Extension

Once we have libmcrypt installed, we can build the PHP extension. One important point: even though PHP 5.3.8 is now the default since Mac OS X 10.7.3, attempting to compile with these sources results in the following error:

php-5.3.8/ext/mcrypt/mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)

Therefore, we need to use PHP 5.3.6 sources which compiles fine and still works with 10.7.3.

You should see output similar to the following:

Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
  • ./configure
  • make
  • sudo make install

On successful install, you will see the following message:

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/

To enable the module, include the following line in your /etc/php.ini file:

extension = mcrypt.so

Finally, restart your Apache server:

sudo apachectl restart

And that's it: you should now be able to utilise the functions, as detailed in the PHP mcrypt documentation. If you are needing a simple way of accessing these functions, check out my SimpleCrypt class.

mcrypt php extension

Mac OS X Lion PHP upgrade - php.ini and Suhosin

If you have upgraded from Snow Leopard to the new OS X Lion, you will notice PHP has also been upgraded - from 5.2 to 5.3.

A couple of points that I noticed post-install. Firstly, my existing /etc/php.ini file was moved to /etc/php.ini-5.2-previous. Restoring this was trivial:

sudo cp /etc/php.ini-5.2-previous /etc/php.ini

However, I noticed that extensions previously installed under /usr/lib/php/extensions/no-debug-non-zts-20090626/ had been removed. So, if you have extensions that you wish to still use with 5.3, they will need to be re-built.

I also noticed that Apple have included the Suhosin patch and extension. Suhosin is part of the Hardened-PHP project which aims to protect PHP applications against buffer-overflow and format string vulnerabilities. In theory, this functionality should be transparent to your application - no configuration or code changes are required.

Install mcrypt PHP extension on OS X Snow Leopard

Lock away the evil...

Please note: The following instructions apply to Mac OS X 10.6 (Snow Leopard). I have an updated guide for how to install mcrypt on 10.7 (Lion).

mcrypt is a useful extension to PHP if you would like to support a wide range of encryption algorithms within your code.

This guide explains how you can enable install mcrypt, along with the PHP extension, on Mac OS X 10.6.

Xcode

The Xcode package installs the necessary versions of tools like autoconf which is needed during the PHP extension compilation process. Make sure you have at least Xcode v3.2 installed; the install package is available on the Snow Leopard install DVD under the “Optional Installs” folder.

libmcrypt

libmcrypt is the library that provides the encryption functions. We need to install this before building the PHP extension.

  • Open up Terminal.app
  • export CFLAGS="-arch x86_64"
  • Download libmcrypt from sourceforge
  • Unpack the archive somewhere
  • cd libmcrypt
  • ./configure --disable-shared
  • make
  • sudo make install

PHP Extension

Once we have libmcrypt installed, we can build the PHP extension.

You should see output similar to the following:

Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
  • ./configure
  • make
  • sudo make install

On successful install, you will see the following message:

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/

To enable the module, include the following line in your /etc/php.ini file:

extension = mcrypt.so

Finally, restart your Apache server:

sudo apachectl restart

And that's it: you should now be able to utilise the functions, as detailed in the PHP mcrypt documentation.

mcrypt php extension

Normalize URL's with PHP

I've posted to GitHub a PHP class that I've written which can handle URL normalization, as specified by RFC 3986.

https://github.com/glenscott/url-normalizer

Specifically, the following normalization steps are performed:

  1. Normalize case
  2. Decode unreserved characters
  3. Remove dot segments

An example of use:

require_once 'URLNormalizer.php';

$url = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d';
$un = new URLNormalizer();
$un->setUrl( $url );
echo $un->normalize();

// result: "example://a/b/c/%7Bfoo%7D"