Saturday, June 28, 2008
For the last week Twitter has been mostly unusable.  While it's been possible to "tweet" it hasn't been possible to view replies, and now you can't see "older" posts.  While twitter hasn't become a staple in my life yet, I can see with some recent changes in my life me relying on it, or something similar, for communicating with others.  Twitter has proven time and time again that it isn't up to the challenge of being a service that we can rely on for much of anything.  I've given some other services a try to see what might be able to take the place of twitter, and I'm starting to form an opinion on what I think may be our best path forward.

I've developed a 6 step plan for removing twitter from our lives.

Step 1: Sign up for friendfeed, and add all the online services you use to your account
Step 2: Sign up for tumblr (or some other microblogging service) where you can post the things you normally post to twitter.  Another option would be to just use the "share something" feature of friendfeed for what you normally use twitter for.
Step 3: Take advantage of all the other services friendfeed supports and use those services for what they're good at.  For links use delicious or magnolia, for photos use flickr or smugmug, in short use the services that you like the most and use friendfeed as the central hub where you can view everything you and your friends are doing online.   
Step 4: Use friendfeed for viewing your "friends" activity stream, and allow it to become the central place that you communicate with your "friends".
Step 5: If you've become reliant on desktop client for interacting with twitter, download twirl or AlertThingy and set it up with your friendfeed account.
Step 6: Enjoy life without twitter

Sound good?

 | 
Saturday, June 28, 2008 5:29:38 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, May 23, 2008
I have a small fantasy football related project that I'm going to be working on that requires access to the full 2008 NFL Schedule.  I decided to use Hpricot, and scrape the schedule from ESPN.  The CSV file I created with the output from the below script can be found here: nfl-schedule.csv (11.48 KB)  

Download script (parse_schedule.rb)

#!ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'

class Game
   attr_accessor :date, :week, :away_team, :home_team, :time

   def to_s
      "#{@date} #{@time} #{@away_team} at #{@home_team}"
   end

   def to_csv
      "#{@week},#{@date.gsub(",", "")},#{@time},#{@away_team},#{@home_team}"
   end
end

def parse_games(doc)
   games = []
   doc.search("//table[@class='tablehead']//tr").each do |tr|
      @week = tr.search("/td/a").inner_html if(tr[:class] == 'stathead')
      @date = tr.at("td").inner_html if(tr[:class] == 'colhead')

      teams = []
      tr.at("td").search("a").each do |team|
         teams << team.inner_html
      end

      if(teams.size == 2)
         @time = tr.search("td:eq(1)").inner_html
         game = Game.new()
         game.date = @date
         game.week = @week
         game.time = @time
         game.away_team = teams[0]
         game.home_team = teams[1]
         games << game
      end
   end
   games
end

games = parse_games(Hpricot(open("http://sports.espn.go.com/nfl/schedule")))
games.each do |g|
   puts g.to_csv
end
puts "Total games: #{games.size}"
Saturday, May 24, 2008 12:35:58 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Monday, May 19, 2008
Have you ever been shamboozled by the WinForms designer in Visual Studio?  If you haven't, its likely only because you've never used it.  Over the last several years I've had many wars with the WinForms designer, and unfortunately I've lost every single time. 

Not long ago as I was exploring a couple interesting open source ruby projects, I came across one that had me longing for something as simple in the .NET world.  The project was shoes, done by none other then why the lucky stiff.  For those unfamiliar with shoes, it's website describes it as:
Shoes is a very informal graphics and windowing toolkit. It's for making regular old apps that run on Windows, Mac OS X and Linux. It's a blend of my favorite things from the Web, some Ruby style, and a sprinkling of cross-platform widgets.
To give you an idea of how simple shoes makes creating the simplest of GUI's checkout the following code:
Shoes.app {
button("Press Me") { alert("You pressed me") }
}
To give you a little more background, shoes uses a ruby "dsl" for describing the layout of desktop GUI, and under the covers is implemented in C.  Although I wasn't sure how far I could get, I decided to "implement" shoes using IronRuby for my philly code camp presentation.  My goal was to keep the same ruby syntax for declaring the layout and controls that make up the screen,  however, instead of using the backend implementation of shoes I wanted to write my own implementation in IronRuby by leveraging the interop capabilities between IronRuby and Windows Forms.  After hacking on it for a few hours a couple nights last week, as well as doing a little more this past weekend I've been able to get enough of shoes replicated in IronRuby to create some reasonable apps.  Let's start with a simple "Hello Iron Shoes" example. 
require "shoes"
Shoes.app :width => 450, :height => 400, :title => "Hello!" do
banner "Hello Iron Shoes"
end

We start with a require statement that includes the shoes.rb file that implements the shoes "dsl".  Every shoes app starts with a call to Shoes.app that takes a hash of options.  In this example we specify the width and height of the form as well as a title.  We then pass a block that contains a simple banner "Hello Iron Shoes" statement.  Within shoes, all layout and nesting is done via Ruby blocks.  So everything within the do...end block of Shoes.app is added as content to the form.  When we run the above using IronRuby we get the following result.

