A source code browser 1

Posted by Daniel Wanja Mon, 20 Feb 2006 21:55:00 GMT

Browse::Source is a simple source code browsing application. It’s 100% based on Collaboa, it’s mostly the source code browser functionality but uses the file system rather than connecting to subversion.

I recently got a request from Justin to have access to some ‘old’ rails code (flexonrails) we wrote a while ago, and also Todd asked for the source code of autumnriders. So I tried Collaboa but it requires to compile subversion from the source in order to have swig-rb. So I extracted the source code browser from Collaboa and removed the dependency on swig-rb. Now if all you need is to add simple source code browsing…then Browse::Source is what you need.

Well, we haven’t posted yet the two code bases mentionned above, but have a look at the source code browser source code Browse::Source

Graphs with Gruff 4

Posted by Daniel Wanja Mon, 20 Feb 2006 12:10:00 GMT

class GraphController < BaseTimeController
   def pages
      g = Gruff::Pie.new("500x350")
      g.title = "All Pages" 
      @current_user.pages.each do |page|
        g.data(page.title, [page.total]) 
      end
      send_data(g.to_blob, 
                :disposition => 'inline', 
                :type => 'image/png', 
                :filename => "timers.png")
    end
end
Pretty easy! Wasn’t it. Note the code above shows only the first of the graphs. Now if only I could find out how to set the minimum of the Bar chart to 0 instead of the minimum of the serie. Any help is appreciated?

I'd rather be on RAILS. 1

Posted by Daniel Wanja Fri, 09 Dec 2005 21:44:00 GMT

This statement is pretty true right now, Rails is just a pleasant development environment. Mike Clark left this sticker at my desk at one of the places I am currently doing a Rails project at.

For another client I am doing a Flex project and work with many great java developers. I thought I would put the sticker in a visible spot and see their reactions. Well, it didn’t fail, some of the comments where pretty funny. Here they go:

  • That’s a big statement.
  • We’ll run you out on a rail.
  • So you would rather be on rails, hein?
  • HuHan!
  • You really are a geek.
  • Where did you get it? You didn’t get one for me?
  • He’s a convert.
  • You are pushing the Ruby stuff today!
  • It looks like it should have a Lenin on it.
  • I’d rather be fishing.

The “Lenin” one I didn’t totally get, even after a long discussion, but I sounded pretty funny to me. As you see, give me a sticker and will say good things about you. No, that’s not the case, I just think Mike Clark and Dave Thomas are putting a very compelling training together, and with these two guys you will learn more in three days than you would ever in any other places. Check out http://pragmaticstudio.com and their new Rails Studio, coming to Denver in January.

An on-line store build with Ruby on Rails 21

Posted by Daniel Wanja Sat, 03 Dec 2005 15:04:00 GMT

In this non-technical article I wanted to share my impressions of writing an online store with Ruby on Rails. http://www.autumnriderstees.com/

Background

On September 9th Lee’s dad mentioned that he would receive a stock of new quality designer T-shirts with funny bikers logos on September the 22nd and asked Lee if he could setup an on-line store. Lee asked me if I could help out writing it in Ruby on Rails and if I thought it was feasible. Hey, I just finished “Agile Web Development with Rails”, how hard could it be, the book contains everything we need. So “heck, yea, we can do it”. So Lee told his dad: “Sure, we’ll do”. Well, it took us just a little longer, not much thought, considering we just met once a week for a month, and two weekends. But considering that Lee just started a new Rails gig, me just being father for the second time and a little sleep depraved, we manage to go-life on October the 16th at RubyConf 2005. First Ruby and Rails is really cool, Dave Thomas books are invaluable in many aspects, not the least being that the most of the order processing part of the application is taken straight from book.

The application

The application is composed of the Store and the Order processing application. The Store allows selecting 4 T-shirt designs each in 5 sizes, to add the ones you like to shopping cart and finally go to a checkout page where shipping and billing information can be entered. Payment processing is done using the payment ruby library that supports Authorize.net merchant accounts (that’s just the one we needed and we go the credit card payment processing integrated in 10 minutes :-). All in all we built the most basic on-line store that one can build. Nowadays such a store can certainly be setup for a couple of dollars with yahoo and other providers. But the fun part was to do it and learn from that. Maybe if Shopify was open for business we wouldn’t have tried to write our own on-line store…but then again we wouldn’t have learn as much.

There are many things that can be improved and we are already planning for next year to add support for more products, designs and configurations to support things like Mugs and Long-Sleeve Shirts. So there will quite some refactoring for the next iteration.

The development process

Well…we where not too formal I believe, we used Basecamp to communicate ideas and create todos and then we just jumped in. Lee’s approach is usually more intellectual and he wants to get things pretty nicely laid-out before starting and I like to start and learn from what we discover and improve has we move along. Together we got a good mix. Lee’s dad just wants to sell his t-shirts. Now regarding Basecamp, if first thought it would be “overkill” for such a small project but it’s really a nice communication tool and helped us out getting organized without having to really think about it.

The look and feel

It’s got to work well, but that doesn’t matter if it’s not looking good. It’s got to look good. Well…we are software programmers, software designers, software architects, but even thought I don’t like to admit it, pretty lousy graphic designers. My first attempts to prototype the site gave a good feel of the structure and style…but just didn’t cut it. On the side for simple html work I use RapidWeaver, a cool tool on OSX to rapidly build html website of predefined types. This tool does a great job of separating content and style and provides a bunch of pretty nice html design that rely heavily on css. Well it took me about five minutes to get a pretty nice proto for the store using that tool and that’s what we went with. The nice part is that is was pretty straight forward to change the static site into dynamic .rhtml pages. Layouts in Rails are just awesome. From an usability point of view, we still have one step to much as the cart and checkout page should really become one. For the next version, we will try to have it similar to the Panic’s Good Store.

DataModel

The data model was fairly straight forward mostly consisting of an Order having many LineItem.

show larger image

Architecture

Although a file structure of an application doesn’t depict an architecture, Ruby on Rails really provides a nice starting point for organizing your code in a clean MVC (model-view-controller) manner and really makes it straight forward for a simple application like this one.

show larger image

Credit Card Payment

Let’s look at some code. First we need the payment gem.

require 'payment'

Then we just need to submit the transaction. I was really as simply as that. Of course you need a merchant account.

def process_payment(order, credit_card_number, credit_card_expiration_mmyy )
    @transaction = Payment::AuthorizeNet.new(
                      :prefs       => "#{RAILS_ROOT}/config/payment.yml",
                      :amount      => @cart.total_price,
                      :expiration  => credit_card_expiration_mmyy,
                      :first_name  => order.bill_to_last_name,
                      :last_name   => order.bill_to_first_name,
                      :card_number => credit_card_number,
                      :invoice     => order.order_number,
                      :test_transaction => RAILS_ENV != 'production'   
                     )

    @transaction.submit
    @transaction.authorization
end

Migration

We went only through the following database schema migrations:

001_initial_schema.rb
002_add_order_ship_date_and_status.rb
003_add_order_date.rb
004_add_users.rb
005_add_product_options.rb

However writing migrations in Ruby is just such a simple solution and make so much sense that I am surprised that there is no standard tools like that in the Java world.

Let’s look at migrating the schema to version 2. We need to add two columns to the orders table and default existing values to ‘Open’. No to move from version 1 to 2, simply issue the command rake migrate. If for some reasons we wanted to revert to version 1, we could issue the command rake migrate VERSION=1.

class AddOrderShipDateAndStatus < ActiveRecord::Migration
  def self.up
    add_column :orders, :shipped_at, :datetime, :null => true
    add_column :orders, :status, :string, :limit => 40, :default => 'New', :null => false

    execute "UPDATE orders SET status = 'Open'"
  end

  def self.down
    remove_column :orders, :status
    remove_column :orders, :shipped_at
  end
end

The “Ajax” thing

Of course we had to play with this. We only used the no page refresh approach when updating the cart. Note when you change the quantity of a given item, the Cart and Checkout tab both get updated dynamically, as well as the total of the order. Note that I only found after the fact the “right” way to update multiple ids from a single server call using evaluate_remote_response instead of our custom solution. In addition with the new javascript supported template (.rjs) all that will be cleaned up for our next iteration.

Testing

We didn’t take a fully Test First Development approach, but Rails makes it so much fun to test that we quickly went back to writing tests while we where developing some of the classes like the cart model and the store controller.

Hosting

I believe that deploying a Rails application in a hosting environment is the weakest point of Rails today. We are using two hosts for different matters, TextDrive and Dreamhost. On other projects we are working with Tom who also happen to have helped Dreamhost setting up Rails on their server and made it pretty easy to deploy a Rails application. So Dreamhost is the route we went, however the application doesn’t always respond nicely and at least not in a consistent manner. I guess that’s maybe what we deserve by using a $9/month hosting plan. Let’s hope that http://railsbase.com from TextDrive will provide a more compelling experience where we don’t have to regularly kill ghost fastcgi processes.

Conclusion

It was a fun learning experience and Rails made it just enjoyable. Ruby and Ruby on Rails forces you to write clean and simple code, encourages you to write unit tests and to refactor stuff as you move along. It’s impressive when comming from a java enterprise background how much more enjoyable and faster development becomes when using Rails.

RubyConf 2005 and RubyWeek

Posted by Daniel Wanja Sun, 16 Oct 2005 21:36:00 GMT

RubyConf 2005 and RubyWeek

What a Ruby Week. I am on the plane back to Denver from the Ruby Conference 2005 that just finished in San Diego. On the beginning of the week I started a new part-time job working on a Ruby on Rails application. On Thursday I flew to San Diego for the conference. Later that evening, with Lee we fleshed out the latest bug of our first on-line Rails application, and put it in production. If you are a Biker and like funny shirts, check out AutumnRidersTees.com. It’s a very small on-line shirt Store. Thank you Dave Thomas for your book on Rails, it was also a nice kick-start for our application, especially the non-public/administrative side of the site. On Friday the conference started, and what a conference, about two hundreds geeks and Ruby fans, inclusive many of the key players that create Ruby, Rails, and many of the awesome frameworks we are using everyday. It’s funny to put a face on who is behind these frameworks. For more info on the speakers checkout the agenda. Matz,the creator of Ruby, and ko1, the writer of the upcoming RubyVM, presented their views on the future of Ruby. I am not sure if this comes from the Japanese culture, but the elegance, simplicity and power, that radiates from the existing and forthcoming releases, made me want to to study this country. About 15 of the attendees came from Japan. It’s interesting how the community still feels small and is so open (and fun) when attending the conference especially when you realize the potential of Ruby and the power meta programming provides by creating domain specific languages. Rails is an example of that puts that power to good use. Speaking of Rails, David Heinemeier Hannsson, provided a nice state of the union for Rails and a hands-on workshop (he worked, we watched) of the forthcoming Rails 1.0 functionality. Rails was the trigger for me to dive into Ruby, and what is coming out will impress many java shops. SwitchTower to deploy applications from a single server to large clusters. Gauge to monitor your application and see what’s going on, live, on your servers. So many other improvements that are just practical. Tom took quite some notes of that presentation. Before the Rails talks I also enjoyed an interesting talk of domain specific languages in general by Jim Weirich followed by a Karlin Fox’s talk on how to create a user oriented specification and testing languages using “english” thus allowing a non-programmer user or business analyst to express the expected behavior of the application. The amazing part is that this domain specific language is implemented using Ruby and results in runnable unit test that excerse the user interface.

A great conference and a great Ruby week.

dvds.onrails.org - integrating Flash with Ruby on Rails

Posted by Daniel Wanja Sun, 31 Jul 2005 23:34:00 GMT

The purpose of the DvdReleases demo application is to investigate some of the possibilities to integrate a Flash Component with a Ruby On Rails application. We will describe:
  • Enabling flash and javascript integration
  • Embedding the FlashTag in the .rhtml file.
  • passing initial values to a Flash component from an ActiveView.
  • embedding multiple Flash components in a .rhtml file.
  • Invoking remotly an ActionController from a Flash component.
  • Calling a javascript function from a Flash component.

Keep Reading>>

Click here to Try it!>>

RubyConf is on the radar.

Posted by Daniel Wanja Thu, 09 Jun 2005 22:16:00 GMT

Lee, Tom, and I just booked for the RubyConf 2005 in San Diego that will take place October 14th-16th. So hope to meet you there...

No fluff just stuff

Posted by Daniel Wanja Sat, 14 May 2005 23:46:00 GMT

I spent most of my week-end learning new stuff, and I also attended the Wedding of Marla and Lee. It has been pretty busy and pretty fun.
Day 1.
It all started on Friday the 13th. Good day to start a seminar with four "Dave Thomas" sessions that where pretty impressive, especially that I just read two of his "pragmatic" series book, namely
The Pragmatic Programmer and Programming Ruby (2nd. Ed.) . The talks are 1. OpenSource Ecosystems 2. Ruby for Java Programmers 3. Ruby on Rails 4. and the Keynote du jour. His first talk "OpenSource Ecosystems" highlights the principles behind successful open-source projects and how it could be applied to your enterprise projects. His keynote presentation on Friday draws analogies between the art in engineering and software development. Of course his two Ruby talks where as entertaining as instructive. Ruby is really worth taking a look at...
Day 2.
Herding Racehorses and Racing Sheep by Dave Thomas. He did it again, an excellent non technical people oriented presentation, investigating learning/teaching and knowledge mechanism based on the level of people (from beginner to expert) based on experiences extracted from other professions. (That description doesn't give justice to his presentation :-) The next talk was NakedObjects by Eitan Suez. Model driven UI's...just what I was looking into for Flex. Foolowing was,
AJAX by Justin Gehtland as a presentation going behind the buzzword and showing many of the javascript techniques used to make google-maps and other dynamic websites.
Day 3.
Hibernate and J2EE Transaction Integration by Mark Richards. Mark showed ways to make it work and presented several gotcha's to be aware of. Better to use Hibernate just with Spring if possible. I attended three presentations by Bruce Tate, Beyond Java and Ruby persistence , Introduction to Spring , and Beyond Java . The Spring and Java talks where really interesting and informative, his last talk on Ruby persistence, as Bruce warned us, was the first time he presented it and still a little refinement is needed. Other than that Bruce is an excellent speaker worthwhile listening too...
Reflecting on The conference
First, you should attend one, it's just a great way to learn some of the latest stuff and interact with some off the leaders and experts in the field.
I get really energized when attending these conferences, so much to try out, so many new thoughts, so many new projects I now want to do, but mostly they confirmed a reflection and phase I started a couple of months ago. A "Back to basics" phase. My goals was to stop trying out everything and not finishing really anything. Energy and simplicity are not contradictory. I will just spend more time doing less, and more energy simplyfing what I do. I just read several of the pragmatic series books (automated build, subversion) and have a few more to read (JUnit). Although I use these approaches during my day job, I didn't do it on my midnight projects. Why? Well not 100% sure why, but it would have saved me time and headaches. Most likely I believe that outside of the constraint of work, I used to like to get more creative and less organized, but that is changing and I get a lot of satisfaction trying to do less and more carefully.. So last month I first purged many of my obsolete projects (the WebObjets ones, the older java ones, the Cocoa ones) and one by one decided what I wanted to keep based on what I wanted to achieve...well I ended up with no old projects...and just one new one. Yea, that felt good. Then I moved the rest of my stuff into subversion. After a little issues with French characters in some of my documents I got everything working. Now I can trace back everychange in my source even for my midnight projects. On osx I use SnvX and the merge tool provided by the osx dev tools. Pretty slick!!
So my only new midnight project is integrating Flex and RubyOnRails. I will be working hard at ensuring that it contains the minimal amount of code to achieve the integration, that's it is fully unit tested, and integrated with an automated build tool. During my day job I use cruisecontrol, I am still debating if I will use DamageControl (a Ruby one)...I am currently inclined going the Ruby way.
Well as you see these conferences get me going...

Older posts: 1 ... 4 5 6