Note: These are rough notes and there may be some variance as versions of raspbian get updated but should be pretty reliable as a guide.
This gist provides some instructions and config in order to have your Raspberry PI automatically connect to a roamed network, however if it fails to discover an available network it will set itself up as a wireless access point for you to connect to.