Contributing to Projects on GitHub

Recently I’ve been contributing to the code project behind joind.in, the event information and feedback site. I rely on joind.in a lot and after putting up with a frankly astonishing volume of feature requests from me, its owner Chris Cornutt very politely suggested that I might like to fix some of them myself. The project is hosted on github and I haven’t traditionally been much of a git fan, but I wanted to contribute so I set off to work out how to begin.

Register on Github

To do anything useful I first needed to sign up for an account. Github has a range of accounts but I found that with one of their free accounts I would be able to get started and contribute to the project. This gives me a project space of my own and a user to tie all my activities to.

Set up SSH Key

In order to authenticate against the github servers, you need to set up an ssh key and give them your public key so they know you are you. You’ll then need to tell git to use this key whenever it makes contact with the github servers. I do quite a bit with ssh and ssh keys myself so I was comfortable with this step. Even if you are totally new, its still pretty straightforward and they have a great howto on github itself which will help.

I had issues with git not picking up that it needed to use a non-standard ssh key, but I found the answers in this entry on the git website. In a nutshell, set up an ssh alias, set the key in there and then use the alias instead of the actual URL when giving the repo location to git. This now works like a charm for me.

Fork the Project

Now, github uses “fork” where I might choose to say “checkout” – fork in my world means something else completely. But in this case you’re just making your own copy of the project repository. This is where you will commit your changes to and it retains its link with the original repository making it easy for anyone with commit access to that to pull in your changes. Patch files are nowhere to be seen, and although I was wary at first, this is project collaboration at its most painless, I’m impressed! Forking was relatively simple and again there was great documentation on the github site. In particular I recommend that you take the time to follow the bit about adding an alias for the “upstream” repository – this made committing my changes to the main joind.in repo really easy.

The forking instructions linked above also gave a description of how to actually use git, how to get my changes applied to my local repo, and how to push them to my remote repo on github itself.

Make a Pull Request

Once I’d fixed a few things, I was ready to push the code back to the main project so that Chris could consider it for inclusion. This is done by making a pull request from the main project page – you can add a comment about the changes you are supplying to help the maintainers to manage all the incoming patches.

Go Forth and Contribute

It was easier than I expected to get set up to contribute to a project using github, so find something you want to improve and/or be involved with, and do it. I began by fixing the docs for joind.in, which was a great place to start since it allowed me to make a useful contribution without touching the code in the first instance :)

Speaking at PHPNW February

If anyone is able to make it to the PHPNW User Group meet in Manchester next Tuesday 2nd February – I’m the speaker there! I’ll be giving a talk entitled “Best Practices for Web Service Design”, which covers lots of information about web services and how to write one that your users will love! Details of the event are over on upcoming, you can find out more about the talks, the venue and the group as a whole. If you’re able to make it then I’ll see you there – its a good crowd :)

Charlie Bag from Burdastyle

About a year ago I discovered the BurdaStyle site – where they have open source patterns. And then over the summer I saw an event organised in NYC where they were making these Charlie Bags – foldable fabric bags for putting shopping in. The pattern is free, and came as a PDF. You print the PDF, and then you cut and stick to make the paper pattern – the bag is bigger than A4.

Once I’d made the pattern, I cut out the bag and followed the instructions. They have good instructions, step by step with pictures. The Charlie bag is really simple so you just zig-zag round the shape and leave the handles like that, just unfinished, which is about the only way someone with my sewing abilities is going to make anything with curvy handles :)

I’m really pleased with the result:

Charlie Bag

This was pretty simple and now I’ve assembled the paper pattern, I might make a few more :)

Three Ways to Make a POST Request from PHP

EDIT: A more modern take on this topic is here http://www.lornajane.net/posts/2018/make-a-post-request-from-php-with-guzzle

I’ve been doing a lot of work with services and working with them in various ways from PHP. There are a few different ways to do this, PHP has a curl extension which is useful, and if you can add PECL extensions then pecl_http is a better bet but there are a couple of different ways of using it. This post shows all these side-by-side.

POSTing from PHP Curl

This is pretty straightforward once you get your head around the way the PHP curl extension works, combining various flags with setopt() calls. In this example I’ve got a variable $xml which holds the XML I have prepared to send – I’m going to post the contents of that to flickr’s test method.

$url = 'http://api.flickr.com/services/xmlrpc/';
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

First we initialised the connection, then we set some options using setopt(). These tell PHP that we are making a post request, and that we are sending some data with it, supplying the data. The CURLOPT_RETURNTRANSFER flag tells curl to give us the output as the return value of curl_exec rather than outputting it. Then we make the call and close the connection – the result is in $response.

POSTing from Pecl_Http

Pecl_Http has two interfaces – one procedural and one object-oriented; we’ll start by looking at the former. This is even simpler than in curl, here’s the same script translated for pecl_http:

$url = 'http://api.flickr.com/services/xmlrpc/';

$response = http_post_data($url, $xml);

This extension has a method to expressly post a request, and it can optionally accept data to go with it, very simple and easy.

POSTing from Pecl_Http: the OO interface

Finally let’s see what the OO verison of the extension looks like. Exactly the same call as both the above examples, but using the alternative interface, means our code looks like this:

$url = 'http://api.flickr.com/services/xmlrpc/';

$request = new HTTPRequest($url, HTTP_METH_POST);
$request->setRawPostData($xml);
$request->send();
$response = $request->getResponseBody();

This example is quite a bit longer than the previous one, and you might think this indicates that this approach is more complicated. In some senses that is true and its probably overkill for our extremely trivial example. However it is worth mentioning that the pecl_http extension is extremely flexible and powerful, and can handle some cases that the curl extension can’t. So even if it looks more complicated here, it can still be an excellent choice to implement.

In Conclusion

That was a very fast round-up of three ways you could make an arbitrary web service call from PHP – hopefully these examples are clear and will help anyone just starting to implement something along these lines.

Screen in Ubuntu Karmic

I have written about screen quite often, mostly including my .screenrc file and showing how to have named tabs for the various screen tabs you have open. When Ubuntu Jaunty came out, I found it had some quite cool enhancements that made the customisations for screen really easy by default – and I wrote about these.

In Karmic Koala, Ubuntu 9.10, the packages are still there but they’ve changed names! So if you want to use screen with Ubuntu Karmic or later, install packages byobu and byobu-extras, and uninstall screen-profiles and screen-profiles-extras (they were broken on my system after upgrade anyway) and you should find everything works as expected. To run screen with the new features, you should run “byobu” instead – although screen commands seem to work to detach and reattach the screens that result, weirdly.

I’m mostly posting about it because I have been very frustrated and there’s no way I could have guessed, or probably ever will remember, what these packages are called. Apparently a byobu is a japanese room screen … you learn something new every day!

Dutch PHP Conference: Call for Papers Now Open

There is an announcement over on the DPC (Dutch PHP Conference) website – their Call for Papers is now open (so go submit!). What’s remarkable about this announcement is that I wrote it, and its signed with my name and the words “Your host this year” … yes, I’m hosting DPC.

I’m pretty excited about this, I love getting involved with events and I also love DPC as an event, so together these are pretty special. DPC is organised by my employers, Ibuildings – so I actually get paid to get involved with this conference, which is pretty cool :) The submissions have already started coming in to the call for papers and the quality and variety of the talks, from people I know well and others I’ve never heard of, is staggering. I’m hoping that this trend continues right through until the CfP closes on 31st January. The task of choosing the tasks will be very difficult but we have a panel of selectors ready to step up to the challenge – and I’m already excited about how good this year’s event is going to be!

Speaking at TEK·X

I’m always pleased to be accepted as a speaker but I’m especially delighted to hear that I’m speaking at TEK·X in Chicago this May. They had a crazy number of submissions for the number of slots available, and I really wanted to go since I spoke there last year and enjoyed the event hugely! This year I’m giving the following sessions:

PHP Best Practices (tutorial) – This is a half-day tutorial with my good friend Matthew Weier O’Phinney covering all sorts of good stuff you can do when you develop PHP. Its a general session and the aim is that everyone in the room takes away something new from our tips and tricks (and stories of what *NOT* to do!)

SVN in a Distributed World I’m giving this talk for the first time, looking at how traditional source control (subversion) compares with the newer distributed version control solutions (git, bzr). There’s been lots of buzz around git but in the PHP world we choose our tools on merit, not on cool factor, so this is a chance for me to share my experiences with both types of systems and talk a bit about which scenarios the various tools are a good fit for.

Open Source Your Career Another new talk! This one is about how much personal gain there is being an open source contributor. I’ve grown hugely, both personally and professionally, from my experience with user groups, events, and software in the open source space – so I’ll be sharing some tips on how things can work out well all round.

If you’re going to the conference, then do make sure to stop me and say “hi” – there are so many people at these events that sometimes I miss out on meeting people I’d like to have spoken to. You can’t miss me, I’m the woman with the English accent and curly hair!! I had an absolutely great time last year and I’m already looking forward to this year’s conference!

New Office

I haven’t posted about the house for ages, mostly because I haven’t been around enough to do much with this project at all! Some months ago (July to be precise) I moved out of the bedroom I use as an office here and into an attic, so we could redecorate the office. To cut a rather long story short, After several holes in walls and other such carrying-on, I’m finally back into my office!

We went from this (you can’t really see how nasty the grey paint was or how much the previous wallpaper pattern was showing through)
office

Surprisingly this happened:
Magnificent ? In His Flying Machine

Less surprisingly, this happened (my house is > 100 years old, brick internal walls throughout, and sometimes the plaster has got tired of hanging on!)
Hole in the Wall

Now that corner looks more like this:
New Office

And my desk is back where it should be, yay!
Office Update

Thanks to everyone who offered to help with hanging wallpaper in response to us struggling so much to make this happen – it was our first time hanging wallpaper but that wasn’t the hard part. This project stalled badly due to a combination of lack of time on my part and the sheer volume of prep needed on a house this age which has been neglected! Thankfully my parents came for lunch last weekend and pushed us in the right direction with a combination of instructions and practical help :)

Looking Back at 2009

2009 was a funny year. I started it with a trip to South America, returning to a job I’d held for a year and was starting to feel settled with. I had grand plans for the year, for myself, my home, and my career. And at the end of the year I can honestly say I achieved absolutely none of these.

Its not necessarily a negative thing – I did some absolutely great things in 2009, its just they weren’t the things on my list. I spoke at a number of conferences and other events, and finally started to feel like I had something to say! The highlights were presenting at tek (because I finally started to feel competent at conference speaking), and PHPNW – where its my home conference which I organise and I knew exactly the session I wanted to bring. I wrote it, brought it, and the session was really well-received. I am definitely not finished with speaking nerves, but I know that if I can get up there and be properly prepared – I have something to give to my audience. Already I’m lined up for quite a few speaking events in 2010 and I’m almost more excited than nervous (almost). Everyone told me the nerves would get better with time – they just omitted to tell me how much time.

In 2008 I was surprised to find that I had written 195 blog posts in a year. I did many more interesting things in 2009 and basically worked a lot more, so I knew I’d be blogging less. This is the 119th post of the year though so actually I did pretty well, all things considered. I’m pleased that I’ve managed to keep writing even through the busy times of the year. I usually post a screenshot of my stats but they’re not that interesting this year to be honest, they’re holding fairly steady and since I don’t track who reads my feeds, it would only be a guess anyway. The blog was mostly a replacement for me remembering things – and it hasn’t changed a lot in the 4 years I’ve had it really!

One thing that I will mention which turned into a bit of a feature this year was that I actually started taking photos of things other than knitting! I think it started with our trip to Peru in January, and also the experience of having my own camera, with nobody else but me to see the results. I’m taking more photos than ever and just replaced my little camera so that’s pretty exciting – my photos are on flickr if you’re interested.

All in all, 2009 was the year that didn’t go to plan – I’m mostly happy about the net result and I think perhaps it was time for me to get a reminder that a master plan isn’t always a good thing. So I’m going with the flow for 2010 and wondering what the coming year has in store; at work and in my wider technical activities I know I’m going to be very very busy and this sadly means I’m stepping away from some of the activities and committments that I’ve enjoyed until now. Above everything else I am hoping that 2010 holds success and good health for us all!

Silencing Curl’s Progress Output

I seem to have been writing a lot of shell scripts to do things with curl lately, and the main difference with piping curl’s output to somewhere rather than just looking at it on the screen is that curl will then start outputting a whole bunch of progress information that you don’t usually see. This can be frustrating if you wanted the same output as it viewed on the command line, or (as in my case) just wanted to grep for something in the header output.

To silence the additional output, use the -s switch – but be aware that this will also silence any error messages as well! Something like this:

curl -s http://lornajane.net | grep PHP

This will enable you pass into grep just the output you would usually see on your terminal. Hope this is useful to someone!