Monday, December 05, 2011

Dinner Diary - Murtabak

Murtabak - minced mutton with garlic, egg and onion with a series of curry sauces. This cost a whopping RM5, approximately £1.

Dinner Diary - Roti Cenai Telur

Roti Cenai Telur  and Iced Milo - Essentially Roti with egg inside served with a series of curry sauces. The lced Milo is the brown drink to the left of the plate. It is basically a cocoa power that you can find in Jamaica. It's made hot, and then has ice put in it. It's fairly awesome. Whats more awesome is that this entire meal cost about RM4, thats 80 pence.

I Took a Picture [Perth Edition]

The Indian Ocean [HDR], Perth, WA, Australia

Dinner dairy - BBQ pork Noodle

So I literary just decided to start blogging the food I eat. Today I went to a place in KL's Chinatown.

It's basically fried noodles in a crap ton of soy sauce with Garlic and little bit of BBQ pork. It's the 2nd time I'm having it, unfortunately it's not as good this sitting as when I had it last week. This was slightly more expensive than my normal meal, coming in at RM10.20, just over £2. Sadly i've forgotten the characters, and cantonese romanization.

Friday, October 28, 2011

I took a picture [Down under edition]

Circular Quay, the Opera House & the CBD taken from the Sydney Harbour bridge in HDR with 3 exposures.

Friday, October 21, 2011

iOS 5 & UITableView datasources

It's been a big week for me, primarily because one of our client apps exploded, in no short part to Facebook screwing me over ... but i digress.

Last week also saw me finally upgrade to Lion, enable full disk encryption (Might blog about this later), and start compiling against iOS 5.

As is usual with big changes in the SDK there are always a few bugs, however this one had me confused for a couple of days.

