GIT Modules

Equivalent to SVN Externals, GIT offers a nice feature called “Modules”. Long short story, you get to link an external project, inside your own project.
What do you make out of this?. Well, suppose you’re using a 3rd party library. You can update everything with just a command line pull. No need to download and merge, by hand.

Sounds nice, right?. It’s done this way:

[cc]
cd MyApp
git submodule add git://github.com/some-framework/some-framework.git Frameworks/SomeFramework
[/cc]

Afterwards, we need to recursively update the submodules. Which will, in turn, clone the ‘some-framework’ repository:

[cc]
git submodule update –init –recursive
[/cc]

Removing “@2x” substring from files

If you’re reading this, probably… it’s because the Art Designers of your team just sent you a bunch of SD assets, with the @2x substring… and you don’t wanna spend the next 30 minutes cleaning that up… right?

If that’s the case, you’ve come to the right place. Fire Terminal, open the containing folder, and type the following:

[cc]
find . -type f -name “*@2x*” -exec sh -c ‘echo mv “$0” “${0/@2x/}”‘ ‘{}’ \;
[/cc]


Note:
you might have just noticed that this will actually echo the replacement. That’s for safety. Validate the output, and proceed removing the ‘echo’ command call.

Waiting until two async blocks are executed (Version #2)

This is a nice variant to this other post. It gives you… way too much flexibility!

[cc lang=”objc”]
dispatch_group_t group = dispatch_group_create();

dispatch_group_enter(group);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
NSLog(@”Block1″);
[NSThread sleepForTimeInterval:5.0];
dispatch_group_leave(group);
NSLog(@”Block1 End”);
});

dispatch_group_enter(group);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
NSLog(@”Block2″);
[NSThread sleepForTimeInterval:8.0];
dispatch_group_leave(group);
NSLog(@”Block2 End”);
});

dispatch_group_notify(group, dispatch_get_main_queue(), ^ {
NSLog(@”Group Notify Block3 :: %d”, [NSThread isMainThread]);
});
[/cc]

Fixing Codesign Issues with Helper Apps

I’ve been getting “Invalid binary” errors, while trying to upload a binary to the AppStore. The solution can be found in stackoverflow, i’m just pasting it here, for future reference…

1. Re-Codesign the Helper app from terminal:
[cc]codesign -f -s “3rd Party mac Developer Application:” -i “com.bundle.YOUR.HELPER” –entitlements path/to/helper/entitlements YOUR-HELPER.app[/cc]

2. 

Remove provisioning profile from Helper app, adding a “Run script” into the “Build Phases”:

[cc]rm “${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Contents/Library/LoginItems/YOUR-HELPER.app/Contents/embedded.provisionprofile”[/cc]

After this, i managed to upload the binary!

 

Route53 Failover Mechanism!

Situation: you run your own website on an Amazon EC2 instance. Something happens: maybe the box runs out of resources (ddos, high traffic, you pick one!).
All of the sudden, your website is offline. Downtime means that Google will push it down in the ranking. So what do we do?.

Well, AWS Route53 has a new, and super cool mechanism, that allows you to set Health Checks. If the website doesn’t pass it, the DNS record will switch to a failover entry.

How can we achieve this?. Amazon itself posted a detailed guide here. Just for the record, here you will find details about when a website is considered healthy.

A couple details:

  1. I’ve used SiteSucker, a free OSX tool, that allows you to create a simple HTML backup. Running a static S3 backup is way cheaper than running two instances!.
  2. If your apache logfile grows **a lot** due to the HealthCheck hits, you can disable the logs, if the user agent is “Route 53”. Simply put the following in your .htaccess:

    [cc]SetEnvIfNoCase User-Agent .*Route 53.* dontlog[/cc]

    Don’t forget about tweaking your website.com.conf apache file, to look like this:

    [cc]CustomLog logs/access_log common env=!dontlog[/cc]

This is just… sooooo cool!