Monkey-Patching iOS with Objective-C Categories Part I: Simple Extensions and Overrides

Have you ever wanted to introduce new functionality to base classes in the iOS SDK? Or just make them work a little bit differently? In order to do so, you must enter the wild and dangerous world of monkey-patching.

Monkey-patching is extending or modifying the behavior of code at runtime without changing its original source code. You can monkey-patch any code, it doesn’t matter whether it’s your own code or not. This is distinctly different than traditional sub-classing because you are not creating a new class, instead, you are reopening an existing class and changing its behavior.

Monkey-patching is possible in Objective-C by using categories. In fact, the definition of a category practically matches that of monkey-patching:

"A category allows you to add methods to an existing class—even to one for which you do not have the source."

In this series of posts, we’ll use categories to add and change methods, to add new instance variables and properties, and introduce swizzling, a technique that allows us to extend and preserve existing functionality. Continue reading

Posted in Mobile | Tagged , , | 2 Comments

Display Line Numbers on Embedded Gists

I've been working on a post here for C5 and in order to make my points, I was referencing gists hosted by GitHub. When those gists were shown as embeds, the line numbers, and thus the clarity of my documentation, was lost. We use Markdown for the creation of the texts so I needed something I could write inside of a Markdown post that would be applied as CSS.

Thanks to these tips:

  1. http://www.whyhat.com/2012/01/line-numbers-on-embedded-gists
  2. http://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript

I was able to come up with the following:

Posted in Web | 4 Comments

Does My Rails App Need a Service Layer?

Sometimes during domain modeling you come across something that isn’t a thing. These operations that don’t quite belong to an object are called services. Services often live in a separate, service layer. The service layer lies between controllers and models, defining an application’s interface, its API.

Designing with services and a service layer is popular in the Java J2EE/Spring community. However, it’s not common in the Rails world. Is this because of the Ruby community’s general backlash against the complexity of Java? Or has the rise of HTTP-based JSON APIs made this architecture obsolete? To answer these questions, let’s take a deeper look at services and the benefits of a service layer.

Continue reading

Posted in Design, Web | Tagged , , , | 18 Comments

Exploring Client-side MVC with Backbone.js

Backbone.js continues to gain popularity in the JavaScript MVC community. I decided to give it a try by creating a simple, single-page app to CRUD a single domain model.

While it wasn’t as trivial as a traditional server-side implementation in Rails, it did turn out relatively clean. This is a long post, and if you make it through it, let me know what you think.

Continue reading

Posted in Web | Tagged , , , | 5 Comments

Configuration for Rails, the Right Way

I still see people promoting various gems and plugins to handle miscellaneous configuration elements for your application. One little known secret is that Rails 3 allows you to define your own configuration elements trivially.

In this case, I wanted to use the nifty wkhtmltopdf utility to create a PDF. I was able to call the binary just fine with Homebrew on OSX but found that I had to use a custom binary checked into git for our production environment on Heroku. So I created a configuration variable to store where wkhtmltopdf could be found in the current environment.

First, we define a default value for all environments in config/application.rb:

module Configurator
  class Application < Rails::Application
    # By default, let OSX resolve the path to the binary
    config.wkhtmltopdf = "wkhtmltopdf"
  end
end

Then we override the default setting as necessary in config/environments/:

Configurator::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Point Heroku explicitly to the binary we need to use
  config.wkhtmltopdf = "#{Rails.root}/bin/wkhtmltopdf"
end

Lastly, we access the configuration element in our code:

  cmd = [Configurator::Application.config.wkhtmltopdf, url, tmpfile.path]

Yes, that’s it. Just use Rails’s environment support and config to store your own configuration elements. They’re trivial to set, trivial to access and require no third-party gems or custom text files.

Posted in Everything Else | 21 Comments

Why We Are an Agile Shop

Last week we had a lively discussion about Agile development at Carbon Five. It was fun telling the story of how we got started with Agile nearly a decade ago. We discussed how it helps us deliver value and deal with the challenges we face as a services company. Here’s a summary of that conversation…

How does Agile help us to do better work for our clients?

To answer that question, I think it’s important to reflect on what makes building a product hard. Here’s a clue: Everything.

Continue reading

Posted in Process | Tagged , , , | 6 Comments

Event: Our Experience Building OVEE on 12/6

We just wrapped up the first phase of a project for ITVS, the Independent Television Service, and want to share the experience. We built OVEE, the online video engagement experience, on a short schedule with a small team. OVEE is a highly-interactive application built using node.js, mongodb, and a slew of other new tools/frameworks.

Our talk is going to cover product design, process and technology. We want to share the whole experience of building a product, not just the technical details.

Product Design Topics

  • Design and development process
  • Usability testing
  • Prioritizing features to match a budget

Technical Topics

  • Overview of the architecture and technical stack (node.js, express, jade, socket.io, flash, etc)
  • Using development spikes to reduce technical risk
  • Testing node.js
  • Lessons learned

After our talk we’ll turn it around and open the floor for those in attendance to share their relevant experience, in 5-10 minute mini-talks.

Additional details and RSVP: http://c5-the-ovee-story.eventbrite.com/

Posted in Process | Leave a comment

Explorations in Go: solving the Instagram engineering challenge

The good folks at Instagram posted a fun challenge on their engineering blog recently:

"Your challenge, if you choose to accept it, is to write a simple script that takes a shredded image in as input and outputs an unshredded and reconstituted image. That is, imagine if you took an image, divided it into an even number of columns and shuffled those columns randomly to produce a shredded image. Then, take that image into the script and output the original image."

(The original post is here: Instagram Engineering Challenge: The Unshredder).

This struck me as a great opportunity to hack out some code in Go (rev 60.1) as part of my continuing exploration of the language and its packages.

Continue reading

Posted in Everything Else | 1 Comment

Generating realistic-looking stories in Pivotal Tracker

We are heavy users of Pivotal Tracker here at Carbon Five, and each project evolves workflows around its use. I recently spent some time writing a Chrome extension to help support some of the common interaction patterns that come up in our workflows.

This blog post is not about that.

I started to write up a post about the Chrome extension and how I developed it (forthcoming), but realized that I needed to show screenshots. Unfortunately, I can’t use images of a client’s production tracker. Hmm.

I quickly whacked together a Ruby script to generate realistic-looking stories in a tracker project. Here it is!

Continue reading

Posted in Everything Else | 2 Comments

Modern Cucumber and Rails: No More Training Wheels

Last month, cucumber-rails 1.1 was released. This release removed web_steps.rb, a collection of step definitions for interacting with a web app.

For months, web_steps.rb contained a warning of its negative effects on feature maintenance. Like most developers, I ignored the warning. During a recent upgrade of an existing Rails app, I realized it was now gone. Instead of copying and pasting it from an older app or using the newly created cucumber-rails-training-wheels gem, I decided to accept the challenge and refactor its steps out of the app’s existing features.

After the refactor, the features read much better. They were simpler, less verbose, and felt more maintainable. I also cleaned up my factory_girl usage, which was causing issues similar to web_steps.rb. Here’s a short overview of the main refactorings.

Continue reading

Posted in Process, Web | Tagged , | 13 Comments