After compiling against iOS 5, i got this message after popping one of the view controllers.
-[YOUR UITableViewDataSource tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x6e78420
Simple, i did something dumb, and over released my datasource class ... But it only happens on iOS 4, not iOS 5. [Cue twilight zone music]. And this code had been stable for well over 6 months before the SDK change [Increase volume].

Generally i a release and nil my objects and set any delegates to nil in my dealloc method. However in this instance i had forgotten to nil out the UITableView's dataSource and delegate properties. The solution was simply:
[_tableView setDataSource:nil];
[_tableView setDelegate:nil];

Now, i'm aware this is 100% my fault, you're always supposed to nil out pointers to non-retained/ weakly referenced objects. As a result i haven't bothered to file a Radar. (Dear apple, you caused me to find a bug in my code ... yeah) However as you can see, for one reason or another i was able to "get away" with it for months, so this post is a fair warning to all to lookout for this.

I took a picture [30 Rock edition]


Midtown Manhattan, New York City, NY from 30 Rockafella Center (No tripod)

Thursday, October 20, 2011

The 6 Month Club

This past tuesday signalled my entry into the "6 month travel" club. Usually when someone is travelling for 6 months they would have been all over the place, however i prefer to move at slightly slower pace. As a result i've "only" visited 4 countries (Iceland,USA, Jamaica, Australia).

I've been blessed with being able to meet some really nice, and interesting people along the way. Overall it's been an rewarding experience. I've got no real plan, i tend to think about my next step about a month before i take it, with the general rule being "go west".

I look forward to the next 6 months, and God willing, it will be even better than the previous 6 months.

在天

Tuesday, October 11, 2011

He who learns but does not think is lost; he who thinks but does not learn is in danger.

I've been in Australia for a 6 weeks now. The majority of that time has been spent bitching about how cold it was, and coding like beast to help get mChat ready for its next big release.

As a result I haven't really done any sightseeing, or at least I hadn't.

As a preparation exercise for when I go to South America I decided to take a bus from Sydney to Melbourne via Canberra. Total journey time came in at seat warming 15 hours.

I love having time to think, and I love to learn so the Confucius quote I used for the title of this post seemed perfect.

So what have I learnt?
Australia is huge and almost infinitely vast. At the moment I'm a hour and half into the Canberra, Melbourne leg. And all I've seen is grasslands. They extend for as far as the eye can see.

Having spent so much time in relatively small countries, buried in a mountain of technology you begin to think that the world is a small place. But in fact the "small" part is the series of interconnected hubs that form the major population centres. Outside of these you can find the "real world". One devoid of fibre, hi-speed rail, politics, and all the other assorted junk that we consider "modern civilisation".

So what do I think?
A good friend of mine what's to change the planet. Not in a "when I grow up" kind of way either. We often discuss how one would go about such a task. Perhaps to change the world what we need to happen is the reversal of the migration of people across the world to urban centres, in such of relatively low paid jobs.

Perhaps we need to allow people to return to the ways of the past, to build a better future.

In recent years anyone reading this would have seen slow destruction of society. As we have moved into the future we are slowly abandoning parts of our past that actually worked.

That's really insightful, so what can I do?
I haven't got a clue. If you'll excuse me I have another 8 hours on this bus. You never know, as I bridge the gap between these two centres of commerce and industry I might just discover the answer ...

Sunday, September 18, 2011

Brute forcing Router passwords

Someone in my house decided to change the password of the router. We share the access with about 10+ people, not all of whom i know so simply asking wasn't really an option. So like any normal person, i searched the internet and found a python script that does HTTP Auth brute forcing. The Indentation was out of whack, so once i fixed it, i thought i ought to share it with everyone.


If you do want to use it yourselves, you'll need a wordlist, which you can find with google's help.

Wednesday, September 07, 2011

Making UIImages with blocks

So i was going to post about something completely different today, but as i was typing i looked at my code, and thought it was verbose and a little bit ugly.

So i made it awesome, and as everyone knows to make your code awesome you add some blocks to it.

My problem was simple, i was faced with the need to create two CGBitmapContext, for the uniformed the following code is required to prepare a bitmap context for drawing.


So after a bit of thought, i decided what i really wanted was a method that did all of this for me, and meant that i didn't have to worry about constantly checking the code for leaks (DRY), and that was pleasant to look at and i came up with the above. The block that you pass in is given a fully formed CGBitmapContext, and the method returns a UIImage generated from that context. Almost like a UIView/CALayer.



So now your thinking, "Yeah, thats cool, but why the [INSERT FOUR LETTER WORD] would i want to use it ?" Well young grasshopper, have you ever wanted to mask a image in code? You know to do those trendy rounded corners ... well yes you can use CALayer's however the idea of using those off the main thread makes me uneasy, and we all know the cool kids do things in the background.


The above actually creates a rounded rect on the fly, and masks the image with it. It's made to be used in a category on UIImage. But look closer, yep thats right kids, no boiler plate, ZERO, NADA, 另, SQUAT (i think you get the point)!

I should take a moment to mention that the awesome code for the rounded rect comes from the awesome Oliver Drobnik, i have the utmost respect for this guy, not just for this snippet, but if you've ever seen his Rich text label and it's associated projects, you'll understand why real soon.

Friday, August 05, 2011

Tuesday, August 02, 2011

Waipo Valley Hike

While some people think i spend all my time on a perpetual vacation, it is sadly not the case. Everyday there is a little bit of something or another to be done.

However since i've been on the Big Island i've made an effort to try and relax, and actually have a vacation. Its not like i'll be having another one anytime soon. Being an iPhone developer and having loads of time off aren't compatible ideals.

So yesterday i started creaming myself on the prospect of visiting Waipo Valley, however it seemed so distance, and far from anywhere that it may as well have been on another planet. Initially i dismissed it, and decided instead to head for Akaka falls, a lovely 400ft waterfall only 20 minutes bus ride away.

However when my bus got to Akaka falls i didn't get off. It was a beautiful day, my camera was charged and my memory card was empty. I rode all the way to Waimea, in the north of the island, glimpsing the Towering Mount Kea, on the left and the steep coast to my right.



Though my consumption and research using the fantastic Offmaps i had learnt about a trail, just to the north of Waimea, that appeared to reach the valley. There is a more direct trek, that takes you to the head of the valley, however this is several Kilometers outside of town (READ not near the bus stop). So i decided to go a slightly different way, that allowed to me to go through town.


After walking though a residential neighbourhood to the north of the town. I found the entrance to the trail (above). Like all good hikers, i just ignored it and marched on.


After climbing the first hill, i got to what looked like a water treatment plant. Despite the signs at the gate, i vehicle from the Hawaii water department drove past me, but said or did nothing.


After the passing the water treatment facility i got to yet another gate, informing me that i was doing something or another wrong ... i ignored it and continued the march. With this particular gate i had to choices, jump it, or use the huge hole in the fence. It's always great to have options.


I was greeted by field full of cattle. I have to say that walking though a field of cattle by yourself is one of the strangest experiences i've ever had. They all just stare at you, and track your every movement silently. It reminded me a lot of when i was in China.


Climbing the hill further revealed a 50 million gallon reservoir, that was bone dry. I assume it fills up with rainwater run off over the winter, and then drains in the summer. This was one of three big reservoirs buried in the hills.


After another 5-10 minutes of walking a finally reached the Kohala Forest Reserve, at this point i knew it was on. I opened that gate and marched onward.


It went from grassy cattle pasture, to rainforest in the blink of an eye. The trail was easy to follow, but due to my naivety i was wearing trainers...


Trainers that got completely murked. There is a water pipe that runs along the trail, in several places it is leaking, which caused the mud trail to flood. Initially just walking on the grass was enough, but there were several places where this simply wasn't enough.

The landscape changed quite rapidly, going from rainforest to hilly plateau in a matter of minutes. While your at least 3 miles away from the nearest human being, you amazingly have 3 bars of AT & T service. I had turned data off to save battery. I'm not the worlds most amazing hiker so i didn't really want to be stranded in the middle of nowhere with half a sandwich, and Nutri-grain bar.
By this time i was almost 2 hours into the hike, I wasn't physically tired but the trail isn't scenic. There isn't much to see, and certainly no one to talk to. While i knew roughly how much further i had to go, the fact that i knew i had to retrace all my steps was beginning to depress the hell out of me. Especially as i was starting to consider if this dotted line that i had sacrificed my time to was actually a route to nowhere. I spotted a small hill up ahead, and made a deal with myself. If the canyon wasn't over the hill, then it was time to call it a day.


And there it was, 2000ft straight down, almost 4 miles in the middle of nowhere. I was at photographic "pay dirt". After about 10 minutes of this beautiful vista, i high tailed it out of there, rain clouds where all around, and this is the last place you want to be when it rains, especially considering that i wanted to salvage what was left of my trainers.

Overall i learnt a couple of things about my hike.

  • Never give up
  • Carry more food & water
  • Get hiking boots
  • Hawaii (Especially the Big Island) is beautiful.

Monday, August 01, 2011

Hawaii: Oahu & Hawai'i (aka The Big Island)

To be completely honest i knew very little about Hawaii as whole before i came here. But i've learnt a lot in the last 5 days. Mainly that i need to learn to drive. So thats definitely on the list for when i get home (finally).


Having flown into Oahu, i spent most of my time in Waikiki, Honolulu. As i was warned it was chock full of Japanese tourists showing off their Canon's and Nikons. I have nothing against my friends from the land of the Rising Sun, however i do suffer from a serious case of Lens envy.

After 6 days in the Japanese version of the Costa Del Sol, i've  flown to Hilo, on the big island, aka Hawai'i. Today, i felt like an idiot for even spending more than two days in Oahu.

Firstly the big island, is well, BIG. The road that runs around the entire coast is almost 300 miles long. I spent today in the car with some good people from Holland, we barely explored a quarter of the island. This place is huge.


What really stuck me is the differences in the flora in various parts of the island. In some places it looks like a Rain forrest, while in others it looks like the surface of Mars. The above is the beautiful rainbow falls.


This is an example of the rainforest like terrain. It even has a canopy that the Brazil Rainforest would be jealous of. Really makes me look forward to the day i finally set foot on the continent of South America, Un dia, un dia.


Then there is the black volcanic rocks. While i know the landscape was formed by magma, it almost seems as if it's been scared by it. I've been fortunate enough to see some amazing things. But this is truly fascinating.

Saturday, July 30, 2011

Auto incrementing version numbers in Xcode

Over the last month or so i've had to kick out a lot of betas for a project. Seeing as i use the fantastic Test Flight. I have to change the version number before i upload each build otherwise Test Flight will overwrite an existing build which is the last thing that we want.

I don't think anyone actually enjoys editing a plists, whether its in Xcode plist editor or the down and dirty XML. So has a result it was the perfect opportunity to get familiar with xcode's build process, and how to tie external scripts into it.

I use 3 segment version numbers (1.1.1), where the first digit is the major version, second digit is the minor version, and the 3rd digit is the build. For the benefit of the team, i wanted to have the latest commit hash in the build number so that people could quickly reference it and know whats going on.

With some direction from this post by Duane Sibilly i was able to hack together the below.

Friday, July 29, 2011

Wednesday, July 20, 2011

Goodnight San Francisco


The Mighty Pacific

When i'm not winning iOS Dev Camp, answering emails or writing code i like to take photos. Lots and lots of photos. As my time in the Bay Area comes to an end, i thought that it might be nice if i actually took the time to visit the Pacific Ocean.

Initially it was foggy (like it usually is) however it soon cleared up.


The birds came out...


As did the people ...


The sun shone ...


And everything was well with the universe (if only for today)

Friday, July 15, 2011

I Took a Picture [SF Edition]

HDR of San Francisco with 3 RAW 14Mpx Exposures processed in Photomatix Pro (Unlicensed ^_^ )

Sunday, July 10, 2011

Monday, July 04, 2011

The Golden Gate


After years of just seeing it in photos i got the opportunity to photograph it myself. It was the culmination of a fantastic day; the end of WWDC and an excellent talk by Buzz Aldrin.

Many people have asked during my journey if i keep a journal. While i don't in a conventional sense, photo's like these will help me remember this experience for a lifetime. 

What isn't always obvious is that the Golden Gate is essentially in the middle of nowhere. There is no easy way to get there from downtown San Francisco without a car, so i had to get my bike on, by chance i was able to rent one at a bike shop near 4th & Harrison. The $400 deposit scared the crap out of me at first, but it was alright in the end.

San Francisco is hilly place, so my plan was to cycle along the Embarcadero, which runs parallel to the shoreline (read: nice and flat). The previous link goes to my little weekend project. I built an app called gpxshare which allows people to upload and share GPX tracks for free. 



This was some what of a rambling post, but i just wanted to share some of these awesome pictures.

Tuesday, May 24, 2011

Core Data & Multi-Threading, part 1337

So i've made yet another Core Data Discovery, at this rate i might need to write a ebook. Now we all know that the golden rule of using Core Data with different threads is to not share contexts between threads.
So if you need to refer to an object on multiple threads you need to use it's NSManagedObjectID. Thats all well and good, but what if you need to call [NSManagedObjectContext save:] multiple times. Well in short it's gonna suck. Well thats cool you say, i can just use the id anyway ... Not quite. There are two types of ID's, permanent and temporary.
Now in my experience Core Data seems to get confused when you use temporary ID's to look up objects on another NSManagedObjectContext. So really to stop these conflicts we need to get a permanent id, but we need to obtain one of these ID's without saving the NSManagedObjectContext.


Well are you ready for the magic ... Shazam

[NSManagedObjectContext obtainPermanentIDsForObjects: error:]

This awesome method will take an array of managed objects, and give them permanent ID's. From my brief tests the overhead is minimal compared to the traditional save method.

Thats all i've got for today, keep on trucking.

[]'s 4 life

Monday, May 09, 2011

Asynchronous Core Data searches with Blocks

I was recently fortunate enough to be able to drop iOS 3 support on a project. This meant that i could start to play around fully with Blocks on iOS. One thing that has always got on my nerves is that there is no built in support for asynchronous Core Data searches.

Previously i tried to wrap up potentially long operations in a special FRCoreDataOperation a subclass of NSOperation. However this was a pain, as i would then have to subclass it or modify the parent class to provide me with a simple callback when the task was complete.

What i really longed for was the way in which you make Ajax requests in jQuery, that of course requires closures, which are of course provided in the form of Blocks. So after hacking around for a bit i came up with this.

Now this is my first real time using blocks outside of simple things like iteration etc. It means that i can do

Now here's the part where i pat myself on the back. The callbacks are executed on the main thread, after the async fetch request is completed. Plus it gets better, The NSArray, for the onComplete block contains a list of the returned objects that are registered with the NSManagedObjectContext for the main thread, or in other words the NSManagedObjectContext you used to perform the fetch.

Once i touch down in the valley i plan to extend this to manage saves as well, making the basic CRUD operations with Core Data "scroll like butter".

Sunday, April 24, 2011

Roaming in jamaica

£6 per MB and it's EDGE, give me strength please.

One flip side this country is a very different to the one I left. But for the most part different for the better.

Going to my grandparents house for the first time in 10 years has been fairly emotional. I'm still expecting to see them around house despite the fact the both have been dead for sometime.

I've compared it to a time machine, as it feels like I've just fast forwarded into the future. One without two people that I had come to know and love so well.

When I landed the lady at customs asked why I hadn't been back in so long (10 years), I'm slowly learning that it's because I knew subconsciously that it would be an emotional roller coaster.

Tuesday, April 12, 2011

Animating a series of images with CALayer

So you want a to animate a series of images, flip book style. While it is true you can use UIImageView, everyone knows that is for wimps. Real men (& ladies ;) ) use CALayer (like a boss)...

