Friday, May 23, 2008

Problems and Solutions

Each of the following things has come to bite me in the back side over the past few days...

Ruby / Rails dates:
Since Ruby (and other languages like it) allows you to dynamically add new methods to classes after they are originally defines, AND everything is an object (including numbers) you can do things like these:

6.months
3.weeks.from_now
1.year.ago


which leads to easily read and understood code and is pretty clever. Only one problem .... there is a subtle nuance here that can be easily missed (as was by me the other day) that can lead to trouble (this same problem is inherant to many languages and DB's concept of time/dates) as is demonstrated by the following statements:

60.days == 2.months
60.days.ago != 2.months.ago


Some of you may pick up on the reason why this is true (and false) but given that I haven't worked in Ruby long and the implementation of the .months method apears to define it as self.days *30 lead me to some confusion.

The reason for the difference is a matter of context. Without the context of a particular point in real time, 2.months is really an abstract duration which the developers decided to define as 30 days / month. When you say .ago you are really saying Time.now - XXX which puts it into context of today and now months.ago means take today's day of the month and move the months number back 2. So as was the case the other day, 2.months.ago == 61.days.ago .... thus the problem.
NDoc
Recently I was documenting some C# code and my pair suggested we use a tool called NDoc which he had used in the past to produce nice Windows help files similar to JavaDocs ... great.

Only problem is that NDoc apears to only work with Visual Studio 2k3 and older ... and someone's port for 2005 has a few bugs. The first being that there is evidently a problem with some of the binaries which means you can only use it if you download the source and rebuild (not a big problem). The second was that it doesn't handle dependencies very well and won't know where to look for your referenced .dlls unless you explicitly tell it where to look for them. This wouldn't be too bad if the feature worked ... which it doesn't. Well, it DOES work if you know the special handshake. In this case the hand shake is to change the property saying to use fixe paths from false (default) to true. And then back again (false x2). Then everything magically works. Thank you random comments poster for this insight and thank you NDoc2005 for producing some decent documentation.
Google Maps API
The google maps api requires a key to be accessed, which can be generated for a given URL you want to use it on by their website. Simple enough, but I have had trouble when doing development work on other sites which didn't have the same key. Luckily I stumbled upon this yesterday. It says its the key for localhost and it works so I am not complaining. :)
SVN + Cygwin + SSH + Capistrano
This one was today. While trying to get our Rails app to be deployable via Capistrano, we decided it would be easier to work on it locally before bothering to set it up on one of our dev servers ... oh how we were wrong. Capistrano attempts to SSH to the server you are deploying to and export the latest code for your project with Subversion. One of the commands it tries to execute looks something like this:

svn update -s -r1234 https://svn.xxxxxx.com /www/apps/myproject/20050523042212/ && (echo 1234 /www/apps/myproject/20050523042212/RELEASE

Thats not quite it but its close enough. Basically via an SSH session it tries to export the latest revision to a new time stamped directory (creating it if necessary) and echoing out the version number to a file called RELEASE. Thats all fine and dandy if your server is running a *nix, but if you are trying to test it locally on a windows box and your SSH server is being run via Cygwin .. then your in for a world of hurt.

Basically, the path you passed into SVN ends up having its slashes switched and is mapped relative to the drive root while the other is mapped POSIX style relative to your Cygwin root which unless you went against the big warning box that pops up, is NOT the drive root. Thus it doesn't work.

I don't have a great solution to that one ... it was just a pain and caused me to lose 45 minutes of my life I will never get back. Tuesday we skip the local testing and get it working on the dev box which is Fedora Core.

No comments: