Confessions of a Flash Addict

"forgive me father for I have flashed"

iOS Quicky: Securing and dumping data from Keychain

keychainFor one of the latest projects I’m working on we are relying heavily on online/offline usage and storing data in the Keychain (Apple’s safehouse for passwords and other secure stuff). For this I’m using a class provided by Apple called ‘KeychainItemWrapper’.

You can download it from Apple’s site.

My approach was simple; When my view was loaded I would setup the Keychain and under certain circumstances I needed to clear a key/value combo, I would do this.

- (void)viewDidLoad
{
    self.keychain = [[KeychainItemWrapper alloc] initWithIdentifier:[[NSBundle mainBundle] infoDictionary][@"CFBundleDisplayName"] accessGroup:nil];
}
...
- (void)resetKeyChain
{
    [self.keychain setObject:@"" forKey:(__bridge id)kSecAttrAccount];
    [self.keychain setObject:@"" forKey:(__bridge id)kSecValueData];
}

Boy was I was dead wrong – it would not clear my keys from the Keychain. Took me hours to find a solution – looking for the proverbial needle in the keychain. (Debugging Keychain is a bitch. Also when deleting an app, the keychain is not cleared, which makes it next to impossible to see changes).
A better approach would be to set up the Keychain like so;

- (void)viewWillAppear:(BOOL)animated
{
    self.keychain = [[KeychainItemWrapper alloc] initWithIdentifier:[[NSBundle mainBundle] infoDictionary][@"CFBundleDisplayName"] accessGroup:nil];
}
...
- (void)resetKeyChain
{
    [self.keychain resetKeychainItem];
}

This would clear the appropriate stuff from my Keychain and present my user with a login dialog again. Problem solved :-)

Day Against DRM 2014

Most of you know I fully support privacy, freedom of speech and am against vendor lock-ins. When I buy something I want to own it, because I paid for it, I want to hack and adjust that object if it does not fit my needs completely an I certainly don’t want to lease it from a vendor.

Just like last year several online book publishers are coming together on the ‘Day against DRM’ – download, keep or share your purchase. And I fully support this! That’s why I’m writing this post.

O’Reilly, who always publishes books without DRM, is doing a massive discount today by offering you 50% off on everything they offer. You can use DRM2014 at the checkout. (Of course I would love it if you picked up a copy of my book ;-)

Packt is offering all its DRM-free content at $10 for 24 hours only on May 6th – that’s all 2000+ eBooks and Videos.

So I hope you support this cause too and pick up some great books in the mean time.

Git autocompletion and autocorrect.

At work i use Git *alot*. Most of the time I type too fast and my screen produces jibrish, commonly known as typos. To prevent this frmo happening, there is a fix.
Git itself has a bunch of configuration options to customise behaviour, preferences and visual appearance.

The manual states;

help.autocorrect

This option is available only in Git 1.6.1 and later. If you mistype a command in Git, it shows you something like this:

$ git com
git: 'com' is not a git-command. See 'git --help'.

Did you mean this?
commit

If you set help.autocorrect to 1, Git will automatically run the command if it has only one match under this scenario.
git config --global help.autocorrect 1
The final parameter to that command is the amount of seconds, unline what the manual states. Setting it to 15 means 1.5 seconds, setting it to 1 means 0.1 seconds.

Git Autocompletion.
Open up Terminal and type in the following;
curl https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion

This downloads the git-completion script and places it in your home folder.
Open up ~/.bash_profile with your favorite editor and add the following line at the end of it.

source ~/.git-completion

You are now good to go. No open a new Terminal tab or force this command by ‘refreshing’ the terminal by typing source ~/.bash_profile Still in Terminal type git com and press the tab key. This should either autocomplete the command or if there are more commands starting with ‘com’ show you a list of possible options.

Enjoy! No moer typos in Git.

UncrustifyX to use with your Xcode 5 formatting needs

For the past couple of days I’ve embedded myself in Xcode and making the most out of Xcode, using plugins and generally getting to know one another. Yesterday figured out how to do proper code formatting using Uncrustify. I’ve looked at multiple formatting templates and after playing around with several tools, I decided to use UncrustifyX. It is a visual tool to play around and create your own code formatting style. I’ve tweaked, churned and crunched out my own formatting style for others to play around as well which you can find on my GitHub account.

From frustration comes inspiration – Source formatting in Xcode 5+

Tools Workshop[UPDATE: To fix this for Xcode 5.1 - please scroll to the bottom of this page]

From frustration comes inspiration – one of my biggest frustrations while using Xcode is that there is no build in way to do code formatting. Well ok, you do have ‘re-ident’ but that is mostly a manual process and i like using the keyboard. Also this is not quite what I was after.

After some searching I found Uncrustify a generic “Source Code Beautifier for C, C++, C#, ObjectiveC, D, Java, Pawn and VALA”. I checked out the sourcecode, build it and placed the newly created binary in my bin folder. Next up was this Xcode plugin. Easiest and fastest way to get this on your system is by unzipping the binary and placing it in your ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins folder. Don’t forget to restart Xcode after you do this.

After you restarted Xcode, you can open the plugin by navigating to Edit -> Format Code

  • Use the menu Format Selected Files to format the selected items in the project navigator.
  • Use the menu Format Active File to format the source file actually opened in the editor.
  • Use the menu Format Selected Lines to format the selected source code (multiple selection is supported). The selection is automatically extended in full lines. If the selection is empty, it uses the line under the cursor.
  • Use the menu Edit Configuration to edit the formatter configuration in an external editor.
  • Use the menu BBUncrustifyPlugin Preferences to change the plugin preferences.

The real magic happens when you assign it to a key binding. Unfortunately this cannot be done in Xcode and have to be done system wide. So go to System Preferences -> Keyboard. Under Keyboard Shortcuts select ‘Application Shortcuts’ and press the plus sign to add a new program. Select Xcode and call it Format Active File. The naming is very important to be exactly the same as the actual item in Xcode. Naming it differently makes it unusable.
Screen Shot 2014-02-12 at 11.22.07 AM

Formatting.
You can also use different configurations for your own source code. If you create a directory called .uncrustify in your user home directory and check out this repository in that location, you have a very good starting point for your own formatting style. If you have questions regarding the formatting and indentation etc, there is a lot of answers on StackOverflow, be sure to check it out if you want to make your own formatting magic happen.

When you go back to Xcode and you see a key binding next to the Format Selected Files you know everything worked out.

Screen-Shot-2014-02-12-at-11.35.37-AM

Et voilà! Pressing that key combo adds magic/formats your source code in the flavor you like. Enjoy!

[UPDATE]
To make this work for Xcode 5.1 find the plugin file, right click on the file and select ‘Show Package Contents’ and open up the Info.plist in a plain text editor. Then look for the key DVTPlugInCompatibilityUUIDs and add A2E4D43F-41F4-4FB9-BB94-7177011C9AED under the last entry. Save and reopen Xcode. Tada!

 

Adding keybindings in Xcode 5

I’ve been using Xcode for quite a while now, but it still takes some getting used to. Today I had enough and wanted to add my own bindings for “duplicate current line” and “delete current line”, something i’ve been used to in FDT.

I’ve found some resources that help me on my way, so here is a quick reminder/walk through to do it (I don’t take credit for exposing this method, i just use it). It takes about 3 minutes to set up and can save you *a lot* of frustration.

  1. Find IDETextKeyBindingSet.plist in the folder /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/ Resources, get the file info and change the rights to “read & write” for user everyone. This allows you to make changes to the file. Now open it in Xcode.
  2. Add a new key as a Dictionary and call it Customized and add a String.
    Screen Shot 2014-02-10 at 1.16.01 PM
  3. As String key add Duplicate Current Line and as value fill in selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:
  4. As String key add Delete Current Line and as value fill in deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToBeginningOfLine:. Save file and close and reopen Xcode.
  5. Now go into “Key Bindings” under “Preferences” and press Customized
    Screen Shot 2014-02-10 at 1.15.41 PM
  6. Now give the two newly added key bindings the binding you’d like, i’ve set mine to CMD-D for deleting a line and CMD-SHIFT-D for duplicating a line.
  7. Enjoy!

Code Reviews

code_review5For the last months I’ve been doing a lot of Objective-C. Got a new job and only focus on iOS development. Since I am the new guy in the team, I learn a lot by looking at code from my peers (and looking at code in general). And even though I have a lot of ActionScript experience under my belt, I’m starting fresh with Objective-C. Frustrating at times, awesome most of the time. I love being the new guy. I get to ask dumb questions, can still write silly code and make a lot of beginners mistakes. And challenge my peers by having Shoshin or beginners mind.

One of the things I really love is code-reviews by my peers, they are mandatory at the place I work. They basically go through my code and comment on it when I fuck up or make dumb mistakes. Lately I had to return the reviewing favor.

Looking through code of my co-workers and myself I noticed a couple of things and thought it would make a good bit for an article. I’ll go through as much of the bad stuff I can find and discuss them here. As habits are hard to change, get in the habit of changing them as soon as you see them in your own code. This is by no means a definitive list and if you have suggestions for more, let me know in the comments.

1. Commented Code
Since you use a VCS like Git or SVN, there is absolutely no need to leave commented code in your source files since you can always revert. So remove it.

2. Duplicate Code / KISS
If you have a lot of duplicate code all over the place – you are doing it wrong. KISS and refactor (see point 6.)

3. NSLogs
Since Apple defines logging *only* for errors, a better way to get information from your app is by utilizing your debugger. There have been numerous articles about not using NSLog in (production) code and why it’s better to use a breakpoint. The cool thing about breakpoints in XCode is that you can use non-breaking breakpoints that send a message to the output window.

4. Retarded and/or short unreadable variable names
No matter what language you write code in, you always need to make sure it is readable. For your team members or for yourself when you come back to a project a year from now. This includes the correct naming of variables. Since Objective-C is by itself a very verbose language, variable name tend to have the same tendency. Using myReallyLongVariableName is oke, since compilers nowadays are optimized to deal with this. Verbosity and readability over brevity and difficulty to read code.

5. Small is beautiful
Just like an app or program, methods need to do one thing only and do that one thing well. Like the UNIX philosophy.  That’s what I’m taught and still believe. Don’t bloat your methods with doing six things. This makes it very difficult to read, understand and debug. Small is beautiful.

6. OOP.
What I see *a lot* is that people don’t know how to use proper OO. Not knowing how to extend classes or know how to design to a protocol (Objective-C’s term for interfaces) is basic stuff. Don’t be afraid to ask your peers, even if you’ve are an (iOS) senior.

7. Design Patterns.
While design patterns are not a magical, ready made solution or a silver bullet if you will, i do advise you to get a proper book on design patterns and learn about Model View Controller (MVC), Key Value Observation (KVO) / Observers and Delegation. These are the fundamentals of iOS programming.

8. Refactoring
The problem with writing code is that there is always ego involved. Even in ego-less programming (MUST READ!). That one brilliant solution you created for that one project will look like crap to another team member. People see things in different ways and that is oke. People do things to solve problems. Don’t try to rewrite everything just because it doesn’t look proper to you, try to put yourself in their shoes when they wrote this piece of code you are looking at. And breathe.

9. Lose the Ego
Reality check: Your code is not you. What? Your code is not you. It is just a solution to a problem, even though sometimes a very good solution. Don’t think you are the only one that can have good solutions. I don’t. (Well I actually do, sometimes – but I’m learning) The best solution come from unexpected corners or people. Even veterans make thinking mistakes, I know I do. And lose the ego. Realizing that makes you grow and makes better software.

10. Take responsibility
The next person that says “Nah that wasn’t me that wrote this” will get a kick in the groin. Seriously. I truly believe developers in general need to take responsibility for the code they create. Not taking responsibility is not believing what you wrote in the first place. You do care about your code right? Otherwise you are in this for the wrong reasons. Making a mistake is not the worst thing that can happen, it’s just a piece of code we are taking about. So have some balls.

BONUS. My debugging mantra
As I already mentioned on Twitter some time ago; Bugs are communication errors between you and the machine and can be fixed by asking ‘what do you think i said and why do you think that?’. Taking this step back can help you debug faster.

So. Embrace change, be open, don’t be cocky, loose the ego, look with children’s eyes, have a shoshin mind and enjoy what you are doing – only then will you grow as a coder.

UPDATE: We are back – server migration

keep-calm-the-server-is-downWe’ve had some downtime lately, a week orso – and i apologize for that. Because I maintain my own server and this domain was still on an old host, host transfer and migration can sometimes be a pain in the butt – maintaining a server is cool, but also time-consuming and the last week i could not make the time to do this properly. But now i did.
So without further ado – this domain is now fully migrated to my new server and you can keep on reading every post on this blog!

Interviewing Grant Skinner for Project Touch

filepicker_zBZhEi9CQIGfFXNrAbBj_touchI have to confess – One of my all time heroes is Grant Skinner. Ever since I got into Flash, version 4 at the time, he was already making amazing stuff and pushing it’s limits. When I was contacted two weeks ago to interview him, it took literally nanoseconds to formulate my answer. “YES!”.