But how? Well you might have some how got in your head that CALayer's contents property supports a NSArray of CGImages. Well this is not the answer, remember that the contents property takes an 'id'as a argument so it supports virtually everything under the sun and then some. Hell, if you felt like making crazy things happen you could just throw a NSData object in there.

Anyways, the actual solution is to use a CAKeyFrameAnimation, to manage the rotation of your images, control the frame rate, and ultimately the duration.

Well all is said and done it should look at this

Sunday, April 10, 2011

Drawing text with a Gradient

Problem

You want to draw (unicode) text with filled with a gradient.

Solution

Since my middle name is now "Core Graphics", let me help you out. It's actually pretty simple. Create your desired gradient in a your image editor of choice, and save it as a PNG. Import it into your project and then ...

Yep folks thats it. Now if you find that your gradient is slightly out of place, you can use CGContextSetPatternPhase to help. You of course would use this before your drawing statement. The docs say:

The pattern phase is a translation that Quartz applies prior to drawing a pattern in the context. The pattern phase is part of the graphics state of a context, and the default pattern phase is (0,0). Setting the pattern phase has the effect of temporarily changing the pattern matrix of any pattern you draw. For example, setting the context’s pattern phase to (2,3) has the effect of moving the start of pattern cell tiling to the point (2,3) in default user space.

