Xcode GCD Snippets

This is going to be short and sweet. For all those Mac/iOS developers that use Grand Central Dispatch, you’re probably tired of Xcode attempting to code complete dispatch_after once you’ve hit the dispatch_a while typing. 99.999999% of the time I’m after dispatch_async. It drives me crazy.

Interestingly enough Apple provided a dispatch_after code snippet, but not one for dispatch_async. A side effect of this oversight is that the code completion appears to show snippets first. So I’ve created two additional snippets that reflect the most common use cases that I encounter – dispatch_async with a global or main queue.

Download my Xcode GCD Snippets and install into ~/Library/Developer/Xcode/UserData/CodeSnippets and restart xcode.

Enjoy and never again see dispatch_after!

18. January 2013 by Jason
Categories: Objective-c | Tags: | Leave a comment

Getting server bit rate in AVFoundation

I was recently asked if it would be possible to provide the bit rate of the stream that is currently being viewed. Figuring that it would be possible as it has to be something that’s known to the AVPlayer, I agreed. Fortunately, I was correct. Unfortunately, it wasn’t as quick of an answer as I originally believed. Here’s how I solved it.

Continue Reading →

26. October 2012 by Jason
Categories: iOS, Objective-c | Tags: | Leave a comment

Provide a library that works with an iOS device and the simulator.

To create a combined library:

1.) Compile library for each SDK as usual.
2.) lipo -create libdevice.a libsimulator.a -output libcombined.a

That’s it.

25. August 2012 by Jason
Categories: Objective-c | Tags: | Leave a comment

Hide unwanted external drives on the Mac OSX desktop

I have a number of external hard drives attached to my Mac. Some for Time Machine, others for iTunes media, but they’re all external drives. In the MacOS finder preferences you have the ability to hide items from the desktop, and one of those is aptly labeled, “External disks.”

I like the desktop clutter free, and mounted volumes that I’ll never directly need access to (away from the command line), I don’t want to see on the desktop. However, I do want to see items like USB flash drives mounted on the desktop. Unfortunately these items are all considered “External disks.” However there is a solution.

And it’s a very simple solution. First, make sure that Finder is configured to display external disks on the desktop. The real answer lies in using the built in file flags that are part of Mac OSX. Simply issue a chflags hidden [file] and you’re already the majority of the way there.

Example:

$ chflags hidden /Volumes/Time\ Machine/
$ chflags hidden /Volumes/Media/

You can verify that the flags were set by using:

$ ls -ldO /Volumes/Media
drwxrwxr-x@ 11 jhowk  staff  hidden 442 Jul 29 18:29 /Volumes/Media

The last item that needs to be done is to restart the Finder. The chflags changes will not be reflected until the Finder has been restarted.

31. July 2012 by Jason
Categories: Mac | Tags: | 2 comments

Subversion recommits

A colleague at work was facing a dilemma and asked for help and I figured that the solution might be usable for others. Here’s the setup. Our SVN trunk typically matches production. Don’t ask why, it just does. Once a release is pushed into production the contents of whatever was deployed is merged into trunk. More like it obliterates what was in trunk.

In this particular case a commit was made after deployment but before the merge, effectively wiping out the changes to trunk. However we still needed to have the commits re-applied. We could have attempted some SVN slight-of-hand, but as it usually works out, the simplest solution is usually the best.

The easiest, and most scriptable solution was to use the way back machine and apply somediff and patch magic. Here’s what we did (make sure your completely up to date when you do).

  1. Get the files that were changed in the previous revision with
    svn log -v -r [REV] |grep "^ M " |awk '{print $2}' |cut -c2-
  2. Go old school and diff and patch
    svn diff -r [REV] [FILE] | patch -R [FILE]
  3. Commit away!

Assuming the changes you want applied are in version 2, and HEAD is at version 3, here’s how it might look

for f in `svn log -v -r 3 |grep "^   M " |awk '{print $2}'|cut -c2-`; 
do 
svn diff -r HEAD $f | patch -R $f; 
done

Lastly, issue the commit and your back to where you should be…

27. April 2012 by Jason
Categories: Development, UNIX | Tags: | Leave a comment

Get a quick fingerprint from public key

