How to guess gender from a first name in PHP

AlienrestroomPhoto by Davezilla

If you've got someone's first name, it's possible to make a pretty accurate guess what their gender is. Obviously there's plenty of exceptions, Sean and Francis spring to mind, but for lots of applications you don't need 100% accuracy or coverage. In my case I want a better understanding the demographics of my users, so a figure that's within a few percent is fine.

There's a great Perl module called Text::GenderFromName that implements this idea, with accumulated wisdom dating all the way back to a 1991 awk script! I haven't found anything that fits well into my PHP projects though, so I finally bit the bullet and ported that Perl script to PHP. The result is up at

and you can get the source at

Thanks to Eamon Daly and Jon Orwant for the original code, and apologies for the mechanical translation of Perl code to PHP. It's now painfully non-idiomatic, but it does work!

For best results you should also install the doublemetaphone PHP module, though it will function without it.

Introducing Fan Page Analytics


Fan Page Analytics is a new project I've just launched to help answer questions about Facebook pages. Here's some examples:

Which parts of the world have the most fans of God? In the US the map pretty clears shows the traditional Bible Belt, but looking worldwide the Phillipines is pretty god-fearing too.

How does ReadWriteWeb's fan base compare to TechCrunch's? From the map, RWW is much more broadly based, whereas TC's readership is heavily concentrated in the traditional US tech centers of California, Washington and Massachusetts. I only see one venture capital fan page in RWW's top 20 most related pages, but I count 8 in TC. On the other hand there's a couple of HR related pages for RWW, and none for TC, which suggests a less geeky audience.

That's all fascinating, but what problem does it solve? Suppose I'm planning the next DEMO conference. Glancing at the related pages shows that Charlene Li and Fred Wilson are people my audience care about, so they should be top of my list to attend and spread the word. ReadWriteWeb and GigaOm fans are more likely to be fans of DEMO than Techcrunch readers, so I might get more bang for my buck buying ad space on those sites. Looking at the locations, CA, WA and MA are way ahead, so I can craft some Facebook ads targeted only at those areas and tied in to some of the other related interests. I can even look at some examples of users in particular locations or with shared interests to understand if they're really my target market. These appear in the right side-bar when you click on an area or a location.

This is an initial release, so expect a few bugs, and it's not yet got complete coverage of fan pages, so apologies if yours isn't there yet. Hopefully you can still have some fun uncovering things like Glenn Beck's fan base in Outer Mongolia.

What can I find out about you if I know your email address?

Photo by HerzogBR

One of the least-understood developments of the last few years is the growth of databases of personal information linked to email addresses. Rapleaf is probably the leader in this field, but even Flickr lets companies search their API for users based on an email address. I wrote a service that queries all the data sources I could find to demonstrate how much is out there:

Give it a try for yourself, you might be surprised by how much companies can discover about you once they know your email address! Many services give out at least your full name and a location, which is often enough to get your address and a phone number from a service like

How to make your intensity maps interactive


Google’s Intensity Map charts are a really easy and clean way to show heat maps of geographic data. Unfortunately, there’s no way to take the next step in the user experience, and let people mouse over and click on the maps to see additional information about a particular area.

To solve that problem, I’ve written a PHP script that extracts the country and state boundaries from the maps and constructs a Javascript function to return the state code for any point on the maps. You can see an example of this in practice at or you can download the complete source, including the boundary extractor.

The example page will show the state or country code for any point you move the mouse over on either of the maps, and if you click, will display an alert showing the name. It assumes your image has the maximum 440×220 dimensions, but you can apply scaling to the coordinates if you are using something smaller.

Create amazing Flash maps with Mercator

I've been using Google's simple map visualizer to picture some of the geographic data I'm gathering, but I've been looking for something more customizable and interactive. After a lot of searching, I finally found Mercator, an open-source flash library for creating maps. I've only been using it for a few hours, but already I'm very excited! It's not only very slick, with built-in animation and a clean look, it's also got a lot of depth, with data and graphics for an astonishing array of countries, states and cities.

The only down-side was getting started. The beginner's guide is aimed at someone with a deeper knowledge of Flash application building than me, and there was no 'hello world' example I could download, though there are several more advanced projects available. So, for anyone else out there who struggles with Flex basics here's a complete project for Flex Builder 3 that just creates and displays a Mercator map. You can see it running at the head of this post, or over at

Manfred's done an excellent job on Mercator, it's a poster child for the quality of open-source projects, and I'm looking forward to creating some rich visualizations on top of it.

A shell script for building MongoDB from source

Photo by Christina Matheson

I've been working a lot with MongoDB lately, including some tinkering to add domain socket support. Unfortunately those modifications mean that I can't just use a binary download when I need to install it on a new machine, I have to build from source instead. There's general instructions on building for Fedora 8, but I found that yum had either versions that were too old for some packages like scons, or as with PCRE it ended up complaining about other programs requiring older versions than Mongo asked for.

As a result, I ended up creating a shell script to handle all the building steps required. This is pretty specific to my own environment and very hackish, but if you're running into the same sort of issues trying to use RPMs for all the dependencies, hopefully this will give you some hints on building from source.

Download Makemongo

# Builds MongoDB and its needed dependencies for Fedora 8
# By Pete Warden

# First, make sure we have git
yum install git

# Now grab the Mongo source from github
git clone git://

# Get an up-to-date version of Scons, yum installs a 0.97 version that doesn't work!
curl -L "" > scons-1.2.0.tar.gz
tar -xf scons-1.2.0.tar.gz
cd scons-1.2.0.d20090919/
# Scons relies on Python, so make sure that's present
yum install -y python-devel
python install
cd ..

# Now grab boost sources - I do see some warnings in Mongo's config about this being out of date
yum install -y boost
yum install -y boost-devel

# Spidermonkey is needed for Javascript support, and there's no RPM
curl -O
tar zxvf js-1.7.0.tar.gz
cd js/src
make -f Makefile.ref
JS_DIST=/usr gmake -f Makefile.ref export
cd ../..

# You need an up-to-date version of PCRE, more recent than the one installed by yum
curl -O ""
cd pcre-8.00
./configure --prefix=/usr
make install
cd ../mongo
scons all

# On my AMIs there's old versions of PCRE libraries left lying around, so move them
mv /usr/lib64/ /usr/lib64/
ln -s /usr/lib/ /usr/lib64/

# Create the database location and run Mongo
mkdir /mnt/data
mkdir /mnt/data/db
./mongod --dbpath=/mnt/data/db --bind_ip=/tmp/mongo.sock --port=0 &

# Now build the PHP drivers and add them to the php.ini
cd ..
git clone git://
cd mongo-php-driver/
make install
echo "" >> /etc/php.ini
echo "" >> /etc/php.ini
/etc/init.d/httpd restart

St Mary’s Glacier


We had my parents to stay over Thanksgiving. They'd never been to Colorado before, so there was plenty to do around Boulder, but I also wanted a long weekend somewhere in the mountains. After digging around on the great Vacation Rentals by Owner site, I found a little two bedroom condo near Idaho Springs, about an hour from Denver.

We drove up the I70, then about 9 miles up a twisty mountain road to get to the little community of St Mary's Glacier. I have to admit my heart sank when I saw the building we were staying in, it looked like an apartment block from East Germany in the 1970's. That impression wasn't helped by the two abandoned cars across the street, next to a boarded-up cabin with broken windows, along with multiple for-sale signs in our building. Climbing upstairs to the condo, the door across the hall had been forced open, splintering the frame. We were pretty sure it was being used by squatters, since the door was permanently open, but towards the end of our stay we spoke to the building manager and they'd apparently just lost their keys!


I felt a flood of relief once we stepped inside, the place was beautiful. You can see a full tour on Randy's website, but he's done a fantastic job decorating. There was a dining nook with windows on three sides, giving a view of the lake and mountains, and the living room was great in the evening thanks to the roaring fireplace.

The real point of the trip was outside the condo. Even though there hadn't been much snow, we were up at 10,400 feet so there was some pretty wild terrain. We had new snow-shoes to try out, so we trekked up the glacier itself, to 11,700 feet. We're fairly certain that Thor is the only Chihuahua to make it up to the top of the glacier, and we were all stunned by the views from the plateau. The only off-note was a couple of jack-asses on quad bikes who decided to ride them up the glacier despite all the sign-posts, only to be driven off by irate hikers.

If you're looking for an authentic slice of old Colorado, St Mary's Glacier is pretty fascinating, with no pretensions, lots of history and more ghost towns nearby than I could count. It's somewhere with character – if you're looking for an adventurous mountain vacation off the beaten track I'd highly recommend it. It's definitely not Aspen, but that's it's charm!