So when all is said and done you get this lovely effect

text drawn with a gradient Best of all this effect works all the back to iOS 2.0!

Saturday, April 02, 2011

Problem: Symbolicate won't ... um symbolicate.

Long live Crash reports, Crash reports are dead. We all love em right, couldn't live without them. But what happens when crash reports go bad. Sadly this isn't a lead up to a blockbuster movie but in fact a real life issue.

As much as a i love Xcode 4, (and i really love it) it swallows errors that symbolicatecrash script spits out. This caused me to send loads of time trying to fix an issue that i knew nothing about.

Well here's the solution. 

1. Do a project clean in Xcode (cmd+shift+K)
2. Delete the entire 'PROJECT/build' directory
3. Go to ~/Library/Application Support/iPhone Simulator/VERSION/Applications/UUID and delete each folder that contains your application name. Be sure to do so for each Version of the SDK.

And then attempt to symbolicate your reports.

I'm led to believe that some genius (who i'll target at WWDC and buy him/her a beer) thought it would be a great idea to use Spotlight to find dSYM files. Sadly i don't believe they thought (or could) apply any sort of search order, leading to spotlight returning random binaries. (When good ideas go wrong).

FYI. If your a member of the Xcode Team, i genuinely appreciate all the work that you folks put into 4.x.  