He is the lead inspirator for Project Touch – a co-production between Code d’Azur (company where I used to work) and Microsoft. The goal of this project: To push the boundaries of the technology and create a community driven video touch editor in HTML5. Prerequisite: it needs to run on every possible tablet. Quite a challenge indeed. They’ve set up a Github account so you can fork the project and a mini site for the participants.

There are between 40 people here, mostly all Flash developers, JavaScript developers and designers. Lots of familiar faces – every ‘head’ of the Amsterdam creative industry is here. This is going to be fun! We start the session by Grant giving an introduction on why he is doing this and what started it all. He lets us know he is by no means employed by Microsoft or an evangelist for their product – he is just helping them improve their products by testing, giving feedback and helping organizing event like these. They already preselected the teams that will work together today – completely random. Very cool and completely out of my comfort zone. I know nobody at my table, but that soon changes. I’ve surrounded myself with some of the best heads the industry has to offer. Everyone introduces themselves and what kind of work they do and tells their specialty. Some are better at UX, some better at coding and some design. But first things first – you can’t code with an empty stomach so… the organization ordered some pizza and beers! After this culinary intermezzo it’s time to get cracking. Grant joins our table to get us started and poses some interesting questions about performance and the technical challenges that lie ahead.

After about an hour we have jotted down loads of ideas, hit the wall on some technical explorations but do have an overall idea about where we are going and what needs to be done in our timeline. Every team comes together for one final session and some closing thoughts by Grant and Nik Nieuwenhuis shows us a final demo of some cool stuff that can be done with HTML5. A very good session that lay the groundwork for everything to come. Inspirational and fulfilling.

But what what about the interview you ask? I got the chance to ask Grant a couple of questions about life, work and play.

Q: The company GSkinner has been around for 9 years. What do you think is the difference between you and any other company out there that does interactive experiences?

A: In those 9 years we’ve been mostly led by innovation – we invest loads of time in innovation and push the limits of whatever technology we are using, Flash or Javascript it does not really matter – innovation can happen with any technology. We grow our own talent, we take students fresh out of school and let them shadow one of our senior developers before the are up to production speed. We’ve grown steadily to about 15 people and our longest working employee, excluding me, has been there for more than 9 years. The average time people stay at our company is about 6 years. The are a bunch of post on our website where we explain our full process. “Introduction“, “Hiring“, “Orientation“, “Training“, “Planning“, “Production“, and “Shadowing“.

Q: What drives you to do what you do?

A: It’s like running – a mental challenge to keep pushing further and further. That and I get bored easily so I need new exciting and different things. Hahaha!

Q: What is your advice for aspiring developers?

A: Play. Play with code. Do silly experiments. Make it, then through it away. Start over to see if you can make it better. Develop a love for coding. Build what you want to get payed to build.

Q: What does the future of touch bring? Where do you see it going?

A: That is a difficult one, we’ve only been doing touch and gestures for less than ten years. A not yet explored world is haptics, i think there can be a lot more done in this field. There are some extensions to devices that bring feedback to games but there is still so much to explore!

 

Current developments: My own company and teaching at the SAE Amsterdam

As of march 2012 i quit my current day job at Lost Boys Amsterdam and started my own company primarily focusing on creative concepts and development of mobile applications. Doing this under the name of Mannetje de Koning I’m running freelance for 7 months now and aside from the occasional bump in the road it’s been going steady. I’m learning a lot about entrepreneurship, everyday again.

I have to admit running your own company comes with a lot responsibility. You constantly have to manage yourself and your time. And one of the side effects of this is that i haven’t taken the time off to write about all the stuff i’ve been doing. That is what this post is all about.

For the last two weeks I’ve been teaching at the SAE in Amsterdam, again. I teach the “Programming AS3 and OOP (Object Oriented Programming) course”. And the good people at the SAE also purchased my book, so i can teach from it. Very cool. Overall I love to teach and my goal is to make the students just as enthusiastic about programming and AS3 like me. Every lesson I start with about 10 to 15 minutes of inspirational videos about what can be done with programming and not just AS3. Then i explain about how the thing i’m showing can be made and how to approach a problem like this. Below are some of the stuff i showed them yesterday.

Augmented Tape Art Live Action from JACQUES-ANDRE DUPONT

Faces from arturo castro.

Interactive Puppet Prototype with Xbox Kinect from Theo Watson.

SketchSynth from Billy Keyes.

Spatially aware devices from Ishac Bertran.

levelHead v1.0, 3 cube speed-run (spoiler!) from Julian Oliver.