Friday, June 29, 2007
In reading blogs today I was extremely disappointed that I couldn't find any mention of new phones that are coming out soon.  In fact this entire week I haven't seen any mention of anything phone related.  What's a guy like me supposed to do? I need a new phone and nobody is talking about phones.  Whats the deal?

Friday, June 29, 2007 4:42:43 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Thursday, June 28, 2007
As Aaron mentions, one of our colleagues recently posted a "brain teaser" on the whiteboard at work.

A/BC + D/EF + G/HI = 1

All variables are unique digits from 1 - 9. Two variables next to each other is equivalent to 10 * var1 + var2. For example, if B = 2, C = 5 then the result is 10 * 2 + 5 which equals 25.

Since my language of this year is Ruby, I figured out the answer with the code below.  I had some of the code sketched out in my head, but I wrote it after seeing Aaron's post last night, so the way I went about implementing it pretty much matched the approach Aaron took.   I should also mention that I'm a Ruby newbie so there might be better ways to go about writing the below code.  If so, I'd love to here them since I'm still learning what idiomatic Ruby is :)

#!/usr/bin/env ruby
class FigureItOuter
  def run
    set = generate_set
    while (calculate(set)) != 1
      set = generate_set
    end
    puts format("%d/%d%d + %d/%d%d + %d/%d%d = 1", set[0], set[1], set[2], set[3], set[4], set[5], set[6], set[7],set[8])
  end 
 
  private
  def calculate(s)
    (s[0] / (10 * s[1] + s[2])) + (s[3] / (10 * s[4] + s[5])) + (s[6] / (10 * s[7] + s[8]))
  end
 
  def generate_set
    s = []
    while s.size != 9
      n = rand(9) + 1
      s <<  n.to_f unless s.include?(n)
    end
    s
  end
end

# a/bc + d/ef + g/hi = 1
f = FigureItOuter.new
f.run


Thursday, June 28, 2007 10:59:49 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Wednesday, June 20, 2007
I'm in the process of deploying a Rails app, and up until a few minutes ago I was having problems getting acts_as_attachement and attachment_fu to work.  I originally started development with acts_as_attachement since I was naive and didn't know there was something better.  After looking for a fix for the issue I was seeing, I came across attachment_fu and came to see that it was superior and would undoubtedly solve my issue.  It didn't....however, the upgrade process was painless and I got some extra goodies so all was good.  For those interested, the extra goodies include pluggable image processors (RMagick, MiniMagick, and ImageScience) as well as an option to store files with Amazon S3.

With attachment_fu installed, I was sure my problem would be resolved.  I suspected the issue I was having was related to RMagick image resizing since I'm deploying to a shared hosting account on TextDrive, and RMagick has quite a reputation for hogging up lots of memory and causing havoc on shared accounts.  After switching over to attachment_fu and to MiniMagick as my image processor I was still seeing my issue, so I realized it had to be something else.

Before going onto the solution, let me explain the problem that was occuring.  When I was submitting a form for an attachment_fu model I was immediately being redirected back to the index page.  Every once in a while the form would appear to be submitting, hang, and eventually hose the lighttpd process.  As I mentioned above, I first suspected the problem was related to image resizing being done by RMagick but I was able to reproduce the problem on a non image attachment_fu model object.  After digging around on the web and coming up empty, I ended up checking out the Rails log file to see if I could figure out what was going on.  Examining the production.log showed that I was going from the :new action, directly to the :index action.  Since I was submitting a form, I should have seen a hit on the :create action for my controller.  This led me to search google for a slightly better phrase which eventually landed me at this "Form doesn't trigger create in production" forum post, as well as this related post on Ruby Forum.

It turns out the problem is due to the way that attachment_fu stores the files uploaded on the file system.  attachment_fu stores the files in a folder with the same name as the model within the public folder.  This causes issues since the url for the controller, as well as the directory for storing files have the same URL.  Fortunately the fix is as simple as adding the following to your application.rb file.
def default_url_options(options)
{ :trailing_slash => true }
end

Deployment is such fun, isn't it! :)


 |  | 