Thursday, March 31, 2011

Coming to America

So after managing to avoid the states in all forms for well over a decade it's time to go back. I'll be able to enjoy the benefits of naked body scanners, and requests to show my papers.

Anyways the trip is split into 4 parts, over two months.

A. New York city
B. Jamaica
C. Los Angeles
D. WWDC in San Francisco.

Interestingly, I have no return ticket, not because I'm planning on becoming an illegal (please note TSA) but because I'm not sure if I'm coming back to the UK or if I will carry on heading west, and reunite myself with the Chinese people (they miss me you know).

The first leg is booked for April 18th, so as song says I'll be "new York da da da dada da new York" HOV ...

While WWDC should be a blast the most emotional part will be going back to Jamaica almost 10 years to the date that I left.

Bon voyage

Tuesday, March 15, 2011

Jonathan @ 24

Well would you look at that. I'm 24 years old. Kinda strange I might add. Well being the kinda introspective dude I am, I thought I would look at my highlights over my 23rd year on this planet.

....

Yeah so that's it, fascinating don't you think. But seriously my 23rd year was a good year, and I'll strive to make my 24 th even better, with the usual smattering of travel adventures, odd situations and hard core forking.

Thursday, February 10, 2011

Creating Push Notification certificates that you can use .cert -> .pem

Thanks to this helpful the post, the rest of the world knows how to convert .cert files (the ones the ADC gives you) into .pem files, the ones you need to actually send notifications to apple.

To further aid this, threw together a little shell script that takes two arguements, the certificate.p12 file and the private key.p12 file and creates a apns_certificate.pem file. Saves a bit of typing and also gives you a hard copy of the commands needed to create the certificates

Wednesday, February 09, 2011

From Russia With Code


I had the privilege of travelling to Kiev, Ukraine for Business. For me this was first trip to eastern europe. Thus far i had only been as far as Hambug, Germany. Which even at it's height was in West Germany, and i believe in the UK control area, so it wasn't even that different. I'm writing this on the plane but i expect the culture difference to be close to that of china, but with out the squat toilets ...

