Good morning movie liners. I don’t expect many answers today, but here we go!
WE ARE GOING TO STEAL… pause for effect… THE MOOOOOONNNN!
Ok, quick, what movie! Send your guesses here.
Good morning movie liners. I don’t expect many answers today, but here we go!
Ok, quick, what movie! Send your guesses here.
Readability Blog: “One of the more useful tools in the Readability toolbox has been our link shortener, rdd.me. The interesting bit about rdd.me is simple: When an article is linked to through rdd.me, it offers up the availability to view the content in a clean, readable view.”
Get to building! If you need some Objective-C to talk to rdd.me, you’re in the right place.
Take a look at RFRddMe.
When I created the project for RFRddMe I added Unit Tests. Every developer should do this today. They’re easy to create and Xcode does a great job getting you started. Everything is setup, you just need to write and run the tests. Really great stuff!
The only challenge for me was how to test asynchronous code? As far as I know it’s up to the developer to figure that out. That’s fine, I have a solution, but I thought I’d share it and see if anyone has an opinion about how I did it.
If you haven’t used the Unit Test Framework included with Xcode, you should. It’s a cut of SenTestingKit, and it does the trick.
It provides a couple of methods that allow you to setup and tear down a unit of tests and all you need to do is write test methods. Here’s an example test method, that does nothing.
- (void)test;
{
STAssertTrue(true, @"test");
}
So, how in the world do you test asynchronous code? The way you write any other asynchronous code. You need a way to block until the code you’ve executed is finished.
The RFRddMe projects makes use of ASIHttpRequest, which runs in a thread. This project requires the implementation of an protocol, RFRddMeProtocol, which provides a mechanism for your application to receive results. This is all really cool because your application’s UI will remain responsive while you wait for results, but I digress.
The bottom line is we have to block while we wait on our results to return. So, here’s what I did to make this work. I created a method, I dubbed hackyRunLoopWait, that makes use of the default NSRunLoop to wait for completion of our asynchronous methods to complete. Here’s what it looks like.
// Introduced methods.
- (BOOL)hackyRunLoopWait;
{
// Reset our _done flag.
_done = NO;
// Reset the _succeeded flag to NO.
_succeeded = NO;
// Get the current run loop.
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
// Spin until the _done is YES or we've waited for 90 seconds.
// Yep, it's a complete hack, just to get this working.
while ((NO == _done) && [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:90]]);
// Need to deal with exiting the loop above because we timed out.
return _succeeded;
}
Here’s how I used it to test methods on RFRddMe.
- (void)testShorten;
{
RFRddMe* p = [[RFRddMe alloc] initWithDelegate:self];
[p shortenUrl:@"http://iam.fahrni.me/2011/11/15/for-posterity/"];
STAssertTrue([self hackyRunLoopWait], @"testShorten");
[p release];
}
Notice the STAssertTrue() statement, it contains [self hackyRunLoopWait], which blocks and waits on our shortenUrl method to complete.
Another thing to make note of is RFRddMeProtocol is implemented by the test class, see the [[RFRddMe alloc] initWithDeelgate:self]. When the request completes it will notify the shortenSucceeded method, which sets the values monitored in hackyRunLoopWait, which allows that method to return.
// RFRddMeProtocol Implementation
- (void)shortenSucceeded:(RFRddMeShortUrl*)shortUrl;
{
_succeeded = YES;
_done = YES;
}
Is this the best way? I don’t know, but it does what I need it to do, and it works as expected. If someone has a better idea I’d love to hear from you. Please, leave a comment, or send an email; rob.fahrni@gmail.com.
The handling of the Occupy Movement by local authorities has gotten out of hand. Police, not the protesters, are getting violent. There’s no excuse for that type of behavior. Do you want to see it turn violent? Is that the idea? It’s ridiculous, step up and address this problem, you did it for the people of Egypt.
THE PRESIDENT: Good evening, everybody. My administration has been closely monitoring the situation in Egypt, and I know that we will be learning more tomorrow when day breaks. As the situation continues to unfold, our first concern is preventing injury or loss of life. So I want to be very clear in calling upon the Egyptian authorities to refrain from any violence against peaceful protestors.
The people of Egypt have rights that are universal. That includes the right to peaceful assembly and association, the right to free speech, and the ability to determine their own destiny. These are human rights. And the United States will stand up for them everywhere.
Maybe you could do the same for America?
Earlier this week Dave Winer pointed out some neat stuff Readability was up to. Part of the piece pointed out a new URL shortener. I marked it and came back to it today. Since I love writing code to talk to RESTful web services, why not write another one?
This afternoon I started on RFRddMe, an Objective-C library for the Readability Shortener Service. Late this afternoon I completed the library, and I checked it into my GitHub Repository tonight. Figuring out git submodules took a bit of time, but it works as advertised.
If you just happen to be looking for Objective-C code to shorten a URL, and add an article to Readability, look no further.
Get the code for RFRddMe on GitHub.
Please, drop me a line, rob.fahrni@gmail.com, if you use the code.
Enjoy.
Good morning! Not many takers for this line, we had one, just one. Oh, but that one was dead on!
Congratulations to Mr. Tommy Williams who correctly guessed…
Luma Labs: “Therefore, we’re acting unilaterally and conceding the market by immediately discontinuing the Loop and LoopIt. Full stop. We apologize for the sudden nature of this decision and our implementation of it, but we feel like our options on this matter are limited.”
I don’t have much to say about this. The little guy just doesn’t stand a chance anymore.
Horrible. What a loss.
Good afternoon! My brain is so mushy today I almost forgot to post our movie line, DOH!
Here it is, good luck.
Ok, quick, what movie! Send your guesses here.
Good morning! We have a winner!
Congratulations to Mr. Steven Vore, who correctly guessed…
This is another Thanksgiving time must see for me.