Radio is dead

JULY 25jDirect linkBTweet this

So last week there was a ton of Twitter hype surrounding the release of the Spotify service accross the USA. I had never heard of the service before and decided to take a look. My first thought? Cool, a better Grooveshark that isn’t under legal tension and isn’t bound by my browser. After looking around, it became clear that not only was Spotify not available in Canada, the company had actually officially voiced that it had no immediate plans to expand here.

I was pretty disappointed that I wouldn’t get to give it a shot, but then I caught wind of a service that has been going strong for about 11 months now, Rdio. It took about 1 hour into my 7 day free trial to realize that I had finally found my excuse to ditch iTunes.

Embracing Native (Sorta)

After using grooveshark for awhile a few months back and ditching it, I didn’t really expect a similar service to go far beyond the browser window to bring their service to me. I was wrong.

The Rdio Mac app is a native\AIR hybrid app that works surprisingly well. The “player” portion of the app is completely native and feels like it should. It responds to the media keys on your keyboard as iTunes does and even posts Growl notifications on track changes. The AIR half of the app is the music library\browser, which in essence replicates their web UI. I usually really hate anything flash, but I was quite satisfied by this as it felt like a pretty reasonable compromise between native and web. Honestly, next to the iTunes music store, I’m not really inclined to complain about it much anyway.

Where the service really shines is its iOS app. Instantly access and stream your entire music collection from your phone. Going away for a couple of weeks? Dropping into a subway for 20 minutes? Don’t worry, the service allows you to “mobile sync” selected tracks, albums or playlists for offline play. The only “caveat” (because this is ridiculously generous)? You have to touch base with their servers every 30 days. You’ll feel right at home when browsing your library on this app as it takes a lot from the iPod/Music app and makes use of all the same playback features and lockscreen shortcuts you’re used to.

And here is where it gets really cool: Pause the current song on your phone in your car when you get home and when you sit down at your desk you can resume playback from the exact same spot on your Mac. Yeah. That just happened.

Social Done Pretty Right

You can easily browse your Twitter, Facebook, Google, friends and see who shares the same music taste as you. Follow them, follow their playlists, or just flat out follow some random guy with good taste. It’s all possible and easy. I spent 2 hours the first night just going through peoples libraries discovering new music.

You can create collaborative playlists between friends, people can follow them, and then play them anywhere as they are updated. It’s literally your own personal radio rdio station. I was at a BBQ this weekend and nobody had any good music. I just popped on the iTunes top 200 playlist. Awesome.

Nice Developer Resources

Rdio also boasts some pretty nice APIs for developers. Ironically, I wasn’t able to get things running on my site because php sucks. Either way, they have an iOS framework that works great, a ruby gem (which I plan on using once I get around to conveting my site) a web streaming API, and more. I’m feeling like leveraging some of these APIs might be my excuse to jump into Mac development sometime soon.

The Good

  • Great iOS and Mac apps.
  • Over 10 million tracks.
  • Mobile sync for offline playback.
  • Easily leverage your existing social networks.
  • Pause and resume wherever you go.
  • APIs!

The Ugly

  • The shuffle really, really sucks.
  • Adobe AIR.
  • Cost of 10$\month.
  • It rapes your battery over 3G.

Final Thoughts

It’s not perfect, but I’ve definitely found the new way I’ll be enjoying my music. I know not everyone is ready to fork out 10$ a month for a service like this, but you should really give the 7 day trial a try before you make up your mind. I’m sold.

Check out my Rdio station


Working with Rakefiles and dynamic namespaces

JUNE 3jDirect linkBTweet this

While working on the numerous parsers required for populating the Transit databases for each service provider (STM, STL, RTL, AMT, etc) we handle, I was faced with a little problem organizing and naming all my different tasks. After doing a little bit of research, it became clear that rakes are intended to work in a similar fashion to controllers, where the heavy lifting is done in a separate class\model.

Since each provider required their own version of a same task (parsing stops, parsing schedules, etc) I obviously opted for an approach that leveraged namespaces. After some tinkering, I came up with a pretty interesting solution to my problem that I thought was worth sharing.

