New Rails Site: FanNation

Posted by Mike Blake Thu, 21 Sep 2006 17:25:00 GMT

The folks at FanNation have done something that no one else in the sports world has done. FanNation: The Republic of Sportmblakemblake's Favorite TeamsGet your own Favorite Teams Widget!mblake's Favorites Teams They’ve created a comprehensive site for sports fans to gather and share information about their favorite teams and players (fantasy too) , and it’s all free.

I spent some time with the developers at FanNation working on the map on the home page. They are a sharp bunch, and I’m constantly amazed at the features they are adding each time I visit. Fannation is now one of the biggest websites around developed on Ruby on Rails. Tag clouds, in place edits, Dynamic news updates using AJAX calls, personalized blogging. This site is a tremendous example of practical usage of some of the latest technologies. And it’s loads of fun.

There’s tons of other functionality I haven’t explored yet, but definitely keep an eye on FanNation!

Posted in  | Tags , ,  | 1 comment

Security Flaws in Diebold's AccuVote-TS voting machine

Posted by Mike Blake Thu, 14 Sep 2006 22:23:00 GMT

Princeton researchers have clearly demonstrated (watch the video) that the a model of the Diebold AccuVote-TS voting machine which has been used in US elections can easily be altered to steal votes in an election.

In their full report The researchers predicted that Diebold would claim that their other products were safe. Diebold went one better and actually tried to refute the obvious with smoke and mirrors.

There are serious problems with several statements in Diebold’s “rebuttal”:

“The unit has security software that was two generations old, and to our knowledge, is not used anywhere in the country.”

The author’s of the study noted that there is newer software, but the tested software was certified and used in elections. They also go on to say that some of the security flaws they found could only be addressed by hardware upgrades. The Diebold machines are running on a Windows CE operating system. As far as the claim ”to our knowlege, not used anywhere in the country” , why because there are no elections today?

“Normal security procedures were ignored.”

Ahem, That’s the point of the demonstration, To show that the security of the machine is flawed. “Our machine works great if no one hacks it!”

“Numbered security tape, 18 enclosure screws and numbered security tags were destroyed or missing so that the researchers could get inside the unit.”

Right but physically opening the machine was just one of 3 separate possible ways the demonstrators showed to install the malicious software. What about when they had a copy of the key, or when they picked the lock?

“A virus was introduced to a machine that is never attached to a network.”

Correct! Viruses have been around as long as floppy disks. Sure they don’t spread as fast as over the network, but slow spreading viruses aren’t pretty either.

“By any standard - academic or common sense - the study is unrealistic and inaccurate.”

A misleading statement not backed up with a single fact. The video of the machine being hacked is all too real.

As the authors of the study note:

“We expect Diebold to respond to this paper by offering similar assurances about other versions of their software and about their closely related AccuVote-TSx product. In light of past experience, public officials should remain skeptical until such claims are confirmed by independent investigators with full access to the machines and software. ”

While future assurances from Diebold may be more cleverly written, let’s hope that public officials are more careful and skeptical in the future.

Posted in  | Tags , , , ,  | no comments

Attend a Hackfest!

Posted by Mike Blake Tue, 12 Sep 2006 14:30:00 GMT

If you’re a programmer like me you’re a little intimidated by the Hackfest. That is , you’ve had several programming gigs over the years, attended a few more day long meetings than you’d have liked, and fear that you’ll be embarrassed by your perceived lack of skill compared to the young whiz kids with a burning passion for creating software.

We’ll let me assure you, the spirit of the hackfest is one of learning and cooperation and not at all that of oneupmanship or competition. At least not at the ORUG .

I had a blast this past weekend and learned a lot from my piers, and left with the feeling that I had helped out as well.

So my advice, fear not and attend a Hackfest!

Posted in  | Tags , , ,  | 1 comment

The Large application.rb File.

Posted by Mike Blake Sun, 30 Jul 2006 18:26:07 GMT

Where?

A common phenomenon starting to appear in some larger Rails applications is a bloated application.rb file.

Why does this happen?

Most of the time, developers place methods here to avoid duplicating code. The application.rb file is a convenient bucket whose methods can easily be seen by all the controllers in the application. In addition, these methods can be exposed to all the views in the application by using the ‘helper_method’

helper_method :find_valid_ad

So now all the views can see the exposed methods as well. Since the Views now have access to the Controller methods, it’s easy to fall into the habit of asking it to retrieve model objects via these helper methods.

What’s the problem?

This results is what design guru’s call Low Cohesion. A class with low cohesion is a bloated class that does many unrelated things. A bloated application.rb file, or any bloated class for that matter, has four fundamental problems.

  1. Hard to comprehend
  2. Hard to reuse
  3. Hard to maintain
  4. Delicate; constantly effected by change.1

Solutions

Class Methods

Rails views can automatically access all of our Model classes. By writing class methods on these models , we can eliminate some unnecessary methods in application.rb . Class methods in Ruby are similar to static methods in Java in that you don’t need an instance of the object to access the method.


So where should the extra method in application.rb live? The trick is to take a look at what the shared method in application.rb is returning. Is it returning an array of Model objects that are all of the same type? It’s better off living in that Model’s class file. If it returns a single instance of that Model, it’s an instance method. If it returns an array of that type, it’s a class method.


For the find_valid_ad method mentioned above, we can now make it a class method in the Ad model.

class Ad < ActiveRecord::Base

  def Ad.valid_ads
    # ... code from the old find_valid_ads method here
    # ...
    Ad.find_all_by_is_valid(true)    
    # ...
  end

end

Rails provides lots of flexibility in communicating between the Model , View and the Controller, so this line of code in the view

<%   find_valid_ads{ |ad| %>
  <%= ad.name %><br>
<% } %>

becomes

<%   Ad.valid_ads{ |ad| %>
  <%= ad.name %><br>
<% } %>

We’ve now eliminated an entire method from the application.rb file.

The MVC Triangle

The important thing to remember with MVC is that The View can communicate directly with the Model. Most web MVC frameworks encourage developers to think like this:

  +------+      +----------+      +--------+             
  | View | <--> |Controller| <--> | Model  |
  +------+      +----------+      +--------+

Rails developers can think like this:

               +--------+
               | Model  |
               +--------+
              /\        /\
              /          \
             /            \
            /              \
      +--------+       +----------+
      |  View  | <---> |Controller|
      +--------+       +----------+

Rails encourages well organized code writing and highly cohesive classes. With that in mind it’s easy to spot a class that is becoming unusually large. Typically the first one to get bloated is the application.rb file. Fortunately, this problem is easily fixed. Using common sense we can delegate responsibility to a more appropriate class.

Applying UML and Patterns, Larman, p203

Posted in  | 1 comment

Luke Bailey and His Ukulele / Tony Macaluso and The Procrastinators

Posted by Mike Blake Thu, 27 Jul 2006 21:24:00 GMT

Tony Macaluso is getting quite a following here in Orlando.

We’re playing tomorrow night, Friday 7/28 9:00 PM at Underground Bluz located at 4892 Conroy Rd, just south of Kirkman. (Near JJ Whispers).

Details here

It’s a double bill with local comic Luke Bailey and his Ukulele. Luke is lots of fun, and is the prime suspect in the case of

Who put this sign on my front lawn?

Posted in  | 3 comments

The Ruby Accessibility Analysis Kit

Posted by Mike Blake Tue, 25 Jul 2006 14:33:00 GMT

Raakt

I was excited to see that Peter Krantz heard the call from the Rails Core team for education about accessibility issues and created Raakt(Ruby Accessibility Analysis Kit). I put it to use immediately, but ran into a strange problem.

The rubyfull_soup gem, which raakt requires contains a class named ‘Tag’, and so does the project I’m using to try out raakt. So I got this error in my functional tests.

ActionView::TemplateError: undefined method `keywords' for Tag:Class

The View is looking for a Model object named ‘Tag’, but it’s finding the rubyfull soup Tag object.

then I tried explicitly loading my Tag object first, and I got this error.

TypeError: superclass mismatch for class Tag

The best workaround I found was to require ‘raakt’ just prior to using it in the method.

  def assert_basic_accessibility
    require 'raakt'
    rt = Raakt::Test.new(@response.body)
    result = rt.all
    assert result.length == 0, result.collect { |msg| "\n" + msg.text + "\n" }
  end 

This little problem reinforces what I mention below . It’s best to put new classes inside modules to give them unique namespaces.

Anyway, Raakt is a great addition to Rails built in testing capabilities. I’m adding it to all my projects.

Posted in  | no comments

Ruby Namespace Conflicts

Posted by Mike Blake Sat, 15 Jul 2006 10:30:00 GMT

Declare new Classes Inside Modules to Avoid Conflicts

In the ruby language you cannot have a Module with the same name as a Class. The reason is that in any instance of the ruby interpreter, all root level accessible Objects are stored in a Hash of constants as either Modules or Classes. This can get cluttered pretty quickly in a large application. Try throwing the line 'p Module.constants' in the middle of a medium sized Rails application.

However, if a class is part of a Module, which acts as a namespace in ruby, it’s name never makes it to Module.constants. So it can have the same name as an existing Module.

To see a demonstration of this, I executed the following ruby code.

module One
end

class Two
  def self.to_s
    "2"
  end
end
p Two

class One::Two
  def self.to_s
    "1::2"
  end
end
p One::Two

class One::Three
  def self.to_s
    "1::3"
  end
end
p One::Three


p Module.constants

class One::One
  def self.to_s
    "1::1"
  end
end
p One::One

class One
  def self.to_s
    "1"
  end
end
p One

Here’s what happened. (output below). A Module named One was created and so was a class named Two. And the interpreter saw that it was good. Then, in the One module, classes One, Two, and Three were created. And the interpreter saw that it was good.

Then I took a peek at Module.constants. The One Module, and the Two Class were saved as constants. But the Three Class was not stored as a constant because it is not at the root level. Since Classes created within Modules are not stored as constants,I was allowed to create a One Class inside the One Module without a getting a TypeError.

But all is not well in paradise. When the program tried to create a class named One it got the error

-:35: One is not a class (TypeError)

That’s because it’s already stored in constants as a Module.

As Ruby grows in popularity, this could become a problem. Especially in the Rails framework where all Model objects are at the root level. Considering this, it’s a good habit to use modules as namespaces when creating new classes in things like plugins and gems to avoid a TypeError.


Output:


1::2

1::3

2

["TrueClass", "FloatDomainError", "Fixnum", "TOPLEVEL_BINDING", "SignalException", "String", "SystemCallError", "UnboundMethod", "Buffering", "Rational", "ThreadGroup", "CROSS_COMPILING", "ScriptError", "MatchData", "Thread", "IndexError", "STDOUT", "One", "SecurityError", "Integer", "SingleForwardable", "Config", "RELEASE_DATE", "Exception", "NoMethodError", "Proc", "GC", "TypeError", "Binding", "Signal", "FALSE", "RUBY_PLATFORM", "Forwardable", "Bignum", "SystemExit", "Date", "NotImplementedError", "EOFError", "FileTest", "TRUE", "Numeric", "Interrupt", "ARGF", "Array", "SyntaxError", "MatchingData", "RUBY_VERSION", "ParseDate", "Time", "RangeError", "ENV", "NIL", "Enumerable", "Module", "PLATFORM", "STDERR","Two", "NoMemoryError", "Float", "Regexp", "DateTime", "Data", "ZeroDivisionError", "ARGV", "Dir", "Process", "Range", "ThreadError", "ArgumentError", "Object", "IO", "Comparable", "LocalJumpError", "Math", "Marshal", "RuntimeError", "STDIN", "Method", "VERSION", "RegexpError", "Hash", "Precision", "Kernel", "Continuation", "File", "SystemStackError", "OpenSSL", "FalseClass", "Errno", "NilClass", "StandardError", "LoadError", "ObjectSpace", "RUBY_RELEASE_DATE", "Gem", "IOError", "Symbol", "Struct", "NameError", "Class"]

1::1

-:35: One is not a class (TypeError)

Posted in  | Tags , , ,  | 1 comment

Rails Conference 2006 - Day 4

Posted by Mike Blake Fri, 14 Jul 2006 00:14:00 GMT

Flashdotted

As the conference winded down, the great information was coming fast and furious. But my mind was a bit overwhelmed. I took in a talk about Laszlo on Rails by Mike Pence. Laszlo is an open source platform for developing Flash applications. Well I saw the last 15 minutes of it anyway, I got in a bit late that morning. And England was up in the world cup shortly.

Internationalization

So I headed over to the lobby bar to watch Soccer. England was playing Ecuador, and I sat there and watched the match with most of the English supporters including Martin Fowler. Martin Fowler is a very cool guy, and sat there and joked around with the attendees like any good Englishman would while watching soccer with the lads. If there was a bartender that morning (or if I’d found any beer behind the bar) the conference would have been over right there.

Meta Programming

But the learning wasn’t over. With England up 1 - 0, I decided to go see Stuart Halloway talk about Meta Programming in Rails. Stuart showed us tons of great programming tips:

He also expanded a bit on what David Heinemeier Hansson touched on the night before, natural language modeling, that is looking at adjectives and adverbs when defining a model.

Meta Configuration

After lunch I saw James Duncan Davidson speak. JDD created Ant and now is championing the effort to simplify Rails configuration and deployment. He spoke to us right from the trenches and I could tell he’d been through the pains of several deployments. It’s fascinating how many of the leading software engineering minds have embraced the Rails platform so quickly. Now it was time to meet the core team.

The Rails Core Team

We stayed in the main conference room and watched as a panel discussion with the core team began. The last time I saw a panel discussion like this was at Java One in San Francisco. But at that panel discussion I got the sense that everyone was trying to outdo each other with trendy acronyms starting with X. I didn’t see any of that attitude here. The Rails core team seems like a pretty down to earth bunch of guys. They’re also wicked smart and good at what they do. They politely disagreed at times, and admitted when they needed to be educated more, such as with accessibility issues. One member talked about learning a new language every year, sort of mental calisthenics. DHH also suggested that the best way to contribute to Rails right now is documentation.

Meta Presentation

The conference organizers then said a few words and gave out prizes. Mike Clark, Chad Fowler, Jay Zimmerman and several others seemed like the were enjoying themselves, and their exuberance helped set the tone for the conference.

My Kind of Town

The conference finished up and I said goodbye to some brilliant people. Then I enjoyed dinner in Chicago with 2 of my new friends Peter Krantz and Andreas Ekström. At dinner we conceived of BatroomAttendant an application to help people improve their careers. Peter and Andreas completed a working model with just 2 hours of battery time on their flight to Sweeden. I’ve register the project at rubyforge so stay tuned for updates.

Posted in  | no comments

Rails Conference 2006 - Day 3

Posted by Mike Blake Wed, 28 Jun 2006 02:50:00 GMT

Working Software Over Comprehensive Documentation

After throwing back a few drinks with some software icons the night before, I managed to make it to the morning talk, given by Justin Gehtland. Justin covered a bunch of the basic Ajax tricks available in Rails then finished his presentation with a bang.

He debuted Streamline, an open source framework that drasticaly improves scaffolding. I’m looking forward to the release in the next couple weeks.

Next up was Doug Fales who is a great example of a single developer creating some great software in a way that just wasn’t possible in the not too distant past. He showed us WalkingBoss which allows users with digital cameras and gps locators to document hikes, runs or rides online.

Inspiration

Afterwards I took a break and began blogging in the lobby about the day before when suddenly an interview with David Heinemeier Hansson broke out as I mention near the end of my post below.

Most of what David said, he said again in his keynote. My favorite part of the interview, the woman interviewing him looked around and at me and said, “It seems like there’s a lot of people here in their 20’s and 30’s.” Then she asked if only young people use Rails. I must look like such a young whipper-snapper carrying around my mac-book on my back.

David replied “I don’t think age matters really.” And continued to say that it’s more attitude and willnigness to learn new things. When asked about confronting people with old habits he responded that if he sees someone doing something that can be done a better way, it would be immoral not to say anything. It really struck me at that moment how driven this guy is.

The interviewer then asked why he made Rails open source. He responded that it would be selfish not to. Again I sensed that this is a man with deep convictions which clarifies just why his framework is so good.

After the interview ended, I sat there fully enjoying the moment. Some Charlie Parker came on, “Hot House” with Dizzy Gillespe from that video clip of the two of them. Then an interview with Chad Fowler began. Chad mentioned to the interviewer that he is a Jazz Saxaphone player, and everything was groovy.

Motivation

In the afternoon Mike Clark gave an awesome presentation on testing, and managed to get some guys who admitted to neglecting testing excited about doing it.

[Nathaniel Talbott] gave a cool talk about Homesteading, which inspired this site, barnraisr .

Today the focus was on working software, and the keynote from dhh was no exception.

Edification

David’s not a preachy guy. He got right into telling us some of the latest enhancements going in to Rails. He also repectfully disagreed with Dave Thomas a bit about making Rails flexible enough to support poorly designed corporate databases. David certainly hasn’t seen as much of the world as Dave Thomas has. But you’ve got to admire his idealism.

On page 241 in Agile Web Development with Rails is a section called “When a Join Wants to be a Model”. This section really made me think when I first read it, and dhh talked about this design technique quite a bit in his keynote. He talked about when a contoller has 12 methods or something like that, you’re probably missing a model in your domain. Also, when method names have namespaces, or underscores, they likely belong somewhere else. He touched on interesting concepts that I had never really grasped, like modeling Adjectives and Adverbs. Both are easy with ruby.

Speech Design Concept Ruby Java
Noun Class/attribute Class Class
Verb method method method
Adjective AOP Mixins Langauge Extentions
Adverb Dependency Injection Closures IOC(Inversion of control) Container

Adjectives are typicaly Mixins like Enumerable or Comparable. Adverbs, which modify behavior of a verb (function), are code blocks (or closures) in ruby. Then he took a dig at Java and pointed out that Java needs Dependency Injection and Aspect Oriented Programming to accomplish the same things.

The most stunning enhancement he talked about is ActiveResource. ActiveResource provides an HTTP interface for basic CRUD operations on a model.

He proposed using POST, GET, PUT and DELETE to represent Create, Read , Update and Delete repsectively.

In order to handle PUT and DELETE which aren’t implemented by most HTTP servers or browsers (yet), he proposed having a hidden variable in the HTTP header along with a POST to signal the correct action to the server.

ActiveResource would of course support the usual types of authentication. The great thing is, it would be easy to create web apps in any langauge to conform to this clever protocol. So dhh may have greatly simplified how we handle RESTful
(I had to look it up too) Web services.

Recreation

After the speech, Gregg and I decided to head towards downtown Chicago. Gregg mentioned earlier in the week that he and his wife love going to the theater, so I located a theater in an interesting neigborhood just within the city limits. As the Agile Ones say, “Individuals and Interactions over processes and tools.”

Posted in  | 1 comment

Rails Conference 2006 - Day 2

Posted by Mike Blake Sat, 24 Jun 2006 18:03:00 GMT

More Women than Dells

Today was mind expanding. Above all else, I got to know some fantastic people. Before the opening keynote I had breakfast with Gregg Pollack who heads up our local Orlando Ruby Users Group. Gregg and I then headed into the main room to watch Dave Thomas speak. At least 80% of the conference attendees were using Mac-books. White ones. The simplicity of Rails and the Mac must have something to do with this marriage. One thing is certain, there are more women here than there are Dells.

Dave Thomas

Dave kicked off his keynote talking about how much momentum Rails has been building. After showing us some Google Trends, we were led to an obvious conclusion. Rails is about to be utilized in the “Enterprise”. Then Pragmatic Dave did something bold. He threw down the gauntlet, and challenged early adapters to prepare the framework for the inevitable; Widespread use in corporations. I had the opportunity to thank Dave afterwards, not just for the talk, but for inspiring me to revive my programming career a few years back, after seeing him and Andy Hunt speak in Atlanta.

Mike Clark

Mike began his talk with his famous intro. “Java free for 1 year 3 months and 6 days.” Mike gave us a tour of Capistrano which he called the best deployment tool in any language. While it’s awesome at deploying Rails apps, he even explained how it can be used to deploy non Rails or even non Ruby applications. Mike is an established leader in the field of Automation. I’m amazed when someone published and successful still keeps on top of the latest technology, but then again thats standard for the pragmatic crowd.

Stefan Kaes

This speaker was fantastic. A real nuts and bolts, numbers guy. He’s pretty much been obsessed with with analyzing and improving performance of rails over the past year. Guys like Stefan save the rest of us so much work, and are the reason for the success of this framework.

Chad Fowler

During the lunch break I got up the nerve to introduce myself to Chad Fowler. At least I though I had gotten my nerve up, but when I stared talking, I sounded like a nervous school girl. Pretty embarrassing, but Chad was very gracious and signed my copy of his new book, Rails Recipes . As my brothers would say, I was geeking out. Sad really, but read on, it gets better.

Amy Hoy

Later I saw Amy give a great talk on starting projects off without using scaffolding. This was a beginner level talk, but I’ve found that when smart people explain basic things, I always learn something new, and this was no exception. The “Filters are Fun” part was a great reminder of the beauty and simplicity of Rails.

Martin Fowler

After 5 PM, we got into the meat of the bating order. Martin Fowler began with a bold confession: He hadn’t used Rails yet. He then went on to explain why it’s so great:

  • Dispels the ‘quick and dirty’ myth. Rails is quick and clean.
  • encourages agile development or conversational development. Which is working closely with users to deliver what they need.
  • Rails is great because Ruby is great. So many components already exist out there. Ruby and Rails make an excellent glue.

Paul Graham

Paul gave a great talk on why great ideas come from the margins. Many rails enthusiasts here have recommended his book “Great Hackers”. Paul is a bit of a rebel, or maybe even a revolutionary. He had a great anecdote about getting things done, and if their getting annoyed that your doing something, your on the right path.

Why The Lucky Stiff

Did I say mind expanding before. Good. Now how about mind altering. There are three kinds of people in this world. People who fit into a #{category} (pick one of your choice here), and people who don’t fall into that #{category}. Then there’s the third kind, Why The Lucky Stiff. I have no idea how he got this name, no one will lever know because it’s grammatically impossible to ask him. “Hey Why, Why Why The Lucky Stiff?” See, an incomprehensible sentence. Even if you’ve never programmed before or have no reason to, you should really learn Ruby just so you get a few more of the jokes when you have an opportunity to see Why The Lucky Stiff.

Epilogue

After Why’s mind altering presentation, I needed something. So I stopped at the hotel bar Maxines for a refreshing beverage. I had a great time meeting Geoffrey Grosenbach who has written quite a bit of code I use. Then at the bar I asked Dave Thomas if he’d ever seen Why perform. He started telling me about seeing him in small room in Oregon. we were interrupted when Dave had to go to the bar for his drink order. You know an amazing thing about the Ruby community? It doesn’t matter if you’re brand new to the technology, or the the father of Ruby in the US, there’s really not a ridiculous amount of attitude or ego around. So here’s what happened.

All right, right now, 10 feet from me, a young woman is interviewing David Heinemeier Hansson, the inventor of the Rails Framework. I’m listening in and don’t want to be obvious, so am just typing. Well without stealing content of this here interview, this guy is obviously incredibly bright and down to earth. And he fits in great with the whole Ruby community. So this really is about the people.

OK back to last night, Dave Thomas was off to get a beer. After he got it, he came back to me and said, “Sorry, priorities.” Then went on to finish his story about seeing Why perform. He told me the story with the passion and humor that you sense when you read “Programming Ruby” or “The Pragmatic Programmer”. Dave is probably the main reason Ruby caught on here in the US, so this all wouldn’t be happening quite like this without him. Yet here he was spending time with the atendees, and sincerely enjoying it.

Am I a programmer yet?

It’s unbelievable. I’m about done with this entry, but David is still being interviewed. But technically this is Day 3 right now, so I’ll let you know what what happens tomorrow.

Posted in  | no comments

Older posts: 1 2 3 4