Topic: Windows

Rails DateTime.to_time, Time, and a case of ‘Why do you need to do that?’

balboa_clock

The problem: I needed to display a warning to a user if the data they were looking at was more than 90 days old.

The solution: Create a method that takes 2 dates (either DateTime or Time), and returns the number of days, or hours between them.

  def self.difference_in_dates(date1, date2, unit = 1.day)
    return nil if date1.nil? || date2.nil? || unit == 0
      (( date1.to_time - date2.to_time ) / unit).round.abs
  end

The problem was simple enough, and my tests were all passing, so I moved on to my next task.

That code has been out in production for several months, but earlier this week, a new developer told me he got an error when running the test:

  NoMethodError: undefined method `to_f'
    for Mon, 21 Sep 2009 14:29:38 -0500:DateTime

(we're running this in Rails 2.0.2)

I looked at the code, knowing it was working before, ran the unit tests myself, and didn't see the issue. Now I'm on Windows and everyone else is on a mac, so as soon as I run into an issue that no one else has seen I want to prove if its a Windows problem. But wait, this test has been running in our Continuous Integration server (Hudson) for months, and no one else on the team ever had any issues with it, and the code has been working in production without any errors in the logs.

I jumped into rails script/console to see what's up, and here's what I found:

 >> x = DateTime.now
=> Wed, 23 Sep 2009 00:00:00 +0000
>>; x.to_time
=> Wed Sep 23 00:00:00 UTC 2009
>> x.to_time.to_f
=> 1253664000.0

Which is what I expected, but when I asked the other developer to run that same instruction, he got an error.

>> DateTime.now.to_time.to_f
NoMethodError: undefined method `to_f'
  for Mon, 21 Sep 2009 14:29:38 -0500:DateTime

What's up with that? We're running the same code, and all of our libraries are the same version. Looking at the date value in his error, I saw the timezone, and decided to try this variation locally:

>>  x = DateTime.parse("2009-09-21T14:29:38-0500")
=> Mon, 21 Sep 2009 14:29:38 -0500
>> x.to_time.class
=>; DateTime

So I'm gathering that when there is a timezone and you ask DateTime.to_time, its just going to give you back a DateTime.
Continue reading »

Rails Development on Windows: Native or Virtualize

Vmware_fusion

I have come to the conclusion that doing rails development native in windows is not worth the cost. Things may seem to run smooth initially, but over time problems inevitably come up, and they have become enough of a pain point that i'm moving to a linux virtualization. This for me makes particular sense as most of the full time ruby guys in my shop are using macs and are no help when it comes to figuring out windows only issues.

The first lesson usually learned by rails developers using windows is to use cygwin.  I didn't initially, until i need to use capistrano for deployment, and guess what, windows doesn't support ssh from the command line, so time for a second rails installation using cygwin for this support. In general, dealing with any type of issue is more frustrating when using windows because most help on the web is not windows focused. A common disclaimer seen when searching boards for help with RoR issues on windows is, "Well, I'm not that familiar with installing xxx on Windows, but" . It's just going to be much easier to install, say gems for instance, if you can build them in the environment for which they were developed.  In fact, awkward native gem compatibility it probably the single biggest reason not to stay on windows.

Then there are issues that don't have to do with trying to fix something that's broken. Performance for one. As seen here, certain tasks on windows are much slower than if virtualized, even if the virtualization has inferior resources.  Also, developing on windows makes for a poor example when it comes to deployment and dealing with production issues as Rails apps are rarely run on windows.  If you're not used to a linux OS, you're going to be completely useless when it comes to working on these machines.

What it boils down to is that Rails and everything around Rails is targeted towards linux. The web services, heavy use of git, the framework itself.  Sure, becoming familiar with Linux with have its own set of frustrations and headaches, but those will be useful lessons that will bring you closer to Rails and its community, rather than farther away.  So until i get my mac and can virtualize my windows enviroment (um, hello Dietrich),  rails is going virtual.

Related Services: Ruby on Rails Development, Custom Software Development

Windows Development on a Mac

app_win1

I've been in just about the same cycle for almost 15 years now. Install Windows. Install the software I need on top of it. Wait about 6 months to a year until I can no longer take the gunk slowing down my system ("Windows Disease"). Backup my data. Format my drive. Rinse and repeat. Do this maybe 3 or 4 times, and then upgrade my hardware. Sound familiar?

So I got smarter. I started making images using Ghost. This has worked fairly well. I get a new system, I set it up as pristine and fully featured as possible, then I take an image of it. This way the install step takes a couple button presses, leaving me to do more useful things with my time. Like blog or something.

Fast forward a couple years. Processors are way faster and have more cores. Virtualization is no longer a toy, and can now be used not just for enterprise purposes, but on the desktop. Sure I'm mostly a Windows developer, but that doesn't mean I don't want to write iPhone / Mac applications. So after cursing my previous laptop up and down on a daily basis, I've upgraded to a MacBook Pro. It's tiny, it's fast, and it runs OS X and WINDOWS via VMWare Fusion. Windows runs spectacularly on my MacBook. The most beautiful part is, as far as I can tell, there is no parallel (no pun intended) to "Windows Disease" on a Mac. It has continued to run as fresh and fast as the day I installed the OS. Now with my backed up copy of my Windows virtual machine, starting from scratch on Windows is as simple as taking a fresh copy and spinning up the backup VM.

Topics: , , , ,

5 things I can do with my windows mobile phone that you can’t do with your iPhone

samsung_blackjack2
After playing with my friend's iPhone for awhile, and using the company phone for testing out our iPhone applications, I started to get really jealous of how cool it is, and how uncool my samsung windows mobile phone seems by comparison.
The more I used the iPhone, the more I got upset at my windows phone and started demanding "Why can't I do this on my phone?", and the more I found that there were apps out there that I didn't even know existed, as one of big problems with the windows platform is that its not easy to find good apps.
So here's my take on how to make your windows phone better, and what it can do for now that the iPhone can't do.

Continue reading »

Ruby on Rails with Windows – How I made it work

I have been developing with Ruby on Rails over the last few weeks. Coming from the ASP .NET/C#/VB world, I am a total stranger to a programming language like Ruby. Any new programming language is fun to learn! Ruby was even more exciting cause it was a new kinda language to me. Though I think Ruby is not as user-friendly as C# or Java, it is as powerful and flexible if not better. Combined with Rails, Ruby becomes a platform that facilitates quick and efficient development of database-driven web applications.

Continue reading »

Topics: , , ,

Using Adobe Flex Builder 3 on a Mac

I've made a recent switch from Windows (Vista) to Mac (OS X 10.5.4). In these two months I had enough time to evaluate all biases that I was carrying with me for the past decade, including the one about coding on a Mac.

+ = :-)
Continue reading »

Topics: , ,

Launch: Pathfinder Newsletter

    Get a monthly update on best practices for delivering successful software.

    Subscribe via email


    Subscribe via RSS      RSS icon

Topics

Search

WordPress

Comments about this site: info@pathf.com