parser.rake

require 'app/models/provider'
require 'config/environment.rb'
Provider.all.each do |provider|  
    require "lib/tasks/#{provider.name}.rb"
    Kernel.const_get(provider.name).provider = provider  
    namespace provider.name do
	task :get_stops do
	    Kernel.const_get(provider.name).get_stops()
	end
    end
end

Instead of having a giant /lib/tasks folder filled with all the different tasks required by each provider, I reduced it down to a class per provider. Since classes are considered constants in Ruby, you can access them dynamically with Kernel.const_get(). My parsing classes look something like this.

STM.rb

class STM
    cattr_accessor :provider
    def self.get_stops()
	#parse and update environment
    end
end

Now you can very easily invoke rake STM:get_stops!

Technically, with this approach you could totally bypass rakes alltogether and directly invoke STM.get_stops() in the rails console, but rakes have the advantage of being able to be run in a production environment (namely Heroku) without timing out. Plus, I just like how it feels! It might be bad practice, I’m not really sure. If you think it is, I’d love to hear your toughts as to why. I did quite a bit of research and couldn’t find much.

It’s a pretty cool technique that so far has worked perfectly for me. My /lib/tasks folder has never looked so organized!


The Cereal Thief

MAY 19jDirect linkBTweet this


Transit for iPhone

APRIL 22jDirect linkBTweet this

Earlier today my buddy Sam and I released a little teaser site for the project we’ve been working on for the past few months.

I don’t want to divulge too much information just yet, but Transit is going to change how a lot of people use public transportation systems in major cities. We’re starting locally, in Montreal, to make sure we get things right, but we hope to add a few other cities by the time WWDC hits.

And then slowly take over the world…


Git Love

APRIL 22jDirect linkBTweet this

Over the past year or so I have made a bunch of should be drop-in classes for various projects. Unfortunately, in the heat of getting a things done, I rarely polish off and document a class like I should.

So I have a bunch of versions of a bunch of classes all over the place and I want a little incentive to clean things up a bit. Take a look at my new Github public repository section. (and yeah I only have 1 repo at the moment)


I just might be working on something pretty awesome...

APRIL 10jDirect linkBTweet this


...or not. Quit looking at me.


MAConfirmButton

APRIL 6jDirect linkBTweet this

I looked around for awhile and couldn’t find a good replica of the AppStore buy button element. Here is mine. This is my first GitHub release and first project directly playing around with CALayers. Any feedback is good feedback!


Operation: Clarification after inactivity

MARCH 30jDirect linkBTweet this

I’m an iOS dev not a NASA scientist. /cc @samvermette . It’s been a busy few months, gimme a break!


NASA Redefines Life

DECEMBER 2jDirect linkBTweet this

NASA has just announced something that is set to change the course of history with regards to understanding and finding new life forms – on earth and beyond. The elements necessary to the existence of life were carbon, hydrogen, nitrogen, oxygen, phosphorous and sulfur. The 6 basic building blocks to literally every single life form on Earth. Until now.

That’s GFAJ-1. A new form of bacteria that can actually build parts of itself out of arsenic. You know, that extremely toxic stuff that kills pretty much anything? Yeah, it can literally eat it. Grown on arsenic, the life form is capable of using the element throughout its biochemistry, such as in DNA, proteins and even cell membranes.

“The idea of alternative biochemistries for life is common in science fiction,” said Carl Pilcher, director of the NASA Astrobiology Institute at the agency’s Ames Research Center in Moffett Field, Calif. “Until now a life form using arsenic as a building block was only theoretical, but now we know such life exists in Mono Lake.”

The discovery was made at the Mono Lake Reasearch Area in California. The lake is isolated and is known for it’s particularly high salinity and arsenic concentrations. It almost looks alien, doesn’t it?

I forget where I read this, but it’s quite literally life as we do not know it. If life can be so incredibly different on Earth, imagine what else could be out there. NASA has confirmed that this new information is vital, and game-changing, in the search for extra-terrestrial life. Awesome.

Read the full press release


The Holy Grail of Retina icon templates?

