Running EC2 + shh-ing + updating Ruby

Quick guide on how to get up and running with EC2 with latest version of Ruby.

  1. Set up your EC2 instance and download the .pem file
  2. Wait until it’s up and running
  3. Type ssh -i ScientiaKP.pem YOUR_USER_NAME@YOUR_PUBLIC_DNS in terminal. -i is to specify the identity/.pem file. HOST_NAME is ec2-user if you just signed up and haven’t changed anything. You can find YOUR_PUBLIC_DNS should be listed at the bottom when you click on your instance.
  4. Press enter and and you should be logged in.
  5. Type which ruby and it should output 1.8.7. We want to update to latest version.
  6. We will download the latest ruby source and compile it. For that, we need a compiler. Run sudo yum groupinstall “Development Tools” to install dev tools.
  7. Download latest ruby: wget
  8. Unzip tar xzvf ruby-1.9.3-p327.tar.gz. Leave v out if you don’t want to see files being unzipped.
  9. Run ./configure
  10. And finally make && make install

It’s actually still installing while I type this so I will update if I get any issues.

Posted in Uncategorized | Leave a comment


RubyMotion was released today. It’s let’s you write iOS apps in Ruby. It’s different though… It does’t use a VM but statically complies your code into machine code so all the performance issues we usually associate Ruby with are irrelevant.

I haven’t tried it out, but judging from code samples, it’s actually pretty awesome. Especially debugging is amazing, you can interact with UI elements in simulator during runtime. Deployment seems easy as well.

But the question remains: Is it a better alternative to Objective-C/Cocoa-Touch. I personally don’t have a problem with Objective-C and I actually love the Cocoa APIs. Now with ARC, it’s even better.

How I feel about MotionRuby? Quoting from hackernews:

Is what 95% of the code in your app is going to look like and I don’t really see what it’s buying you [Linking to a code sample]. You’re also throwing away all the type checking you’d get on essentially the same code in Obj-C.

I really like Ruby but I don’t intend to use it for iOS apps.

Don’t get me wrong, I think it’s a great alternative. I just don’t think it brings anything new to the table.  At the moment, I feel like it’s just a subset of Objective-C and Cocoa-Touch APIs. It was released today, I am pretty sure incompatibilities will pop up soon. So, here are some of the things going against MotionRuby:

  1. Costs $250 (as opposed to free Objective-C/Xcode).
  2. No static type checking.
  3. Can’t use awesome ruby gems.
  4. Have to know Cocoa Touch APIs to use (and I think 90% of learning Objective-C is learning the framework. Oh wait… that applies to any language).
  5. No way to mitigate retain cycles (at the moment at least).

Overall, I think it’s a solid alternative to Objective-C and I will watching this project closely.

Posted in Uncategorized | Leave a comment

mruby and iOS

So Matz, the designer of Ruby pre-released mruby (minimalistic ruby) a week ago. It’s targeted towards embedded systems. As the name suggests, it’s suppose to have a very small memory footprint and you can interpret it or compile and run it in VM. It’s still in it’s infancy though so there’s a ton of bugs,

It gained a lot of attention on HackerNews and everyone is talking about using to to write GUI on iOS. One project that’s trying to do this is MobiRuby. It’s a bridge between Objective-C and Ruby runtime. I have to say it’s disgusting.  Other than the fact that you are trying to mingle your way into a framework (it’s more of a hack than a real solution), take a look at the code:

class NSString < Mobi::Cocoa::Object

class UIAlertView < Mobi::Cocoa::Object

def _S(str)
 NSString._stringWithUTF8String str

alert = UIAlertView._alloc \
 ._initWithTitle _S("Hello"),
 :message, _S("I'm MobiRuby"),
 :delegate, nil,
 :cancelButtonTitle, _S("I know!"),
 :otherButtonTitles, nil

WTF is this? I don’t even…

Sure, you can write a wrapper around it but I already see a shit ton of problems. Not to mention, you need to be familiar with Cocoa in other to use this. Two completely different ideologies…

What would be cool instead is if someone writes OpenGL ES bindings for mruby, similar to Codea or Corona/Maoi SDKs. It would be great for prototyping and writing small/simple iOS applications. Not necessarily geared towards games (unlike the frameworks I mentioned above), but something that provides access to Cocoa-like UI elements.

Posted in Uncategorized | Leave a comment

Asynchronous [NS]URLConnection With Blocks!

UPDATE: NSURLConnection let’s you do this now on iOS 5+.

Recently I was working on a project and I needed to make a simple API call to a server and monitor the upload/download progress. Importing an entire networking framework like AFNetworking or ASIHTTPRequest seems like an overkill for such a simple task. Using NSURLConnection’s synchronous method (with GCD) won’t magically make it asynchronous, it will still block the entire thread. There’s an overhead because NSURLConnection is asynchronous in nature. Also, there’s no way to get the upload/download progress and you have to wrap it around ugly cryptic GCD methods.  The only option left remaining is implementing the NSURLConnectDelegate protocol but that just makes your class and code look ugly.

So, I wrote this simple class: URLConnection. It’s not just a wrapper around NSURLConnection’s synchronous method using GCD (I’ve seen a lot of people doing that). What you get:

  • Speed that you get out of pure asynchronous implementation of NSURLConnection.
  • Upload progress
  • Download progress
  • Blocks, making everything simple and look clean!
  • No need to import dozens of libraries and frameworks.

Something to keep in mind: The download progress depend on wether the server passes in “Content-Length” parameter in HTTP header field. If that’s not there, there’s no way to determine the progress. In that case, the download completion block will simply not be called.

Here’s a quick example showcasing URLConnection (getting top rated YouTube videos today):

NSURL *url = [NSURL URLWithString:@""];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

[URLConnection asyncConnectionWithRequest:request
 completionBlock:^(NSData *data, NSURLResponse *response) {
 [progress dismiss];
 } errorBlock:^(NSError *error) {
 [progress dismissWithError:@"Error!"];
 } uploadPorgressBlock:^(float progress) {
 //Upload progress (0..1)
 } downloadProgressBlock:^(float progress) {
 //Download progress (0.1)

Let me know if you find a bug or added something useful to this class and I will update it here.

Posted in Uncategorized | Tagged , , , , | 4 Comments

Hello world!

I am an iOS developer. I’ve been programming for about 2 years now. I plan on posting whatever I find interesting/challenging/worth sharing, mostly programming related.


Posted in Uncategorized | Leave a comment