Thursday, June 21, 2007 2:03:58 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Thursday, June 14, 2007
Over the last couple days a number of people on our team have been investigating why an operation marked as one way on one of our WCF services ends up blocking when it's called.  We looked at a number of things with our setup including:
  • Making sure our operation did in fact have IsOneWay=true defined
  • Ensuring none of the behaviors we have setup for exception sheilding and authorization were cuasing the call to block
  • Ensuring that it wasn't something within our client by creating a console app to replicate the problem
  • Validating the configuration on both the client and service side where both correct
  • and more...
Yesterday afternoon Sam and I began to dig into the problem a little deeper by turning on tracing and message logging for our services.  After spending a bit of time tracing through the logs with SvcTraceViewer we eventually spotted something in the client side log that didn't look right.  The entry looked something like this:

Close Secure Session       10s

What was mysterious about this line was that in order to replicate and debug the problem we had a service that looked like this:

[OperationContract(IsOneWay=true)]
public void MyOneWayOperation(ItemRequest request) {
    Thread.Sleep(10000);
}

So it appeared that the Close on channel was actually blocking until our one way operation completed.  We weren't totally convinced that this could really be the case, so we changed our operation like so:

[OperationContract(IsOneWay=true)]
public void MyOneWayOperation(ItemRequest request) {
    Thread.Sleep(20000);
}

which resulted in the following line in our log:

Close Secure Session       20s

This convinced both of us that it was defintely blocking when closing down the client proxy.  At one point in the past we had run one way messages and not seen this behavior though, so what had changed to all the sudden cause our operation with IsOneWay=true set to block?  It turns out that the "problem" was due to a change in the way we used the client proxies.  Previously we had code that looked like this:

MyServiceClient client = RetrieveClientProxy();
client.MyOneWayOperation(new ItemRequest("KLDF992"));

But due to some problems that we've had with secure sessions timing out, and other inconsisitencies we changed our code to:

using(MyServiceClient client = new MyServiceClient()) {
  client.MyOneWayOperation(new ItemRequest("KLDF992"));
} // FYI, Dispose on a ClientBase calls Close

Instead of re-using our client proxies we're now recreating our client proxy every time an operation is called.  This results in our performance not being as great as it could be since the client has to re-establish it's security context on every call, but, it's also resulted in our services being a lot more reliable.  We'd rather have things run slightly slower than have them not work. 

I still don't understand why closing the client proxy would block when calling a one way operation.  Since a one way operation immediately returns a 202 letting the client know that it was received I'm unsure of why the proxy needs to wait around for the operation to finish when you call Close on it.  It seems to defeat the whole purpose/nature of a one way operation.  I've explicitly said that I don't care about the return value so I don't see why it can't just close when I tell it to. 

 |  | 
Thursday, June 14, 2007 1:44:44 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [6]  |  Trackback
This post from John Lam has prompted me to download the latest beta of VMWare Fusion.  I've had a love hate relationship with Parallels ever since I installed it.  Back when I first got my MacBook Pro I was using BootCamp to run Windows, however, I found I often wanted to switch back and forth between OS X and Windows and rebooting took way too long.  When I heard about Parallels, I was instantly interested and proceeded to download the beta.  After using it for a while I decided to go ahead and purchase it.  Since Parallels supposedly supported booting from a BootCamp partition my plan was to continue using BootCamp so I could go directly into Windows and use it without suffering from the cost of virtualization, but also be able to run it from within OS X for those times when I wanted to use apps from both OS X and Windows at the same time.  Well Parallels ended up completely hosing my BootCamp setup so I needed to start fresh with a new image that wasn't based of BootCamp.  Ever since making this change I've been frustrated when trying to get things done in VS.NET (which is more of less the only Windows app I use anymore at home).  So, I'll be downloading VMWare Fusion in hopes that it resolves many of the issues that I have with Parallels.  It might mean shelling out a little extra cash but considering the "upgrade" for existing Parallels customers is $50 for version 3 it won't be that much of a difference.  I'll let you know how it goes. :)

 | 
