Introducing RestFB, a Java Facebook REST API Client

Just wanted to mention that I’ve written a Facebook REST API client called RestFB, which is available under the terms of the MIT license.

If you need to do a Facebook Connect implementation in Java, please give it a try and let me know what you think!

Posted in Java | Leave a comment

When Callable<V> is not enough

At work today I ended up having to write this because Callable<V> wasn’t flexible enough for what I needed:

public interface Operation<V, E extends Throwable> {
  V execute() throws E;
}

…would love to see this (as well as a Pair<A,B> class) in a future cut of Java.

Posted in Java | 1 Comment

CNN Sob Stories

I liked this morning’s front-page CNN story:
picture-1
If you bought a house you can’t afford and are unable to keep paying the mortgage, maybe you shouldn’t have a $90/month (minimum) iPhone…just sayin’.

Posted in Humor | 4 Comments

Three20 JSON Example Project

I’ve uploaded an example Three20 project that demonstrates a very simple JSON datasource. You can grab the code here. It’s assumed that Three20 lives at ../three20 relative to the project root and that you’ve got Stig Brautaset’s JSON framework installed in your ~/Library directory as explained on the Google Code wiki.

There isn’t much to the example – just a single controller and datasource. It’s pretty straightforward to bolt on additional functionality like a “load more” button (just read the TTCatalog and Three20 source) and hook into the other nice table features Three20 offers out of the box. Until better docs are available, hopefully this example can serve as a starting point for your own experimentation. Feedback is welcome!

Some screenshots so you know what you’re getting…first, the controller (registered as a datasource delegate) gets a notification that the datasource is in a loading state – this view is then automatically shown by the framework:
loading
Second, the data has been loaded and the datasource has notified the controller that it’s ready. The controller then retrieves data from the datasource and displays it:
json-images
(I’m using a feed provided by the Yahoo Image Search Service API: here’s the raw JSON.)

Update, October 3 9:30 AM EDT
It’s come to my attention that some people are still using this code – please don’t! It was based on three20 as it existed back in March/April 2009 and is now very much out-of-date. If you’re looking for current and correct three20 sample code, Keith Lazuka’s github has what you need. Thanks!

Posted in iPhone | 21 Comments

Three20 JSON datasource implementation

Three20 is a nice iPhone library, but the documentation is pretty much limited to the TTCatalog example app code…one thing that’s left as an exercise for the reader is the implementation of a datasource that fetches its data over the network and how it interacts with its associated TTTableViewController.

One approach to this problem is to subclass a canned datasource, which gets us a bunch of stuff for free right off the bat:

@interface MyDataSource : TTListDataSource<TTURLRequestDelegate> {
 @private
  BOOL _loading;
  BOOL _loaded;
}

You’ll want to provide meaningful implementations of accessors like loadedTime:, isLoading:, isLoadingMore:, isLoaded:, etc. Your controller will query the datasource using those selectors to know what state to show (e.g. loading, error, data, no data).

Write a load:nextPage: implementation that hits the network:

- (void)load:(TTURLRequestCachePolicy)cachePolicy nextPage:(BOOL)nextPage {
  TTURLRequest *request =
   [TTURLRequest requestWithURL:@"http://test.com/test.json" delegate:self];

  request.cachePolicy = cachePolicy;
  request.response = [[[TTURLDataResponse alloc] init] autorelease];
  request.httpMethod = @"GET";
  [request send];
}

Write a requestDidFinishLoad: implementation that pulls JSON out of the response (maybe using Stig Brautaset’s very nice JSON framework) and let your controller know that data’s available via dataSourceDidFinishLoad:.

- (void)requestDidFinishLoad:(TTURLRequest*)request {
  TTURLDataResponse *response = request.response;
  NSString *json = [[NSString alloc] initWithData:response.data encoding:NSUTF8StringEncoding];

  // Load up self.items with json data however you'd like

  [json release];

  _loading = NO;
  _loaded = YES;  

  [self dataSourceDidFinishLoad];
}

Don’t forget to implement requestDidStartLoad:, request:didFailLoadWithError:, and requestDidCancelLoad: and have them notify any interested delegates of the request’s status. Here’s an example:

- (void)request:(TTURLRequest*)request didFailLoadWithError:(NSError*)error {
  _loading = NO;
  _loaded = YES;
  [self dataSourceDidFailLoadWithError:error];
}

In your controller, createDataSource: might look like this:

- (id<TTTableViewDataSource>)createDataSource {
  MyDataSource *dataSource = [[[MyDataSource alloc] init] autorelease];
  [dataSource.delegates addObject:self];
  [dataSource load:TTURLRequestCachePolicyDefault nextPage:NO];
  return dataSource;
}

Have fun out there.

Update, April 11 10:30 AM EDT
I’ve added a new post with a downloadable example project and (finally) cleaned up the above code. I apologize for previous typos; I really should make sure the code I post actually compiles instead of writing/tweaking it in a wordpress edit window.

Update, October 3 9:30 AM EDT
It’s come to my attention that some people are still using this code – please don’t! It was based on three20 as it existed back in March/April 2009 and is now very much out-of-date. If you’re looking for current and correct three20 sample code, Keith Lazuka’s github has what you need. Thanks!

Posted in iPhone | 8 Comments

Fedex Webdevs Have Small Monitors

Fedex CSS fail

Needs more background-repeat: no-repeat;

Posted in Humor | Leave a comment

UnknownHostException: Java & IPV6 on Linux

In case this helps someone else, I spent a few hours trying to pin down why my GWT app was seeing UnknownHostExceptions for things like google.com when using HttpClient in hosted mode.

Luckily, I found this guy (girl?) in the same boat, who figured out that you just need to flip a system property to get correct behavior – in my case, passing in the VM argument -Djava.net.preferIPv4Stack=true on Tomcat startup.

Posted in Uncategorized | Leave a comment

Lots of Data

At xmog we’re working on a project for Advanta that requires fast searching over millions of records. Luckily for us, Lucene is disgustingly good and makes the whole process relatively simple.

The reason I mention this is because Amazon’s Elastic Block Storage was released today – finally, persistent non-S3 storage inside the compute cloud. We could slap Hadoop and a database and webserver on that bitch and be ready to roll. Great stuff, really excited to see old-fashioned webhosting die.

Posted in Uncategorized | Leave a comment

Billing Manager on the iPhone

I was pleasantly surprised to see Billing Manager land at the top of the heap of Apple’s list of iPhone Productivity Apps (and we’re 7th most popular across _all_ apps) only a few days after we added support for Mobile Safari. We’re also a “Staff Pick”. Good stuff!

Posted in Uncategorized | Leave a comment

POOL ON THE ROOF MUST HAVE A LEAK

Don’t remember where this was originally from (found it years ago). You have to admit it’s awesome.

Posted in Uncategorized | 1 Comment