NOVEMBER 20jDirect linkBTweet this

I just came across the awesome blog of Michael Flarup – a very talented designer and self proclaimed “iconist”. He has made what I believe to be the Holy Grail of app icon templates.

Simply Edit Contents of the specifically labeled smart object contained in the 512×512 group and it automatically generates all the other sizes for you. They obviously need some tweaking to be pixel perfect, but what a great way to test icon ideas and quickly see how they look at different resolutions!

The template also comes with an action macro that slices the file up and names all the pieces per Apple’s naming scheme. Sweet.


Windows Phone 7

NOVEMBER 17jDirect linkBTweet this

I’m usually the self admitted Apple™ 4EVER guy, but today I came across something that surprised me. For months, I’ve been ignoring all the hype surrounding Windows Phone 7. I chalked it up to another Microsoft Kin style venture and paid no attention to it. Obviously they were destined to bite off more than they can chew once again.

Well last night I finally took a look at it. I have to admit. I was impressed.

What really caught my eye was the UI. For 1.0 software, this looks surprisingly well polished. Much more so than Android went it first hit the scene. At first, I rolled my eyes at the tiles concept. Ok, so they’re going out of their way to not copy Apple directly. After taking a second look though, I think its actually a great concept. I really like the idea of the tiles being able to present summary data from the app as part of the interface. The typography is well chosen. The menus are coherent. It just looks good.

Animations are, for the most part, smooth as butter. The touch event handling looks almost as good as iOS, which is surprising seeing as how terrible it is for Blackberry and Android. Seems like the hardware is on par this time around.

This isn’t a review or anything, my exposure is limited to a few articles and videos. But it’s a pretty rare occurence for me to praise anything Microsoft. (I think the last time I did was the X-Box 360 launch) So this was worth mentioning.

Not sure I see myself developing for the platform (.net :S), but I’m definitely curious to see how the OS evolves over the next year or two.


Guy builds a 16-bit ALU in Minecraft

NOVEMBER 13jDirect linkBTweet this

I’ve never played Minecraft, so I don’t get all the hype that surrounds it. Either way, this guy designed and built an ALU unit IN GAME. It actually works. He plans to build an entire computer, that could potentially run at a whopping clock speed of 16 Hz and actually compile code.

Turns out this little project of his might have landed him a job when a potential employer caught a glimpse of his work on Reddit. He documents his progress on his YouTube channel. Take a look, it’s pretty damn impressive.


Core Data in 3 Simple Steps

NOVEMBER 12jDirect linkBTweet this

There are no simple and example driven introductions to Core Data for iOS anywhere. I’ve looked. This should get you started in less than an hour. Basic objective-c skills are a must.

For simplicity sake, we will implement the Core Data stack in the AppDelegate of our new app. In practice, you will probably want to write a helper class that you can use throughout your app.

1. SETTING UP THE STACK

First things first, add the Core Data framework to your project. Now, add this to your AppDelegate header file:

#import <CoreData/CoreData.h>
@interface YourAppDelegate : NSObject <UIApplicationDelegate> {
@private
    NSManagedObjectContext *managedObjectContext_;
    NSManagedObjectModel *managedObjectModel_;
    NSPersistentStoreCoordinator *persistentStoreCoordinator_;
}
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@end

Next up, the method implementations:

- (NSManagedObjectContext *)managedObjectContext {    
    if (managedObjectContext_ != nil) {
        return managedObjectContext_;
    }    
    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil) {
        managedObjectContext_ = [[NSManagedObjectContext alloc] init];
        [managedObjectContext_ setPersistentStoreCoordinator:coordinator];
    }
    return managedObjectContext_;
}
- (NSManagedObjectModel *)managedObjectModel {    
    if (managedObjectModel_ != nil) {
        return managedObjectModel_;
    }
    NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"YourAppName" ofType:@"momd"];
    NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
    managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
    return managedObjectModel_;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {    
    if (persistentStoreCoordinator_ != nil) {
        return persistentStoreCoordinator_;
    }
    NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"YourAppName.sqlite"]];
    NSError *error = nil;
    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
        abort();
    }    
    return persistentStoreCoordinator_;
}

