Your browser is very old. You might enjoy surfing the web more if you used something newer like:

Google Chrome

Even Firefox would be OK.

If you're being forced at gunpoint to use Internet Explorer, you should at least upgrade it. Version 8 is tolerable and 9 will be OK when it comes out.

Posts from January 2009

Google Client Logins

I’m working on a little PHP app which is going to read data from a Google Spreadsheet document (more on that later).

The first thing I needed was the ability to authenticate against a Google Account which lead me to Authentication for Installed Applications. Pretty straightforward. POST a bunch of variables and, on successful login, get an Auth code back that can be used for future queries.

To that end, I threw together a little class to handle logins. I’m sure it’s been done many times before but it was a fun exercise.

class LoginFailedException extends Exception {}

class GoogleClientLogin {
    public $url;
    public $accountType;
    public $email;
    public $password;
    public $service;
    public $source;

    public static $CALENDAR_SERVICE = 'cl';
    public static $SPREADSHEET_SERVICE = 'wise';

    private $responseCode;
    private $auth;

    public function __construct($email, $password, $service, $source, $accountType = 'GOOGLE',
                                    $url = 'https://www.google.com/accounts/ClientLogin', $autoLogin = true) {
        $this->url = $url;
        $this->accountType = $accountType;
        $this->email = $email;
        $this->password = $password;
        $this->service = $service;
        $this->source = $source;

        if($autoLogin) {
            $this->login();
        }
    }

    public function login() {

        $postData = array(
            'accountType'=>$this->accountType,
            'Email'=>$this->email,
            'Passwd'=>$this->password,
            'service'=>$this->service,
            'source'=>$this->source
        );

        $httprequest = curl_init($this->url);

        curl_setopt($httprequest, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($httprequest, CURLOPT_POST, true);
        curl_setopt($httprequest, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($httprequest, CURLOPT_HEADER, true);
        curl_setopt($httprequest, CURLOPT_POSTFIELDS, $postData);

        $rawresult = curl_exec($httprequest);
        $result = explode("\n", $rawresult);

        foreach($result as $line) {
            $matches = array();
            if( preg_match('/^HTTP.*?\s([0-9]{3})/', $line, $matches) > 0) {
                $this->responseCode = $matches[1];
                if($this->responseCode != '200') {
                    throw new LoginFailedException('The login attempt failed with a response code of ' . $this->responseCode);
                }
            }

            $matches = array();
            if( preg_match('/^Auth=(.*?)$/', $line, $matches) > 0) {
                $this->auth = $matches[1];
            }
        }
    }

    public function getAuth() {
        return $this->auth;
    }

    public function getResponseCode() {
        return $this->responseCode;
    }
}

And here’s how you use it

try {
    $login = new GoogleClientLogin( '[username]@gmail.com', '[password]', GoogleClientLogin::$SPREADSHEET_SERVICE, '[identifier]');

    echo $login->getAuth();
    echo $login->getResponseCode();
}catch(LoginFailedException $e) {
    echo 'Login Failed:  ' . $e->getMessage();
}catch(Exception $e) {
    echo 'Error occurred:  ' . $e->getMessage();
}

<identifier> is just some string that identifies your app, presumably so Google can cut down on abuse.

Your data is your life. Why aren’t you protecting it?

Given how cheap disk space is, there’s no excuse for having at least some sort of backup system. I’m appalled by how many people I know who have no backups of any kind. I’m especially concerned for people who only have laptps.

What are you going to do if that laptop gets stolen or run over by a bus or has water dumped on it?

The main question you have to ask yourself is

If my computer completely failed right this second, what would I lose?

You have some shopping to do if the answer to that question scares you.
Go buy a copy of Acronis True Image and a cheap USB hard drive.

You can get almost total peace of mind for under $200.

That first step is the most important. But there’s another thing to worry about

What happens if my house burns down and I lose my computer and my backup disk?

Some people might be comfortable ignoring that level of paranoia. If you took the first step and are comfortable stopping there, go ahead and stop

I’ve been burned a couple of times before so I’m a little more paranoid. Here’s my setup:

  • A Linux fileserver which serves as a backup to my two Windows machines. The My Documents folders on my Windows machine also point to network shares on the fileserver
  • One of the Windows machines has a second 500gb SATA drive in it that serves as a backup to a number of files from the Linux fileserver (like the My Documents folders)

All of the backups happen automatically via cronjobs twice a day. I have a few very simple Bash scripts that use rsync to do incremental backups. This system has served me well and I’ve had to go to those backups several times.

But it’s always bothered me that I don’t have offsite backups as part of the equation. I investigated a number of services like rsync.net and Dropbox but those seemed a bit expensive.

In the end, I settled on Jungle Disk which uses Amazon S3 for online storage.

I paid $20 for the full version of Jungle Disk (there’s a free trial too) and I’ll be paying $0.15/gb/month to actually store the data at Amazon S3 (you also pay $0.15/gb for transfers in and out).

It’s nice too because I’m not locked into Jungle Disk (which is great so far). I can use an Amazon S3 compliant client to get files in and out.

I hear sob stories from people who’ve lost all of their digital pictures/mp3s/etc and I have very little sympathy because it’s too easy to avoid.

So get out there and make sure your data is protected.

RAID basics

What is RAID?

RAID stands for Redundant Array of Inexpensive Disks. Meaning that you can combine disks in different ways to create a large pool of space while protecting yourself from drive failures. Most RAID levels can survive the failure of at least one disk.

However, RAID is not a backup solution.

I’m going to say that again because it’s important.

RAID is not a backup solution.

RAID only protects you from hardware failure. It doesn’t save you from an errant rm -rf command. All the RAID in the world doesn’t do you any good if all your files get deleted and you don’t have backups somewhere else.


RAID 0 combines a minimum of two disks into a single large disk. Two 100gb disks would give you 200gb of usable space. You can use disks of different sizes but you’re limited by the size of the smallest disk.

Good

  • Fast read/write speeds

Bad

  • Lose one disk and you lose everything


RAID 1 mirrors the contents of one disk onto another disk. Two 100gb disks would give you 100gb of usable space.

Good

  • Easy to set up. Most controller cards support it and it’s pretty fast as software RAID.
  • Can easily handle a single drive failure and can sometimes handle multiple drive failures (depending on the total number of disks and the controller).

Bad

  • While read speeds are normal, writes are twice as slow
  • Not a very efficient use of available disk space.


RAID 5 spreads parity data across all disks giving you more available storage with a comparable fault tolerance to RAID 1. This is a flexible and cost-effective option.

Good

  • Makes good use of disk space. That means four 100gb drives would providing 300gb of usable space under RAID 5 while only providing 200gb of usable space under RAID 1.
  • Very fast reads, medium-speed writes

Bad

  • Requires a minimum of 3 drives.
  • Rebuilding a failed array is much slower than RAID 1
  • Controller cards are more expensive

RAID 10 – Mirroring & Striping

RAID 10 is a great option if cost and hardware are not an issue and is achieved by taking two RAID 1 arrays and combining them into a RAID 0 array. Four 100gb drives would yield 200gb of usable space.

Good

  • Fault tolerance of RAID 1
  • Read/Write performance of RAID 0

Bad

  • Expensive to implement. Controller cards are generally pretty expensive and also requires a minimum of four disks.
  • Doesn’t scale very well due to the sheer amount of hardware required.

Thanks to Wikipedia for the images. Don’t worry, I’m not leeching them.