Thursday, June 14, 2007 1:27:42 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Tuesday, June 12, 2007
Brian has a interesting post about his discovery of the new EXCEPT set operator in SQL Server 2005.  When I read his post I was at first excited, but then disappointed.  You see, the EXCEPT set operator could potentially save us from updating or inserting a large number of records in the data imports that our system runs.  Unfortunatly, we currently support BOTH Oracle and SQL Server so this new and exciting SQL Server 2005 feature wouldn't help us with many of our clients (since they're primarily on Oracle).  However, after a little bit of Googling I came across the MINUS operator in Oracle, which appears to be the equivalent of the SQL Server 2005 EXCEPT operator.  I'll have to dig into things a little more to know if the EXCEPT and MINUS set operators are equivalent, as well as run some tests to see what kind of impact it could have on our data imports, but it looks promising.

 | 
Wednesday, June 13, 2007 3:47:02 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
The validation infrastructure within Rails is another one of the niceties that it provides.  By decorating model classes with validation helpers you can quickly define a pretty thorough set of validations for a model.  As an example of the types of validations that can be added to Rails models lets take a look at a user model created by the acts_as_authenticated Rails plugin.

class User < ActiveRecord::Base
  # Virtual attribute for the unencrypted password
  attr_accessor :password

  validates_presence_of     :login, :email
  validates_presence_of     :password,                   :if => :password_required?
  validates_presence_of     :password_confirmation,      :if => :password_required?
  validates_length_of         :password, :within => 4..40, :if => :password_required?
  validates_confirmation_of :password,                   :if => :password_required?
  validates_length_of       :login,    :within => 3..40
  validates_length_of       :email,    :within => 3..100
  validates_uniqueness_of   :login, :email, :case_sensitive => false

  #other stuff
end

By using validates_presence_of, validates_length_of, validates_confirmation_of, and validates_uniqueness_of we're able to put together a detailed set of validation rules for our User model.  Additionally, we can enable and disable certain validations by defining an :if parameter on our validations.  With all these things in place Rails provides a nice default set of functionality for ensuring the validity of models.  One of the things that's been on my mind since I started working with some of these validations is how they might scale, and how well they'd support a model object with complex validation rules.  While it seems as though what's provided out of the box by Rails could be bent in order to meet most requirements I came across something today that looks very promising.

The ActiveSpec project aims to provide domain driven design (DDD) style specificiations to the Ruby world.  While Rails is getting all the attention, ActiveSharp isn't limiting itself to Rails, but instead makes itself available to all of Ruby.  On my train ride home tonight I read through the Introduction to ActiveSpec and was pretty excited about the direction it's headed.  It's pretty early in the game so the current bits may not be ready for prime time, however, that doesn't make them any less promising.  In addition to providing the ability to create simple specifications, composite specifications, ActiveSpec also provides a base ActiveSpec class with macros to help make the process of creating complex specifications more straight-forward.  I've included some sample code snippets below, but to get a full run down of ActiveSpec checkout the Introduction.
# Composite Specifications
spec = CompositeSpecification.new
spec.add_specification(SizeSpecification.new(6, :username))
spec.add_specification(CollectionSpecification.new(18..30, :age))
spec.add_specification(ConfirmationSpecification.new(:password))
spec.satisfied_by?(User.new)
#=> false


# Custom Specification Class
class UserSpecification < ActiveSpec::Base
requires_presence_of :username, :password
requires_size 6, :password
requires_confirmation_of :password
requires_inclusion_in 18..30, :age
end

UserSpecification.satisfied_by?(some_user)

# pure ruby selection
User.find_by_specification(SomeAdvancedUserSpecification)

# specifications for SQL queries?
User.find(:all, :conditions => SomeAdvancedUserSpecification.to_sql)
 | 
Wednesday, June 13, 2007 3:18:44 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
I must say I'm growing more fond of Rails the more I use it. It seems like it was actually designed by someone writing real applications for a living, and designed to make the common things that we have to do in most applications straightforward and easy.  Tonight I needed to add some logic to send out emails so I read through the ActionMailer chapter in Agile Web Development with Rails.  For those interested, sending out emails in Rails requires that a mailer class be created that inherits from ActionMailer.  The easiest way to do this is to run the mailer generator like so:

