Test post for possible hovercard issue

I’ll be adding comments here.

Blog Moved!

I’ve finally decided that being a real software engineer it was about time for me to have a “proper” blog. Enjoy mokacoding, powered by Jekyll and hosted on the GitHub pages.

All my coding posts are there. I still have to decide what to do with the few other muggles posts.

It’s been fun using WordPress, but the thrill and simplicity of writing my posts in Markdown is really and publishing them via git push is something my geeky soul needed.

Some things I learned in July

July has been a month dense of learning and (re)discoveries! First of all Rails 4, which I come to love back in the day, when I was working with my friends on the first prototype of Kunerango

Objective-C and iOS Development


Guess what? CoreData doesn’t make your life easy when you’re seriously working with test, http://stackoverflow.com/questions/1876568/ocmock-with-core-data-dynamic-properties-problem. I like the protocol approach, even if it adds a some “boilerplate code” to maintain.

nomad a set of useful tools to automate the every-day development. Another gift from mister Mattt.

Ruby on Rails

Rails 4 finally out! http://weblog.rubyonrails.org/2013/6/25/Rails-4-0-final/

Nice and clear guide to testing with RSpec on Rails http://everydayrails.com/2012/03/12/testing-series-rspec-setup.html

Binstubs, because the less we type, the better! http://blog.barbershoplabs.com/blog/2013/03/01/upgrading-to-rails-40-binstubshttp://mislav.uniqpath.com/2013/01/understanding-binstubs/http://robots.thoughtbot.com/post/15346721484/use-bundlers-binstubs

The haml-rails gem integrates with the template generators, out of the box!

How cool are named routes? post 'items/move_down/:id' => 'items#move_down', as: :move_down ), look at the routes.rb comments to know more about them.

Amazon AWS S3 gem http://amazon.rubyforge.org

I found a nice gem to add enumeration type to the ActiveRecord models: active_enum, but is it compatible with Rails 4? Here’s a link on how to use it http://qubitlogs.com/Rails/2013/02/01/creating-pre-defined-set-of-attributes-mapping-integers-to-strings-in-rails/#.UdWbpT6DQ_U


I wrote some scripts to speed up some of my daily task at work, and used some nice gems in the meantime:
nokogiri, to parse HTML using CSS selectors
rest-client, fetching pages from the web with one line of code
json, to parse JSON
diffy, comparing strings has never been so easy
mail, sending emails from your scripts

Coding Recipes



Several ways to run a command line command from a Ruby script.


Fixing Postgres connection error on OS X Mountain Lion http://jaygoldman.com/2012/11/fixing-postgres-connection-errors-on-mountain-lion/ (funny because with Node there were no problems)


I looked into a bunch of Javasciprt techs: Underscore.jsJadeHandlebarsStylusExpress



Software Engineering Good Practices

Coupled dependencies, I found one of those monsters in a colleague’s code. It took a lot of self-control to avoid being a prick and pointing it out on GitHub.

Interesting readings

How Basecamp Next got to be so damn fast without using much client-side UI

What I did in a week…

As promised one week ago, here’s a report of what I managed to do in this unusually full of free time week.

I’ve caught up with Arrow and Game of Thrones. The Red Wedding was better in the book, in my opinion.

Oh! Yes… I did some coding as well 😀 I’ve completed the MVP of my iOS app, and I have a working and tweeting setup of the Twitter based Rails App.


I’ve built a simple app using CoreData and MagicalRecod for the data storage, focusing on a simple gesture based UX, powered by JTGestureBasedTableView, with an iOS7ish look. The idea was to roll it out on TestFlight for a week or two and then submit, but the recent cracker attack at Apple have delayed plans. I also used my two WIP pods MGCraftman and MGObjectiveUtils, but the project is simple so I didn’t have the occasion to add stuff to them.


To implement my Twitter based web app I’ve relied on the twitter gem, which does all the dirty work for me. I’m using Haml for the templates, I love it, so minimal and clear. I’m also gonna use SASS for the styling. So far I’ve only been using LESS, so I decided to give it a twist.

Good Practices

Both the projects are obviously being implemented in a as much test driven way as possible! rspec and webmock on the Ruby side, Kiwi on the Objective-C one. Neat!

Finally my simple PR on xctool has been merged, and I’m proud of it. And surprised no one thought about coloring the result output before…

That’s all. I’m overall satisfied of what I managed to build. Although I could have avoided watching half a season of Arrow in two days while coding and focusing more… -.-



A week of time…

I found myself in an unusual situation: my girlfriend is gonna be away for a week, and almost all my friends are already busy for the weekend. This means that I’ll have a lot of lonely time!

What am I gonna do? The answer is easy: code as much as I can, and enjoy the sun that’s been blessing London for the past days.

I’ve actually already started coding. I’ve just submitted a PR to xctool, let’s see how it goes…

I’m gonna write again in a week and report my progress. Hopefully I’ll have an almost ready iOS app, and an embryo of a Twitter-based web-app ready

CocoaPods: the $(inherited) flag

Edit: the blog has moved! Check this article here.


I’ve done it a lot of times by now, but I keep forgetting it. So here’s a quick post to commit it to memory!

If we have a project with the Tests target it can happen that after running pod install we get this messagge:

[!] The target `MyProjectTests [Debug]` overrides the `FRAMEWORK_SEARCH_PATHS` build setting defined in `Pods/Pods-MyProjectTests.xcconfig'.
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

How can we “use the $(inherited) flag”? Where should we add it?

The $(inherited) flag is an flag we can pass to the linker and that does some magic…. I haven’t been able to find a proper explanation for how $(inherited) works, although it’s easy to guess from the name.

Being a linker flag we can add it in our target Build Settings > Other Linker Flags section.

Screen Shot 2013-07-10 at 00.16.36

That’s all. I feel better now that I’ve put this piece of memory in the external storage of my brain that is the internet. And I hope it may help someone else too.

Some things I learned in June

Last month I decided to start keeping track of the things learned along the way. This list at the moment seems kinda short, let’s say that’s because I didn’t start keeping track of the stuff from the beginning of the month.


Testing Objective-C classes equality: http://stackoverflow.com/questions/10944460/testing-class-equality-in-objective-c

Objective-C _cmd returns the method name within a method: http://stackoverflow.com/questions/2770307/nslog-the-method-name-with-objective-c-in-iphone

You can use a Pod locally: https://github.com/CocoaPods/CocoaPods/wiki/Working-on-a-pod

Systems and Tools

How to stop autocorrect in zsh:


Where does the Logarithm name come from:
“Napier first called L an “artificial number”, but later introduced the word “logarithm” to mean a number that indicates a ratio: λόγος (logos) meaning proportion, and ἀριθμός (arithmos) meaning number.” http://en.wikipedia.org/wiki/Logarithm

Brownies by Mistakes – Attempt 2

So last weekend I made brownies again. The result of attempt 1 was way better than I expected so I decided to see if it was just luck or if the recipe I accidentally created by mixing a couple found online was actually good.

This time I used half the size of the ingredients, except for the white chocolate chunks which didn’t look enough to me last time. I also used the same oven container, to have thinner brownies. The results were positive, but I made other mistakes, and repeated some of the old ones!

Mistake number 1: Always check what you have home before going to the super market. Specially if you don’t live by yourself
Yep… I forgot to check the sugar already. I finished it last time, and I assumed it was still like that, but my flatmate bought new one. Not that having a spare pack of sugar is a bad thing, but it could have been avoided

Mistake number 2: Weight your ingredients before starting… and prepare all the rest as well!
I weighted everything on front but… I forgot to cut the chocolate to pieces, which is something that’s not as fast as you’d expect.

Mistake number 3: Don’t Facetime your mom while you should focus on making brownies.
To be fair, my mom Facetimed me. Anyway, speaking with her I forgot to add the eggs one by one, which provides a better meshing, and to keep track of the time I put the dough in the oven.

The mom call had a positive contribution though. Here’s a power tip: cut the exceeding paper before putting it in the oven. Ok maybe it’s not such a power tip, but I didn’t thought about it…

Mistake number 4: Don’t cool them down in the fridge
There are many post on how to cool down brownies quickly. I tried to put them in the fridge after a couple of hours after taking them out of the oven. Mistake! All the tips are for people in a rush. I was in no rush, in fact I went to bed and left the brownies in the fridge all night and part of the morning. They ended up being not as softy and gluey as they were supposed to be.

Here’s the only picture I took of them, we ate them pretty quickly!

2013-06-23 12.24.28

That’s all for now. I’ll probably let the brownies rest and try something else next time.

mokagio’s self memo for Facebook Integration on iOS – Part 1

Part 1 – Facebook Login

0 – Create a Facebook App

Create an app on the Facebook App Dashboard, what are you gonna integrate otherwise?!

1 – Add the Facebook SDK Pod

Given that you have already setup your libraries management with CocoaPods, and you should have, add to your Podfile the line

pod "Facebook-iOS-SDK", "~> 3.5.2"

Then run pod install.

For more info about how to use CocoaPods check out this post of mine.

2 – Add some Facebook data to the Info.plist

Facebook requires you to add two fields to your Info.plist file:

  • FacebookAppID: a 15 digits number you can find in the Settings page of your app on your Facebook developer page.
  • FacebookDisplayName: how to comment, the display name of your app?

3 – A basic login flow

The tutorial tells us to put all the Facebook login in the AppDelegate. I don’t like this approach, because I don’t want to make the delegate dirty with code related only to Facebook. I prefer to create a FacebookProxy class, with class methods to call to interact with Facebook.

Whatever solution you prefer the steps for the login are the same anyway:

  1. Check if the user is logged already. Let’s assume he isn’t…
  2. Present in some way a call to action for the Facebook Login.
  3. Call the Facebook SDK method to login the user.
  4. Let the SDK do it’s job.
  5. Come back to the app and handle the result.

Check if the user is logged in

To get the current Facebook session we use FBSession.activeSession. To see if the session is active, and therefore the user is already logged in, we need to check the state property: FBSession.activeSession.state. A quick look to the typedef enum of the FBSessionState and:

+ (BOOL)isUserLoggedInFacebook
    if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded
        || FBSession.activeSession.state == FBSessionStateOpen
        || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {
        return YES;
    } else {
        return NO;

Call the Facebook SDK method to login

Easy peasy:

[FBSession openActiveSessionWithReadPermissions:nil
                              completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
     // handle stuff here

In the completion handler we should… handle the result of the open active session. I think that this really depends on what our app will do, so I’m not gonna write any snippet here.

Come back to the app and handle the result

If you’re user’s are using iOS 5 -I hope they’re not-, or if they’re so dumb they haven’t installed the native Facebook app for iOS, the login will occur with a sort of modal window in your app. In all the rest of the cases the

Frameworks needed in the Test Bundle

TDD is the way. Full stop. I noticed that adding the Facebook-iOS-SDK pod to my project wasn’t enough for my test bundle to run, there were some framework dependencies missing:

  • AdSupport.framework
  • Social.framework

Brownies by Mistakes – Attempt 1

The other day I accidentally ripped my girlfriend’s curtain trail off the wall. To be forgiven I had to make brownies. I never made brownies before, but I’m always up for learning something new… In this post I’m not gonna write how to make brownies, or copy one recipe from a site better than mine. Surely if you’re reading this you’re able to use Google to find a proper recipe. Or you are my mom. I’m gonna write about the mistakes I made, so that may be I won’t make them again, and you will avoid them. Brownies #1

Mistake number 1: Always check what you have home before going to the super market
I was sure I had plenty of sugar, turns out I hadn’t! Lucky enough one of the recipe (see mistake number 2) I followed recommended two types of sugar, so I had some sugar anyway.

Mistake number 2: Follow a recipe, only one!
Since I never made brownies before I read many -I’m joking, just 3- different recipes before starting. But then when I was making them I kinda mixed two of them, not really smart. Next time I’m gonna stick to one and one only.

Mistake number 3: Once in the oven they’ll grow…
I had prepared a nice rectangular tin, but when I put the dough in it looked too big for it. I was scared I’d had to spread it so much that the result would have been too thin. I was wrong! I didn’t know it would have grown during the cooking, so I just put it in another smaller circular tin. It ended up being 1.5 times taller than I expected…

Mistake number 4: …and the center grows more than the sides!
Yep! I should have expected it…

Mistake number 5: Weight your ingredients before starting
Weighting things should not be done in a rush, as you want to be precise. Also it can take time. If I’d front measured all my ingredients all the brownies making process would have been smoother.


How they were supposed to look:

How they actually looked:

2013-06-15 10.42.38


Anyway we ate them in the end, and… surprise! They were actually quite good! Girlfriend and flatmates were all pleased by the result. The only explanation I can give myself about the outcome is that I followed a tip of a cake lover friend of mine: “Don’t be afraid to use butter. Butter makes everything better”

Now that I set the bar the only thing I can do is keep experimenting to push it higher. Stay tuned!