In a way this is good prep for me as i've always wanted to ride the train from Moscow all the way to 北京, and maybe even on to Pongyang, DPRK (insert joke here).

The Standout things
* Everyone seems to like drinking tomato juice, in lieu of fruit juice.
* Haven't seen a samovar yet.
* Yes, they drink a lot of vodka.
* You never drink vodka without eating ... unlike the UK
* It's not as destitute as you would think
* A lot of people speak english, especially in service industry.
* My Russian is awful
* It kinda looks like that level from Call of Duty 4 modern warfare, you know, this one, seriously.

Sad i was only there for three days, three cold days, where i didn't go outside much. But hopefully i should go back in the summer so i'll have more to say and show then.






Wednesday, January 19, 2011

Why does Darren Bent cost £18 Million?

I think Bent is good goal scorer, with a proven record. But i don't think he's worth £18 million quid. Thats not an insult, i'm just old school and think that's a lot of money. (I don't think Chris Smalling is worth £7 million either, that is an insult ... to man utd ^_^, thanks Sir Alex we really like Dembele) It's a good question don't you think. I'm no accountant, but lets try and work this out. I'm always amazed at how a football clubs legal people arrive at these figures.and have felt that while they are crazy there has to be some kind of reasoning and logic to them.

It is slightly hard to do this as few things are actually official, but as Rafa says lets work with the facts (that are mostly rumours).

Darren Bent is rumoured to earn £50k a per week, and had 2 years left on his contract at sunderland.

That means that his contract excluding any bonuses or commercial rights is worth about £2.6 million a year or £5.2 million. I believe this should be his 'book value', and the value that would stated on Sunderlands accounts.

Next Darren's move to Sunderland from Tottenham cost £16 million, with a cash component of £10 and the additional £6 million to be paid in various (i assume) performance related bonuses. Now i would guess that a club like sunderland structured the majority of these payments to be done over a period of time, being that Bent only left a year and half ago, they probably haven't paid this total sum yet.

Lastly as reported, a cause in the deal with Tottenham, was that Sunderland had to pay them 10% of his next transfer fee, something they would also need to take into consideration when negotiating with Aston Villa.

So lets do some basic addition with the numbers above

£5.2m (contract)
£10m (purchase price from spurs)
£15.2m

Now lets say that Sunderland have a policy of trying to maintain a profit margin of around 10% margin on player sales, that puts us in a range of £16.72 million.

Now we are missing one thing, Spurs cut. Thats 10% right?

10% of 16.72 million is £1.72 million

Which i assume sunderland passes on to Villa, so we get £18.39 million. If if they can't legally do this £16.72 still isn't far off the headline £18 million figure that we see in the press.

In fact depending on how much sunderland and already paid tottenham in bonus related payments, they might not have even made a profit. Also i dont know if Darren's 50k p/w wage is before or after tax, because if it is after tax, the value of his contract to the club is effectively doubled. due to the 50% tax rate.

Not accurate, not throughly researched, but certainly interesting.

Next, how the hell did they work out 'CR7' was worth north of £70million?

If you got any insight for me please share either on twitter @veritech or in the comments.

Friday, January 14, 2011

OpenGL Docs

I was about to dabble with OpenGL in recently, when i made a horrific discovery.


Happy Friday :D

Tuesday, January 04, 2011

NSNotificationQueue, Coalescing and SIGABRT

So it's one of those days, your steaming along adding a feature and then bam, you hit a road block. Well here was mine.

I've come to love many cocoa API's over the last year. One i've been late to embrace is NSNotificationQueue. What can i say that hasn't already been made clear ... it's a queue for notification objects ... well almost it has one particular feature that makes it totally awesome, Coalescing.

Coalescing is useful for when you want to call a method multiple times but only have it execute it's action once every so often. Since i've started coding for iOS i've been a fan of simply calling [UITableView reloadData] to refresh my table views, it's simple concise and i don't have to worry about index paths etc. However if you are drawing complex cells, and you need to call this method while you process some data you really don't want to happen every single time, the user isn't playing COD, they just want to see their data, and not have it flick around. So in my UITableViewDataSource classes i do this ...


With the handler to the reloadNotification calling the actual reload method. This means that in one area of my app, where i am listening for NSManagedObjectContextObjectsDidChangeNotification (gotta love cocoa conciseness )the reload method gets called just once instead of 10+ times.

Awesome right ....

Well there is a problem, you might have noticed that enqueueNotification: takes a postingStyle. This calculates when in the duration of the run loop the queue will attempt to deliver your notification. Because i want my Run loop to be a free spirit and not care about what my crazy background threads were doing i would usually choose NSPostWhenIdle. Well i did till today.

The problem is the UITableView that this data source is assigned to can be dealloc'd at anytime, and while my dataSource is a good cocoa citizen and removes it's self as an observer before it is dealloc'd the notification has already been assigned it's target and is waiting till the run loop is idle ... read waiting till after my object has been dealloc'd. This of course means the the objective-c runtime attempts to call the reload method on dealloc'd object, and we all know what happens when that happens ... Well i thought i did. I code with NSZombieEnabled on, so in such a situation i expect to see a nice friendly message saying i've sent a message to an invalid object ... I got that message ... sometimes. Instead 9/10 times i got a big, fat, bold SIGABRT.

Oh, but you have stack traces ... um no. When crap happens in the objective-c runtime, you close your eyes and pray that they will go away, well thats what i do.

Anyways the solution was to ensure that notification was dispatched as quickly as possible, so NSPostNow was a much better fit. My professional($_$) opinion is that unless you have a long running object (ie the app delegate) or a singleton, never use the NSPostWhenIdle.

Conclusion

NSPostNow > NSPostWhenIdle
(9 out of 10 times)

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.

Friday, November 19, 2010

Ultimo Videos de Sevilla

My last videos from sevilla, headed to a Flamenco club with some new folks after my flight got cancelled, enjoy


Sunday, November 14, 2010

End of an era

This morning I found out that my grandmother died. While it's a sad event in and of itself, bares an additional level of significance.

It signals the end of Samuels surname. My grandparents only had girls, 3 of them to be exact. While my surname might be Dalrymple, I identify more with my maternal side of the family, and felt more in touch with that side of my family.

It was also that side of the family that was the first to come to England during the wind rush years, and is partly why I hold a British passport, and thus am able to live in Sevilla.

My grandparents did a lot for me, not only did they raise me but much of my personality and drive developed as a result of their influence. So I owe them a lot.

Sunday, October 31, 2010

Sevilla en el Video

Heres triplet of videos that i've shot on the iPhone 4 since i've been here.This first one is just some kids playing football down by the river.

This second video was taken one evening in one of the many plazas in Sevilla. The locals (mainly students), are doing pre drinks before rolling before heading to a club, or knowing so of them, just simply having dinner!

Friday, October 29, 2010

Day 22

Today was a personal milestone. It signified the longest time I've been away from home in my relatively short life.

Before this china held the record, at 21 days. Now while you could argue that I was in Jamaica for much longer, I was living with my grandparents so it was a very different scenario.

I'm relatively settled now, I know my way around town, my Spanish and more importantly my confidence in my Spanish is improving. I got some friends, most of whom speak English sadly.

How long will I stay for, your guess is as good as mine. But
the sevillianos are wonderful (& beautiful) people, they have awesome food and are really friendly. Why would I want or need to go else where.

Only time will tell, I look forward to the next 22 days.

Monday, October 18, 2010

Are you for real?

I've been in spain for 12 days. During that time i've been looking for a place to call home. My conversations with various parties have usually begun with this.

¿Puedo visitar de habitacion hoy o esta semana?
This is spanish for "Can i visit the room today or this week?" However some of the responses i get back to this simple request are crazy. Take this one for example

 Hello.Jonathan

         Thanks for the email and am really glad for you interest in my  Apartment.I owns the Apartment,My name is [REDACTED] and also want you to know that it was due to my wife's Sickness that made us to leave the  Apartment and also want to give it out for rent and looking for a responsible person that can take good care of the  Apartment, we are not after the money for the rent but want it to be clean all the time .So for now,I am in Benin Republic Cotonou in our new home and also I am with the keys and documents of the  Apartment,we tried to look for an agent that we can give this documents before we left but could not see and we don't want the  Apartment to be used any how in our absence that is why we took the keys and documents  along with us here and as you know that,I and my family are in the Benin Republic Cotonou on a christian mission of God all because of the sickness,so i hope you will promise us to take very good care of the  Apartment but your absolute maintenance of my  Apartment is most important thing.So get back to me on how you could take care of our  Apartment or perhaps experience you have in renting a home.Note that the rent is going to be ( 260 Euro) No extra fees.I will like you to give me a call on this effect to know how serious you are.Hope you are okay with the price  per month with DVD Player, air conditioning,alarm system. The kitchen is fully equipped with all necessary cooking utensils,refrigerator-freezer, four-hob and oven,microwave,dishwasher and washing machine and Dryer and i will want you to get back to me with the Application form below :


  APARTMENT ADDRESS:[REDATED]



            ========  RENT APPLICATION FORM  ========
            ========= PRIVATE & CONFIDENTIAL========  
     
    Also,Pls answer these questions below:
    1)Your Full Name__________________________ ____________
     
    2)Present Address(where you reside now) & Phone
      Number________________________ _______
    3)How old are you _____________________________
     
    4)Are you married ______________________________ _____
     
    5)How many people will be living in the  Apartment ___________________________
     
    6)Do you have a pet ______________________________ ___________
     
    7)Do you have a car ______________________________ ____________
     
    8)Occupation ______________________________ ___________________
     
    9)What is your religion ______________________________ ______________
     
    10)How long are you willing to stay
    ______________________________ ___________
     
    11)When do you intend to move in ______________________________ ___________
     
    12)1 month Or 2 month deposit needed ______________________________ ________
     
    13) Pictures of all the Occupant that will stay in my  Apartment ______________________________ ________
     
    Looking forward to hear from you with all this details so that i can have it in my file incase of issuing the receipt in your name and contacting you.Await your urgent reply so that we can discuss on how to get the keys and the documents to you,please we are giving you all this based on trust and again i want you to stick to your words,We are putting everything into Gods hand,so please do not let us down in this property of ours and God bless you more as you do this. Pls note that you will be viewing the  Apartment from outside and won't be able to inspect the Interior because the keys and the documents to the  Apartment are with me here in Benin Republic Cotonou and It is located on a cool, quiet and safe neighborhood.
     
     
    Thanks and God Bless.
    Regards.
