Shortening URLs from PHP with Bit.ly

I’ve been looking around for a really simple API that would be a nice place to get started using web services from PHP – and I realised that bit.ly actually fits the bill really well. They have straightforward api docs on google code, and it’s also a pretty simple function!

Here’s a simple example, using PHP’s curl extension, of using the bit.ly API to get a short URL, using PHP (you need an API key, but if you’re a registered bit.ly user, you can log in and then find yours at http://bitly.com/a/your_api_key).

$ch = curl_init('http://api.bitly.com/v3/shorten?login=username&apiKey=R_secret&longUrl=http%3A%2F%2Flornajane.net');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
print_r(json_decode($result));

Continue reading

Speaking at OggCamp

I’m delighted to announce that I’ll be speaking at OggCamp this year. This is an event that I’ve attended both previous years, and one that I always seem to get a lot out of. It’s an open source, anything goes, unconference kind of event. Except that this year there is also a scheduled track of talks alongside the usual unconference content.

I love oggcamp for the sheer randomness of what I learn there. I’ve variously seen talks on home automation, mapping, operating systems, politics … the list is pretty long. This year, it’s in Surrey, on the same weekend as the final deadlines for my book so I figured I’d have to give it a miss. But when I got an invite to speak on the scheduled track, I realised this was the omen I needed, and accepted at once!

I’ll be giving a talk entitled “Open Source Your Career” – a talk which brings up an aspect of open source that we often don’t discuss; the personal rewards that an individual can gain from being involved in open source. If you thought it was all about altruism, think again. I’ll be bringing anecdotes, from my own career and others’, about how the best way to fast-track your professional growth. See you in Surrey :)

Celebrating One Year in Business

A year ago, I left my job at Ibuildings and went freelance. At the time, I didn’t really know what I wanted to do next, and I was excited about the opportunity to try out a few different things. I blogged about my new (ad)venture when I launched it, but I haven’t written much since and people keep asking me for updates – the anniversary seems like a good time to reflect.

Well, I still don’t know what I want to do next, but that seems like less of a problem these days. I’m busy but in a planned-in-advance, only wearing myself down because there was something so exciting I couldn’t say no, kind of a way. I am not a great fan of travel, and have always tried to avoid it, but in fact so many interesting things came up this year that I ended up on the road more than ever. It turns out that there is a world of difference between being sent somewhere on short notice, and planning a series of interesting professional engagements that just happen to involve being away from home a lot all at once. And if I don’t want to go: I don’t go. It’s amazing how many people will wait til next month if you ask them!

Continue reading

A Book Burndown Chart

You might have noticed that things have been a bit quiet around here lately … that’s because I’m writing a book and doing a lot of editing at the moment. I love doing both of these as part of my work, but it turns out that when you’re already writing/editing 3k words a day, it’s hard to find more words to blog with (well, and I usually blog whatever code I’m writing which isn’t a whole lot right now). I did however want to share with you the news that I’m working on a book (about PHP, for the lovely Sitepoint).

I’m completely new to book-writing and it felt like a mountain to climb. I have five chapters of around 8 thousand words each to write for the book (I have co-authors, who are also lovely), and the general advice I got was to just take it all one step at a time. This sounds a lot like the way I teach project management and time management to developers, so I used those same skills and created a burndown chart (I blogged about creating these before):

As you can see, there have been some great days, and some quieter days. The flat lines are mostly weekends or days where I was out of the office with other clients. Although I feel slightly overwhelmed (and this doesn’t show the edits that come back after I submit each chapter), the graph is at least going in the right direction!

First Steps with GraphViz

This year I moved my whole presentations toolchain over to LaTeX and PDF, and where I added diagrams (which doesn’t happen a lot!) I used graphviz to generate them. Graphviz is a way of describing items and their relationships in a textual manner, and rendering them into a graph – and the results can be saved as an image, or included in LaTeX documents.

I found graphviz frustrating at times but on the whole it draws clean, symmetrical graphs far beyond anything else I can manage, even if I do use a mouse or tablet. Since I’m not able to use a pointing device on a regular basis, and I’m marking up my presentations in text also, it turned out to be a really good fit. I thought I’d share how I got on with it and some of my own graphs – as much to remind me next time conference season comes around as anything.

Continue reading

PHP Returning Numeric Values in JSON

When I wrote about launching a prototype of a new joind.in API, quite a few people started to try it out. My friend David Soria Parra emailed me to point out that many of the numbers in the API were being returned as strings. He said:

It’s just a standard problem of PHP REST services. When I try to access it with java I have to convert it over and over again to ints.

I did have a quick look at the PHP manual page for json_encode but I didn’t see anything mentioning this. A few weeks later (my inbox is a black hole and it takes a while to process these things) I fell over a throwaway comment to an undocumented constant JSON_NUMERIC_CHECK, and I added the constant name to my todo list. In the time it took for me to actually get around to googling for this, some wonderful person updated the PHP manual page (this is why I love PHP) to include it as a documented option, and someone else had added a user contributed note about using it.

It turns out, this constant does exactly what I need. Here’s a simple use case:

echo json_encode(array('event_id' => '603'));
echo json_encode(array('event_id' => '603'), JSON_NUMERIC_CHECK);

and the output:

{"event_id":"603"}
{"event_id":603}

There are probably some situations in which you don’t want all your looks-like-a-number data to be returned as a number, but for now it seems to be a good fit for api.joind.in.

RepRap Masterclass

I spent last weekend in lovely Bath, but I didn’t get to see much of it as I spent all three days building a RepRap, or Replicating Rapid Prototype. This is a 3D printer that can print plastic into any shape you can think of (and some that I definitely didn’t). The Masterclass was organised by EMakerShop and brought together a bunch of people with ties to the local area who are all active in the project itself.

Continue reading

Using Modelines in Vim

I’m working on a book at the moment, and there are strict guidelines on formatting. One thing which is tripping me up is that all code samples must use two spaces for indentation. I normally have my editor set to 4 spaces, so I was looking for a good way to keep just these files consistent in their layout. Enter vim’s modelines feature!

You may have seen this, a comment line at the start or end of a document which gives the settings for vim to use, something like this:

/* vim: set sw=2: */

This is a modeline in vim. I tried adding my own at the top of my sourcefiles, but vim seemed to ignore them. It turns out that modelines are disabled in vim by default (for security reasons) but you can easily turn them on in your .vimrc with:

:set modeline

The only change I want to make is the tab sizes which is why I use the line above. The vim modeline documentation is the best place to go if you want to add options of your own to this line

PHPMyAdmin Designer View

This week I’ve been using phpMyAdmin for what feels like the first time in years. I’m happier at the command line, but needed some graphical representation of information and easy ways to export example queries for the book I’m working on. I noticed that phpMyAdmin now has a Designer tab, which shows relationships between tables and allows you to define them.


Continue reading

The Worst Way To Find Women Speakers

I am a female speaker, and a software developer, which puts me in a fairly small minority at the events I usually attend (I’m a PHP consultant based in the UK, to give you an idea of what kind of events those are). Recently I’ve been asked my opinion more than once on the issue of women speakers being in a minority at technical events, and I’ve also been the “token” women speaker at a technical event.

The worst thing you can do is find some random, underqualified person who represents the demographic you want to include, and put them on the stage. Although gender is often the issue we hear most about, the same applies to anyone who isn’t a young, white male; it’s just that gender is easier to see and talk about than either age, ethnicity, sexual orientation, or anything else, and also since I’m a young, white female, it’s the only aspect I can comment on.Women are in such a minority that they are, almost by definition, representative (see http://xkcd.com/385). Anyone who sees your randomly-selected woman speak will simply go away thinking that women aren’t really good at speaking. Continue reading