Due to the GitHub “SSH Key Vulnerability”, all of my keys were deactivated and I needed to reactivate them. Without going into details about the issue, GitHub provides you a list of your key fingerprints that you need to validate and reactivate. If you don’t know the fingerprints of your keys, you might think your stuck. Not necessarily.

If you have the public key handy, you can do this:

ssh-keygen -l -f [public key file]

And you get exactly what you need; a fingerprint of your public key.

13. March 2012 by Jason
Categories: Development, UNIX | Tags: , | Leave a comment

Xcode 4.3 quirks

With the Xcode 4.3 update, Xcode has become a full-fledged application in the App Store. There are a few implications to this seemingly innocuous change, but they can (and have) cause a few hiccups that I’m going to point out below. The obvious change is that Xcode is no longer installed via an installer. Should help out tremendously for updates so developers are no longer forced to re-download a gigabyte plus of data for the small fraction that was actually updated.

More importantly though, is that Xcode was just one application in a suite of tools that was installed in /Developer. In order for Xcode to become an “application” in the App Store vis-a-vis an installer, a number of changes were made that will affect Xcode users prior to 4.3.
Continue Reading →

26. February 2012 by Jason
Categories: Development, Mac, Objective-c | Tags: | Leave a comment

Getting a background texture behind a UITableView

In many apps when you viewing the top of a UITableView and you pull down you get one of three things: a plain white background (i.e. YouTube), a pull to refresh (i.e. twitter), or a textured or differently colored background (i.e. contacts). By default when you have a UITableView, you will get the first option, a plain white background.

If however you would like to do something like contacts where the perceived “background” of the table view is something other than default. If that’s the case, it’s relatively easy to do. Here’s how.

In your UITableViewController (usually viewDidLoad:)

// This sets the lighter linen looking background.  see UIColor for more "System Colors"
[[[self navigationController] view] setBackgroundColor:[UIColor underPageBackgroundColor]];
// Make the background of the table view transparent.
[[self tableView] setBackgroundColor:[UIColor clearColor]];

Then implement this method in your UITableViewController:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor whiteColor]];
}

After playing around and failing in different ways, this seems to be the simplest solution by far. Simple, easy and does what it should.

05. December 2011 by Jason
Categories: Development, Mac, Objective-c | Leave a comment

Mac OS X Lion Clean Install Quirks

I decided to do a clean install on my development laptop with Lion to clean out the cruft. Not that it really needed to be done, but I was curious to see if there were any discernible differences between the Snow Leopard (SL) upgrade and a clean install.

For those who are wondering, you can find a plethora of resources on how to do it if you so choose, but I did want to point out a few quirks that I ran into after the install. I’m not sure if these are environmental differences that I had adjusted a some point in the past, but when I re-installed a clean version of Lion a few things changed.

  1. Mission Control – By default, there’s really only one space. If you upgraded an existing SL installation and used spaces, it created them by default in MC. Furthermore, Control-UP activates MC. Control-Down does the old Exposé routine.
  2. Tap to Drag – I don’t remember the actual starting state of this but I checked on another laptop and my desktop with the Magic Trackpad and they were configured the same so I’m working under the assumption that this may affect a few people like myself. If you were used to the whole tap to drag routine, it’s not there — well technical it’s there but not active. Once you activate the tap to click, tap to drag doesn’t. And it’s not in the Trackpad preference pane either. Strangely enough, it’s tucked away under Universal Access/ Mouse & Trackpad/ Trackpad Options…Universal Access Preference Pane

As I find more quirks I’ll update this post.

Enjoy.

29. July 2011 by Jason
Categories: Mac | Tags: , | Leave a comment

Selective Site Mirroring with wget

Since Cloudera doesn’t seem to support an rsync server for us to mirror against, I had to resort to using wget to mirror their CDH distribution. To save some time for those who are attempting to do something similar, here’s a wget one-liner to grab only the RPM’s (while maintaining the directory structure):


wget -N -r -nH -np --cut-dirs=3 -A rpm,xml http://archive.cloudera.com/redhat/cdh/3/

11. May 2011 by Jason
Categories: UNIX | Tags: | 2 comments

← Older posts