Um, ok. So do you want to take me out into the woods and shoot me too? I thought for a moment, that this could be true story, even though it may as well have had SCAM in the title. Later that same day i got another email from another landlord.


Hola,
La renta mensual es de 450 euros para todo el piso, incluyendo todos los servicios públicos (agua, electricidad,gas,calefacción, Internet, TV,garaje, aire acondicionado, lavavajillas, recogida de basuras). Se puede mover en cualquier momento. El problema es que soy la única persona que tiene las llaves y estoy lejos,en Romania con mi trabajo, pero si sigues interesado podemos tratar algo,utilizando un servicio de efectivo en entrega como TNT, que se encargará tanto de pago y la entrega de las llaves en la manera más segura para usted.
Gracias
Thanks to google translate ...

The monthly rent is 450 euros for the entire floor, including all utilities (water, electricity, gas, heating, Internet, TV, garage, air conditioning, dishwasher, garbage disposal). You can move at any time. The problem is that I am the only person who has the keys and I'm far away in Romania with my work, but if you interested we can work something out using cash on delivery service such as TNT, which will handle both payment and delivery of keys in the safest way for you.

Wow, so apparently everyone in Sevilla goes away and takes their keys with them. Maybe they need an iPhone app for that ...

Tuesday, October 12, 2010