script/generate mailer OrderEmail confirm_order

The generator creates a mailer object in the models folder of your Rails application that looks like so:

class OrderEmailer < ActionMailer::Base
  def confirm_order(sent_at = Time.now)
    @subject    = 'OrderEmailer#confirm_order'
    @body       = {}
    @recipients = ''
    @from       = ''
    @sent_on    = sent_at
    @headers    = {}
  end
end

Which we may modify to have the necessary settings, and accept the necessary order parameter like so:

class OrderEmailer < ActionMailer::Base
  def confirm_order(order)
    @subject    = 'Thank you for your Order'
    @body       = {:order => order}
    @recipients = order.customer.email
    @from       = 'steve@sellscoolstuff.com'
    @sent_on    = Time.now
    @headers    = {}
  end
end

The generator also creates a rhtml template for the email in the views/order_mailer folder that can be used to construct the email message.  To send the email is simply a matter of calling the deliver_confirm_order method on OrderMailer.  Take notice that we call deliver_confirm_order and not just confirm_order.  Rails supports either sending emails out by using the deliver_ prefix, or allows the emails to be created by prefixing the mailer method with create_. What's really nice is that the Mailer uses a rhtml template within the views directory for the mailer (views/order_mailer in the example above) to generate the email.  This allows you to create emails using the same mechanisms used to create dynamic pages within Rails.  Plain text emails can be created, or the mailer methods and views can be updated to pass along parameters, which we do above with the order parameter.  The only difference between a mailer template and a template for a controller is that the mailer view is being used to create a text email rather than an HTML page that will be rendered to the browser.

With my mailer in place I had everything I needed to send out the necessary emails.  There was only one problem, on my MacBook Pro the emails I was generating weren't sending.  Luckily I was able to find this page on how to get OS X setup to send emails via SMTP.  After following these steps I updated my /config/environments/development.rb file to have the following settings for ActionMailer and all was good!

config.action_mailer.server_settings = {
  :address => "127.0.0.1",
  :port => 25
}

 | 
Wednesday, June 13, 2007 2:38:32 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Saturday, June 09, 2007
As I stated a couple days ago, I was planning on learning MonoRail for a very small project that I'm working on.  Due to various circumstances, I'm not going to be using MonoRail, and will instead be learning a little more Ruby on Rails.  The primary issue is that I've been having a lot of problems as well as frustrations with Parallels lately.  The  biggest frustration is that I can't seem to get going within VS.NET due to OS X having all my common keyboard shortcuts mapped to other things.  I know I could remap them, but when I'm in OS X I want them to be mapped to the things they're supposed to.  The other issue is that VS.NET is repeatedly hanging, left and right.  I'm not sure if its a Parallels issue, or a problem with having both Orcas and VS 2005 installed or something else.  What I do know is that it makes trying to get anything done very difficult.  The final issue, which may be much more my own fault than anyone elses, is that getting going with Castle proved to take longer than I anticipated.  My primary issue was in trying to get everything built from the trunk with the VS.NET wizards and such setup.  I'm still getting a compile error that's related to AL.exe which may be related to having Orcas installed side by side with 2005.