What's you might find particularly interesting is that since Mono just recently completed their implementation of Windows Forms, and since IronRuby is open source we get the same cross platform support from our IronRuby implementation as we get with the real shoes.  We can also add a bit of user interaction by using an edit_line and button like so:

require "shoes"
Shoes.app :width => 200, :height => 200, :title => "Hello!" do
@input = edit_line
button("Say Hello") { alert("Hello #{@input.text}")}
end


Finally to see some of the other controls that are supported checkout this very beautifully designed form:

The code for this beauty is as follows:
require "shoes"
Shoes.app :width => 800, :height => 600, :title => "IronShoes everything sample" do
flow :width => 800, :height => 600 do
stack :width => 300, :height => 600 do
link "CLICK ME" do; alert "HEY"; end
link "GOOGLE", :click => "http://google.com"
image "shoes-logo.png", :click => "http://code.whytheluckystiff.net/shoes/"
@e = edit_line
banner "Hello Iron Shoes"
para "This is shoes...", strong("and another"), em("and a final one")
button "Foo" do
alert("Hello Foo")
end
button "Bar" do
alert("Hello Bar")
end
button "Get Textbox Value" do
alert(@e.text)
end
edit_box :width => 200, :height => 100
end
    stack :width => 400, :height => 600 do
  banner "Banner"
title "Title"
subtitle "Subtitle"
tagline "Tagline"
caption "Caption"
para "This is some more text"
image "rails.png"
para "Jimmy kissed", strong("Margaret"),
"and I've saved a picture somewhere on",
link("Flickr", :click => "http://flickr.com")
end
end
end

To checkout the code for my IronRuby implementation of shoes you can download the zip file containing my demos from my Code Camp presentation.

Overall, the experience of creating a basic implementation of shoes with IronRuby was very enjoyable.  While I did run into some problems, for the most part things went very smoothly.  I created a basic calculator, a very ugly friendfeed client (since twitter was down), as well as the other basic examples shown here. 

There is still a lot of API's available within shoes I'm not handling, as well as many things I'm not handling as well as I could so I'll likely continue to hack around on it a bit.  WPF and Silverlight support would be nice (and very doable) as well!

Tuesday, May 20, 2008 1:24:59 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
This past weekend I got a chance to present on IronRuby at the Philly Code Camp.  I had a really great time preparing and giving this talk, despite more then a few hiccups along the way (keynote trouble and computer crash!).  After getting to talk to a few people afterwards it seems it was well received despite my stumblings.

My primary goal for the presentation was to encourage those in the audience who don't know Ruby to learn it.  I think Ruby is a great programming language that has a ton of really compelling use cases.  Additionally, I think the process of learning Ruby is extremely beneficial and can change the way you think about and write software.

I'm very excited about where the IronRuby project is, and even more so about where it's headed.  The team is making great strides and getting really close to a couple milestones that will be very exciting.  We really need to get as many individuals within the .NET community involved in the IronRuby project as possible so we can have a kick ass implementation of Ruby that runs on the CLR!

I've attached my slides to this post, but be forewarned that they're not all that useful standalone.  I've also attached my sample code/demos.  I had the most fun putting together my "shoes" sample which I'm going to write a follow up post on shortly I've written about in my Creating Cross platform GUI's with IronRuby post.

Slides
Sample Code

Tuesday, May 20, 2008 12:52:26 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Thursday, May 08, 2008
In preparation for my upcoming Code Camp session on IronRuby I've been hacking around on the IronRuby source, as well as on Ruby programs that can run on IronRuby.  One of the core areas of interest for me concerning IronRuby is in writing specifications for my .NET applications using Ruby.  While I've been learning Ruby (the real kind) I've become very fond of the testing libraries they have available, most notably RSpec and mocha

Over the last two nights I've been writing some ruby code to test .NET classes written in C#.  With a few of the hacks I have locally, I've had some pretty good success.  The following set of specifications verify the behavior of an Account class I've written.

require "../../trunk/tests/ironruby/Util/simple_test.rb"
require "IronRubySamples"
include IronRubySamples

describe "Account" do
    describe "When depositing money into my account" do
        it "should increase my balance by the amount deposited" do
            account = Account.new(10)
            account.Deposit(10)
            account.Balance.should == 20
        end
    end
                               
    describe "When withdrawing money from my account" do
        it "should decrease my balance by the amount withdrawn" do
            account = Account.new(100)
            account.Withdraw(50)
            account.Balance.should == 50
        end
    end
                   
    describe "When withdrawing money from an account with insufficient funds" do
        it "should tell me I have insufficient funds" do
            account = Account.new(30)
            should_raise(InsufficentFundsException) { account.Withdraw(50) }
        end
    end
   
    describe "When making a withdraw that drops my balance below the minimum" do
        it "should reduce my account by the amount withdrawn + the low funds charge amount" do
            account = Account.new(55)
            account.Withdraw(50)
            account.Balance.should == 4
        end
    end