Los Negros

So I've been in Sevilla almost a week. What can I say its a cool city. Filled with beautiful women, nope of whom speak English. But hey I wanted a challenge.

So like all places what makes Sevilla so different from Hemel Hempstead. Well there are a lot of differences. There are no crazy roundabouts, the women look better, and they speak better English... I think the biggest difference is the attitude of the people. People here place a premium on family and community. The focus on work is significantly less and 'hustling' mentality is almost absent. The people here wish to enjoy and their lives. That's not to say I've moved to a society of lazy folks, but they certainly do know how relax. As one person put it 'they work to live, not live to work'.

The search for a place to live is going slowly, I've decided that I want to live with Spaniards as that's the only way I'll improve my Spanish. While it's difficult, nothing worth doing is ever easy right?

What has made this trip a great deal easier and somewhat less nomadic, is the presence of Jason, in his own words the 'original g'. However I prefer a more apt term for the two of us, Los Negros. He also happens to cook a mean steak.

Friday, October 08, 2010

48 Hours

In 48 Hours i've met, and gotten to know the following

6 Aussies
8 Americans
1 Canadian
3 American Iraqi War Vets
2 Spanish Teachers
Several Spanish students
2 Beautiful German ladies
A load of Germans
1 Korean women needing her photos backed up.
1 Moroccan
1 Frenchman

And last but not least, 2 Brits.