2. CREATING THE DATA MODEL

The next step is to create our Data Model. Add a Data Model file by going: File > New File > Resource > Data Model. Name it YourAppName.xcdatamodel.

Select your Data Model file in the file browser to bring up the modeling interface. (reminders of MS Access anyone?) So let’s start by creating a couple of entities. How about the ol’ Country and City example? So start by making a Country and a City entity. Add 1-2 attribute properties to each entity, like Name, Country Code, etc. It should look something like this:

Make sure the Name and Class of your entities match. Now, add a City to-many relationship property to the Country entity:

Now add a Country relationship property to the City entity. Each City can only be in one Country, so no to-many here. Now, if you did everything correctly, you should be able to set the inverse relationship for both entities. You end up with something that looks like this:

We’re all set, we just need clases for these entities so we can use them in our code. Select all the entities and go to File > New File > Cocoa Touch Class > Managed Object Class. Select your app target press next, and then finish. Voila the classes have been generated for you (Country.h, Country.m, City.h, City.m).

3. USING CORE DATA

Now you’re ready to start Core Data’ing! Don’t forget to include your entity header files. Here are a few quick examples of how to use what we’ve just setup.

Adding a new Country:

//Don't forget to pass the managedObjectContext to your viewController from the AppDelegate!
Country *currentCountry = (Country *)[NSEntityDescription insertNewObjectForEntityForName:@"Country" inManagedObjectContext:managedObjectContext];
[currentCountry setName:@"Canada"];
[currentCountry setCountryCode:[NSNumber numberForInt:011]];

Adding a City to the new Country:

City *currentCity = (City *)[NSEntityDescription insertNewObjectForEntityForName:@"City" inManagedObjectContext:managedObjectContext];
[currentCity setName:@"Montreal"];
[currentCountry addCityObject:currentCity];

Saving the managedObjectContext:

NSError *error;
if (![[self managedObjectContext] save:&error]) {
    //Make sure you handle this!
    NSLog(@"Can't save object context");
}

Searching for all the cities in the currentCountry object:

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"City" inManagedObjectContext:managedObjectContext];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Country == %@", currentCountry];
[request setEntity:entity];
[request setPredicate:predicate];
//Take a look into NSFetchedResultsController for more advanced functionality with your fetch requests.
NSMutableDictionary *results = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];

And with that you now know how to setup and utilize a basic Core Data stack in your iOS application. Take time to familiarize yourself with NSPredicate and the different format strings available. Take a look at NSSortDescriptor for ordering your data because Core Data fetch requests come back unordered. Also, read up about NSFetchedResultsController and NSManagedObject and know what you’re playing around with.

Did this article help you? Did I forget something? Let me know!


Confessions from phase 3 and 4

NOVEMBER 10jDirect linkBTweet this

I guess I should halt development on that nifty Hammer App I was working on. Clever bastards beat me to the punch!


Keeping tabs on your NetworkActivityIndicator calls

OCTOBER 10jDirect linkBTweet this

Just pop this little snippet in your AppDelegate! Works like a charm.

- (void)setNetworkActivityIndicatorVisible:(BOOL)setVisible {
    static NSInteger calls = 0;
    if(setVisible)
        calls++;
    else
        calls--;
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:(calls > 0)];
}

Custom UISplitViewController behavior

SEPTEMBER 8jDirect linkBTweet this

Ever tried to resize the first viewController of a UISplitViewController? Not exactly the easiest thing in the world considering that _masterColumnWidth is private and set at a static 320.0f.

Swap out Apple’s crappy UISplitViewController for MGSplitViewController by Matt Gemmel. Implementation is hypothetically a snap; it uses all the same init methods, setters and getters that a regular UISplitViewController uses, plus a few little goodies. Awesome work Matt, thanks a lot!


My name is Mike

AND I LOVE REDDIT

I'm a 24 year old law student slash iOS developer based in Montreal, Canada. A Jekyll and Hyde of sorts. Not really sure which side is the evil one!