Amazon Web Services Start-Up Challenge

Posted by on October 29th, 2007.

Intridea is excited to participate in the AWS Start-Up Challenge.

We've entered three of our applications:

Scalr is a self-curing and auto-scaling environment built on EC2 and S3. Scalr makes it dead simple to create, configure, and maintain a custom server farm for your application that's fully redundant, self-curing and scales automatically based on load averages.

MediaPlug allows site operators, developers, and entrepreneurs to add images, audio and video to their websites at a fraction of the cost. It's a white-label plug-and-play solution that provides image, audio and video transcoding to dozens of popular formats.

SocNet is an extensible and fully customizable full-featured white-label social networking platform.

All three products will officially be beta launched November 5.

Share:

Comment on this post (0 comments)


Improved BetterNestedSet Plugin

Posted by on October 27th, 2007.

On a recent project when I was using the BetterNestedSet plugin to manage a large hierarchal set of data, I encountered a problem that required me to find all of the items in a nested set that had children and those that didn't. In nested set terms I wanted: all 'parent' nodes and all 'leaf' nodes that exist within the 'tree'.

If you want to do this through the current BetterNestedSet interface you might be tempted to do something like this:


Continue reading this post

Share:

Comment on this post (1 comment)


DRYing markup using block-accepting helpers

Posted by on October 19th, 2007.

As much as we all strive to write perfect, semantic XHTML that can be styled entirely independently, the reality of browser compatibility and even our own creative choices often leads to design refactoring. Obviously in Rails one big help for this is the use of partials, making sure that you can change your markup in one place and it will be reflected for often-repeated content. But what about for lower-level, underlying layout structure? Nested partials quickly become a mess to deal with, and traditional helpers don't always offer the flexibility and intelligence that is needed to get the job done.

Enter block-accepting helpers. These allow you to wrap markup around content without the ugliness of a my_thing_start and my_thing_end. With a little more work, they can also provide an intelligent layout structure that requires minimal (and beautiful) code in the view. Let's start with a simple example. Lets say that most, but not all, of the pages in my app have a similar container and title. Creating multiple layouts using partials for everything just to add or not add a couple of lines of code is way too heavy. On the other hand, my designers want the flexibility to change how the container is represented in markup, so I can't just throw the markup into each action. Here's the markup I want (for now):

<div class='main_container'>
    <h3><!-- Some Title --></h3>
    <!-- Some Contents-->
</div>

This is obviously pretty basic, and wouldn't be a big deal to change if the design changed, but this is just an example. If you're dealing with some kind of nested div rounded corner solution, or any number of other necessary CSS/markup hacks to get the look you desire, it could become quite a chore. So how do we create our DRY helper? Primarily through the use of the concat method in the ActionView::Helpers::TextHelper module. Here's my helper (just put this in either the relevant helper or ApplicationHelper:

def main_container(options = {}, &block)
  concat("<div class='main_container'>",block.binding)
  concat("<h3>#{options[:title]}</h3>",block.binding) unless options[:title].blank?
  yield
  concat("</div>",block.binding)
end

So that wasn't so bad, was it? Now in our views all we have to do to get our main_container is:

<% main_container :title => 'My Page Title' do %>
    <p>We can put whatever we want here, and it will appear inside the container.</p>
<% end %>

Cool, huh? There are other resources that dig much deeper into blocks, procs, and the ruby wonderfulness going on behind the scenes, but this is purely a functional demonstration. Suffice to say that placing a &block (or &proc or whatever you want to call it) as the last parameter of a method allows that method to accept a block and later yield to it. The yield statement works much the way it does in layouts, passing code execution for a time and then getting it back when the yielded code is finished.

Do make note that, like form_for, you do not use the <%= but just <% when declaring your block. This is because you aren't returning anything, but rather directly concatenating code onto the binding passed when you make the block call.

Now that was certainly useful, but doesn't really have that 'wow' factor that really makes you appreciate a new way of doing things. Let's take a stab at another common problem in app design: menu systems. Using block-accepting helpers and introducing the concept of a builder class, we can build menus intelligently and easily.

The implementation you are probably already familiar with of this type of class is the FormBuilder used in form_for. We will take that same concept and apply it to menus on a web application, taking care of a number of common headaches associated with menus. Here's the whole enchilada, and we'll go through it piece by piece. This code should be dropped into a helper:

def menu(options = {}, &block)
  id = options[:id] || 'menu'
  concat("<div id='#{id}'><ul>",block.binding)
  # we yield a MenuBuilder so that specialized methods 
  # may be called inside the block
  yield MenuBuilder.new(self)
  concat("</ul></div>",block.binding)
end

class MenuBuilder
  def initialize(template)
    # by passing in the ActionView instance, we gain 
    # access to all of its helpers through @template
    @template = template
    @action_count = 0
  end

  def action(name, options = {}, html_options = {})
    # create a local array for the classes we will be tacking on to the list item
    classes = Array.new
    # add the 'current' class if the current page matches the link options
    classes << 'current' if @template.current_page?(options)
    # add the 'first' class if this is the first time we've added an action
    classes << 'first' if (@action_count == 0)
    @action_count += 1
    "<li class='#{classes.join(' ')}'>#{@template.link_to(name, options, html_options)}</li>"
  end
end

So that should look at least somewhat familiar, right? Here's a sample implementation so that we can talk about what's going on:

<% menu do |m| %>
  <%= m.action 'Home', home_path %>
  <%= m.action 'Blog', blog_path %>
  <%= m.action 'Account', edit_user_path(current_user) %>
<% end %>

So in just a few readable lines of code, we've done all we need for a pretty complex menu. However, because of our helper, all of the complexities are going on behind the scenes! So let's talk about our helpers. The actual helper that we call is very similar to the one we made earlier with one difference: rather than yielding with no parameters, we yielded a MenuBuilder object, which was then called in the yielded code to create menu actions. A builder can be used when there needs to be state information or more complex logic than simple helpers can provide.

In this case, we wanted to make sure that an action was marked as the first action if it was indeed the first to be called. By implementing an instance variable to count the number of actions that had been called, we are able to do this with ease. Additionally, if we ever wanted to change how the menu items were rendered, all of the changes are completely contained in the helper and builder, leaving the views unchanged.

I've found it a useful practice to stub out block-accepting helpers for any markup that I think I'll be using frequently at the start of an application. This gives the developers a chance to keep going while the design can evolve on a completely separate track. Additionally, it creates some fantastically readable code in the views.

Share:

Comment on this post (1 comment)


Intridea Presents at Facebook Developer Garage

Posted by on October 13th, 2007.
Dave Naffis demonstrated Intridea's Photo Greeting Card Application in-front of a technology audience at the Facebook Developer Garage event in Washington DC. This event was sponsored by Facebook and the local tech companies. The demo followed a lively discussion of new features and enhancements. Kudos to Pradeep for developing the app in one weekend.

Intridea is developing several facebook apps for large corporations to extend the corporate brand into facebook's social graph.

Share:

Comment on this post (0 comments)


Intridea at Startup Weekend DC

Posted by on October 13th, 2007.
Chris and Barg will be participating in the Startup Weekend DC on October 26-28. We are sponsoring the event. We are looking forward to sharing ideas and building relationships with our DC tech community. Please stop by and say hello to us.

Share:

Comment on this post (0 comments)


Selenium_on_rails Quick Start

Posted by on October 9th, 2007.

Over the past few days I've been diving into Selenium, an automated functional testing tool for web apps. It's pretty slick - in fact, like most of the technologies I've been using over the past two years, it does so much for you that the struggle always ends up being a matter of getting out of its way and letting it do its thing. So I'm gonna throw out some pointers on using Selenium within the Rails testing framework via the selenium_on_rails plugin; the only caveat I'll mention is that this post is especially geared towards the newbie wading into a project with pre-existing selenium tests. So I'm focusing on how you can get started with writing tests and integrating them into what's already there.

Open up firefox and install the Selenium IDE extension. This allows you to record your test by simply using the browser. The IDE keeps track of where you click - just make sure the record button is on. Go ahead and click through your test application and watch as the IDE records your actions.

Now you need to go into your selenium_on_rails plugin area and edit config.yml. In the browser config area, make sure it's pointing to your browser binary. For example, I kept most of the defaults, but made sure the following lines were there, uncommented:environments:
  - test
browsers:
  firefox: '/Applications/Firefox.app/Contents/MacOS/firefox-bin'

Next, especially if this is a project with existing tests, make sure you've installed the right user extensions. These are prefabbed actions for doing things like logging in via javascript. In my project I found this file in:

vendor/plugins/selenium_on_rails/selenium_core/scripts/user_extensions.js

All you need to do is point the IDE at this file by opening the IDE window and navigating in the top menu to "Options > Options > General tab". Put the path to user_extensions.js in the input box entitled "Selenium Core extensions (user-extensions.js)".

OK, so let's take a look at the existing selenium tests. They're probably in test/selenium. If there's subdirectories under that, these are probably test "suites". For example, in the project I'm working on, they're organized depending on which type of user the test is geared towards: user or admin. The actual test scripts can be recorded in a variety of formats; mine are all HTML tables, where each row is a step in the process.

So let's get to recording tests. First, start your server in the test environment:

mongrel_rails start -e test

The whole premise of testing is verifying the response to an action. In Selenium, this is accomplished via assertion statements. The IDE makes this elementary: when you've reached a page on which you need to verify the output, just highlight the text and right click. At the bottom of the popup menu, several approaches to verifying the text are mentioned. I don't understand all the "selenese" yet but there's simple commands like "assertText" that ensure a particular passage is included on the page - that should get you started.

So you've recorded the steps necessary - now click "File > Export Test As" and save it in the correct test directory in the format you wish (such as HTML). Now you should be able to run this test via rake test:all. That's it!

Share:

Comment on this post (3 comments)


Campfire SVN and email notification

Posted by on October 5th, 2007.

Here's a quick way to add Subversion notification for Campfire using Tinder.

Create svn-campfire.rb with the correct username and password:

Add this to your SVN post-commit hook:

/usr/local/bin/ruby /path/to/svn-campfire.rb "$1" "$2"

Here's a quick way to send emails to campfire. Create an email address to use for sending messages to campfire and then create mailer-campfire.rb with your domain, usernames and passwords:

Then create a cron job to fire this off every minute:

* * * * * /usr/local/bin/ruby /home/path/to/mailer-campfire.rb

We also use it to remind us of daily standups:

Our cron job fires it off every weekday at 2pm.:

0 14 * * 1-5 /usr/local/bin/ruby /home/path/to/status-campfire.rb

Next step, create a Jabber gateway for Campfire using Tinder.

Share:

Comment on this post (1 comment)