end

The next step in my quest to test .NET code with IronRuby required me to figure out how to mock out dependent objects.  I considered several different options.  My first thought was to try and use "simple mock", however, I quickly realized via Scott Bellware that while it worked well on IronRuby libraries it wouldn't fit my needs.  My next thought was to give Moq a try.  After downloading Moq, I attempted to run a spec that referenced Moq and created a Mock<T> instance as shown below:

require "../../trunk/tests/ironruby/Util/simple_test.rb"
require "IronRubySamples"
require "Moq"
include Moq
include IronRubySamples

describe "LoginController" do
    describe "When a user logs in" do
        it "should vallidate credentials with login service" do
            mock = Mock.of(ILoginService).new
            #do expects
           
            controller = LoginController.new(mock.Object)
            controller.Login("steve", "****")
        end
    end
end

When running this via ir.exe I got an error that "Moq.Mock is not a generic type".  After poking around a bit I discovered this was due to a bug in IronRuby.  Currently IronRuby has problems when there is a generic and non generic type of the same name within a referenced assembly.  In order to work around this, I first tried to figure out what needed to be modified in IronRuby, however, that wasn't very fruitful so I decided to modify the source for Moq to get around my problem.  After renaming the static Mock class in Moq to MockRetriever, and hacking around another bug in IronRuby related to creating generic types where the type argument is an interface, I was finally able to get IronRuby to create the Mock<ILoginService> type:

mock = Mock.of(ILoginService).new

Unfortunately, this led to me to another roadblock.  When setting up expectations in Moq you do so with lambda expressions such as:

// C#
var mock = new Mock<ILoginService>();
mock.Expect(s => s.Login("steve", "****"));

While IronRuby has blocks and lambda's it doesn't have a way to express the above (at least that I know).  I'm going to dig around in the IronRuby source a bit to see if any ideas pop into my head, but at this point I'm not very hopeful. 

 |  | 
Friday, May 09, 2008 1:09:46 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Sunday, April 20, 2008
As I continue on my quest to get more information about IronRuby, I figured it was worth figuring out what needs to happen in order to contribute code back into the project.  The source code for IronRuby is synced with RubyForge every so often, and patches to the source code can be submitted on the RubyForge project here.  Before making any contributions to IronRuby a contributor agreement must be electronically signed.  John Lam's post to the IronRuby mailing list can be found here, and the actual agreement is available at: http://www.ironruby.net/contributor.pdf

The agreement appears to be pretty staight forward, the main point worth attention is that you grant Microsoft all rights to the contribution.
For good and valuable consideration (including without limitation the opportunity to contribute to the Project), receipt and sufficiency of which is hereby acknowledged, Assignor hereby assigns and agrees to assign to Microsoft its entire right, title,
and interest (including all intellectual property rights) in the Contributions.

Microsoft then licenses the contribution back to you to do with it as you wish.
Microsoft grants You a non-exclusive license under the rights assigned to Microsoft in Section 3 to use, reproduce, modify, license or otherwise distribute, and exploit the Contribution as You see fit.

If you're interested in contributing you need to send an email to ssiadmin at microsoft.com requesting to be added as a contributor to the IronRuby project.  I sent an email this morning so I'm not sure what happens next, but I'm assuming the electronic signing of the contributor agreement will be the next step.

Sunday, April 20, 2008 12:31:37 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, April 19, 2008
I've been digging around IronRuby a bit lately, checking out the source, the specs, and writing very minimal code into rbx to see if it works as expected.  Over the next couple weeks I'm going to try and dig a little deeper into IronRuby in an attempt to get a better feel for where it is, what I might be able to use it for, as well as to experiment with some ideas I've had over the last couple months. 

When I first downloaded IronRuby I did so on my Mac in hopes that I'd be able to cruise around the source in TextMate, compile with Mono, and avoid having to fire up a VM whenever I wanted to experiment.  My initial attempts, albiet not very focused, were a failure.  Fortunately within the last week or two I came across Seo Sanghyeon's IronRuby on Mono How to.

The first step is to download and install Mono 1.9.  Once you have Mono installed you need checkout the IronRuby source from RubyForge and then download and apply this patch that Seo created.  Finally run: rake compile mono=1 and assuming everything goes well you'll be greeted with another command prompt which you can use to fire up rbx (aka IronRuby's irb) and begin experimenting.
svn co http://ironruby.rubyforge.org/svn/trunk ironruby
cd ironruby
patch -p0 < patch-mono-r93
rake compile mono=1
mono build/mono_debug/rbx.exe

Saturday, April 19, 2008 1:56:03 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback