Friday, December 31, 2010

2010: My Highlights

Well would you look at that, the year is over already. Before we condem it to history i wanted to have a quick look back at this year.

Float-Right (aka my career)
I've been self employed for entire year! Thats right folks a whole year. In that time Float-Right has really grown. While i'm not quite groupon, and i haven't bought that Aston Martin Rapide yet, i'm happy with what i've been able to achieve in that time. I've had some help mind you, not only in the form of my Mum, who has kept me snug with regular cups of tea, but also my small but loyal twitter following who make up for the lack of work colleagues.

2011 should see Float-Right do more work internationally, not only in terms of client base, but also in terms of where i will physically be located (thats right, i'm going back to Espana!). Also i hope to finally meetup with the rest of the iOS/Mac dev community at WWDC this year. As a result please send me work! Flights to San Francisco, hotel stays, and WWDC tickets are not cheap. Even my budget travel ethos doesn't cover me on this one.

Travel
In 2009 i travelled to China, Hong Kong, Barcelona,Spain & Paris,France. I thought that was fairly amazing. Well i think it's fair to say i've had another good year, visiting Amsterdam( Netherlands), Barcelona(Spain), Sevilla(Spain), Tel Aviv & Jerusalem (Israel).

Despite now being essentially banned from a number of nations thanks to my visit to Israel, my list for 2011 is even bigger. Argentina, Australia, USA, Switzerland, Norway and of course my new home (in the sun), Sevilla.

Moments
Have had a lot of interesting moments and times this year, but here are some of my highlights.

* Encouraging Ezra (@ezrabutler) to take a boat trip in international waters for his birthday ... this was about 1 month before the infamous flotilla incident

* Meeting Joaquin. Not that it was bad, it was just overwhelming.

* Hanging with Jason and his friends in Sevilla, he really helped make that experience amazing.

* My "lovely" trip to sunny barcelona, hint, it wasn't lovely, and it damn sure wasn't sunny.

* Being confused for a homeless person on the streets of Barcelona at 2am.

* Meeting Jonathan/Joe (@improvmonkey), full of interesting facts and views on life, the world, and the babylonians.  I've never met a grown man that can party like that. I can't mention Joe without mentioning some other folks i met on that trip; @ahoova @llan_peer and @guy.

* Amsterdam with the lads, while people find this hard to believe i don't smoke, but that was hilarious. Especially the trip to the park on the last day. Shout out to @andrew_francis & @jai_morjaria. We gotta do that again.

* The sheer number of people that i met in Sevilla, too many to name them all (well i might have forgotten some of their names ... ). Strangely two of my favourites were both Aussies, Amy & Jardana.

* While i also met her in Sevilla, she deserves a bullet point all to herself, Serpil, aka El Professora, the woman that helped beat my spanish into shape, while also showing me what being truly multilingual looked like. She was also a really nice person!

* Buying stuff in a spanish shop in chinese. Absolutely hilarious.

* FOWA after party, that's always funny.

=======================================================
Anyone else noticing that all the good stuff happens overseas ... i'm just saying
=======================================================

* Geeky i know, but i finally purchased my first ever Macbook pro :)... which i put a rather large dent in three weeks later :(

* Living in a hostel(s) for two weeks. It was awesome at first but really started to get depressing towards the end.

* Finally having a piece of published software! Only took 22 years.

* Having a flight cancelled for the first time in my life.

* Watching the sunrise on beach in Tel aviv.

* The way people (who aren't from California) get excited when i tell them i make iPhone apps for a living, (putty in my hands i tell you...)

* My cafe con leche experience ... aka hot milk with a tea bag in it. Priceless.

* Completely stopping Web Development, i can't explain how great that is.

* Meeting the Girls as @andrew_francis and i call them, hilarious night. Good people.

* Saying the Stweetfight app would only take a couple of hours (thanks @samwilliamh)

* Doing a standup like performance for a roof terrace full of germans.

Well that made me smile, if no one else. So lets give away some awards.

My most hilarious moment of 2010 ...
Watching Nykia drop off a chair. Being 2010 it's on video of course

My most depressing moment of 2010
Letting go one of my early clients.

My happiest moment of 2010 ...
I can't pinpoint a single moment, but as the above shows all the time i spent outside of the UK were my happiest times. (i'm still game for the passport swap if you are)

My Saddest moment of 2010 ... 
My grandmothers funeral, never have i shed that many tears in so little time

Goals for 2011
I have many, being the continuously improving sort of person i am, but here are a few.

* Go back to spain (por todos tiempo)
* Go back to China (on my to the DPRK perhaps ....)
* Build a Mac App
* Discover this work/life balance that people talk about
* Go somewhere i haven't been
* Improve my Spanish & Chinese, especially my ability to read the latter.
* Starting learning Arabic
* Pray a little/lot more, at this rate someone might confuse me for an atheist! I'm actually a christian shock horror!

To everyone, best wishes in 2011. Don't forget it's just like 2010, but your older this time ^_^

Thursday, December 16, 2010

Offscreen drawing on the iPhone using NSOperations, CGImage, CGLayer


What?
Creating and or modifying images offscreen or in a background thread.

Why?
Chiefly for performance. The main thread of an iPhone application is usually fairly busy doing all sorts of things. By rendering complex images in the background, you can do all manor of things. In my case I wanted to know how to render an image larger than the size of the device screen, and then save that image to disk.

For my fellow lovers of NSOperationQueue(aka possibly the most awesome class in Cocoa), this allows you to bundle image processing and generation in to NSOperation subclasses or if you like the new hotness a block, and add it to the queue.

How?
Well with a lot of C. If you have ever overridden UIView's drawRect: then most of what is below should make perfect sense.

First thing is first, as we want to operate on our own thread we have to create everything ourselves. Primarily that means no quick calls to UIGraphicsGetCurrentContext().

The key thing to remember is that the drawing coordinates are inverted. This means that CGPoint(0.0f,0.0f) is actually the bottom left not the top left corner. I'm lead to believe this is a hold over from the Postscript drawing system that originated on the mac, and this is how the big boys do it. So stop whining and code.

Nicely it would appear that the UIImage representation methods automatically invert the image, so you only have to invert your coordinates for CGContext drawing calls.

Exactly How?

This is the process
*Create a CGColorSpace
*Create a CGBitmapContext
*Create a new CGLayer
*Get the the CGLayer's context

Draw into the context as you would normally, using the CGContext methods

*Render that CGLayer into the CGBitmapContext
(if you want an image)
*Create a CGImage from the CGBitmapContext
*Convert the CGImage into a UIImage
*Use one of the UIImageJPEGRepresentation or UIImagePNGRepresentation methods to get an image that can be saved to disk or sent over the wire etc.

NOTE: This code will not work unless you have a image named sample.jpg in your bundle or change the assignment to the backgroundImg variable.

Sample code


Go forth and code.