Anyway, I've decided to go with Ruby on Rails instead.  Below are some things that I think are going to be of value:
By the time this project is over I should have a pretty good overall feel for Rails, and will be posting my thoughts on it in comparison to my primary development platform (.NET/C#). I'm going to continue to look into getting everything going with Castle and MonoRail as well, since my initial reactions to it after going through some of the getting started material and documentation was very positive.

Regarding the Parallels issue, I think I'm going to clean things up in my virtual machine, copy them over to someplace safe on the network and go back to using BootCamp.  While Coherence and such is nice, I simply can't be productive when running the applications that are important to me (VS.NET) within Parallels.  Since Parallels supports BootCamp, perhaps I'll still use Parallels from time to time to quickly switch between XP and OS X, but for the most part I think I'll be ditching Parallels.  Heck, maybe I'll just give up Windows all together, and become a Rails developer. :)

 |  | 
Sunday, June 10, 2007 12:57:39 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [9]  |  Trackback
 Thursday, June 07, 2007
Tonight I found out the hard way that prior to version 5, MySQL don't support using an aggregate in an ORDER BY clause.  Unfortunetly my web host is currently on 4.1.21-standard of MySQL while my development machine is running 5.0.27-standard.  The end result is that some pages within the Rails app that I'm working on are not working so well on my staging box at Site5 :(

I tried to find details online about when ordering by aggregates was added, however, I didn't have any luck so all I know is that it works in the version on my dev machine, but not on the version that my web host is running.

Update: For those interested the work around is to include the aggregate in the select list with an alias, and then order by the alias.  So instead of including the aggregate in the order by like so:

SELECT Column1, Column2, etc FROM MyTable LEFT OUTER JOIN MyJoinedTable on MyTable.Id = MyJoinedTable.OtherId ORDER BY COUNT(*)

You instead need to do something along the lines of:

SELECT Column1, Column2, etc, COUNT(*) Cnt FROM MyTable LEFT OUTER JOIN MyJoinedTable on MyTable.Id = MyJoinedTable.OtherId ORDER BY Cnt

And yes, I know the SQL here is completely contrived and might not be showing why the order by count is needed but that's not the point.  And for those wondering, as far as I can tell Rails doesn't exactly make it easy for  me to do what I need to do.  I can write all the SQL myself, but I was using find along with an :include to pull in an association, which means the necessary SQL isn't something I want to write if I don't have to.



 |  |  | 
Friday, June 08, 2007 1:59:56 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, June 04, 2007
Although I'm not finished the application that I'm building with Ruby on Rails, I've decided that next up on my plate for new'ish technology is MonoRail.  Afterall, all the cool kids who aren't quite cool enough to be doing Rails seem to be going crazy for MonoRail.  As a former web guy I've done a lot of WebForms development, so its time that I see what all the hype is surrounding MonoRail.  I was originally going to build the business/data layer with LINQ to SQL, but I think I'm instead going to go all Castle and use ActiveRecord along with Ayende's NHibernate Query Generator

Unfortunately, I'm not smart enough to be able to figure out how the heck to get the MonoRail project templates to show up in VS.NET.  I'm guessing they're not necessary, but for a MonoRail newbie they seem like they'd be useful.  I'm planning on building things from the trunk, as such I tried following these instructions on Using the Trunk.  Can anyone offer any advice on how I might get the project templates working?  Should I give up and just go with the very old MSI that's available?

UPDATE: It helps if you actually read the documentation.  Running the RC2 installer and then following the necessary steps in Using the Trunk worked perfectly.

 |  | 
Tuesday, June 05, 2007 2:59:02 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Friday, June 01, 2007
Matt Warren, who has been one of the lead developers on many aspects of LINQ, recently posted two very interesting stories describing The Origins of LINQ to SQL, and IQueryable's Deep Dark Secret.  In his first post on the Origins of LINQ to SQL, Matt talks about some of the previous dead projects, such as ObjectSpaces and WinFS, that influenced LINQ to SQL.  I found it interesting to hear about how LINQ to SQL came to be, and some of the internal politics that had to be overcome to make it a reality.  In his second post, IQueryable's Deep Dark Secret, Matt talks about how a call from Don Box eventually led to what is now at the core of LINQ, IQueryable.

Saturday, June 02, 2007 12:38:52 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
I've thought several times about trying to learn the basics required to build an OS X application.  In the past, this meant either going with Java or Objective-C, neither of which I have much experience with.  I've heard a couple people mention RubyCocoa in the last couple of months, but I never looked into it to see what it was all about.  Thanks to Peter Cooper, of Ruby Insider, I've been enlightened and now know that RubyCocoa's goal is to allow OS X applications to be built with Ruby, which in hindsight shouldn't have been very hard to figure out. Although I don't have the time at the moment, I'm certainly going to add a "checkout RubyCocoa" task to my "stack". 

Peter offers the following links:

Friday, June 01, 2007 10:21:19 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback