james kahn's scratchpad

a blog on technology

Rails 3: Wrong Timezone in Text Field?

I came across this issue today in a Rails apps I am writing. It took me a while to figure out so hopefully this post will save someone else a bit of time. My dev environment is Rails 3.1.3 using Ruby 1.9.3 - although this may affect other versions.

My Rails app has a custom default timezone, with the following set in config/environment.rb:

config.time_zone = 'Brisbane'

There are no issues with Date attributes. The time zone is respected through the Rails app when creating or displaying DateTime attributes. However, when editing DateTime attributes, the time displayed in the form is in the UTC time zone rather than local time.

After trying numerous workarounds, I found a post on Stack Overflow mentioning that this appears to be an issue with displaying DateTimes in text fields in Rails. It appears that this is a limitation (bug?) in Rails. As I’m using a JQuery-UI DateTimePicker plugin, I have to use a text field to display the time.

As mentioned in the Stack Overflow post, to fix this issue I needed to force the attribute to be used by the text field by changing the text field in my form from:

f.text_field :start_time

to:

f.text_field :start_time, value: f.object.start_time

Fixed.

How to Flush the DNS Cache in OS X Lion

The old way to flush the DNS cache in versions of MacOS X prior to Lion was to run the command:

dscacheutil -flushcache

This doesn’t work for me in Lion. To flush the DNS cache in Lion, run:

sudo killall -HUP mDNSResponder

Offline

After mucking around with my webserver and switching from Apache to nginx, it appears as though my blog was offline for a month or so. I’m sure the world didn’t miss it with my amazing post frequency.

The Easiest Way to Run IE6, IE7 and IE8 on the Same Machine

There are far too many guides on the net about running multiple versions of IE on the same machine. And most of them are a pain in the ass to set up.

Here’s something I bumped into today: Spoon’s Browser Sandbox. Spoon have a plugin that can launch all sorts of applications from your browser. It streams virtualised application packages to your PC through the browser. A couple of clicks and IE6 - or any other application they have in their portal - will launch.

This is probably the single best use of application virtualisation that I’ve seen in the wild. It’s the kind of “just works” technology I love. Great for web developers or occasional hacks (I’m in the latter category).

And just for the hell of it - here is a screenshot of Firefox (running natively), IE8 (running in a Windows VM via VMware Fusion) and IE6 (running in the VM with Spoon) all on my MacBook Pro:

Screenshot2010-03-17at2.05.48PM.x6wThM1iJWYU.jpg

My New Favourite iPhone App - Instapaper

I download and play with a fair amount of iPhone applications, but I only stick with a few in the long run. The few that I use all the time are NetNewsWire, RunKeeper Pro, and Pocket Weather AU. I’ve found a new application for that list - Instapaper.

The idea behind Instapaper is to mark web pages when you’re at your computer so that you can read them offline on your iPhone when you might have a few minutes to kill. You add a “Read Later” link - which Instapaper supplies - to bookmarks toolbar in your browser. Whenever you’re at a page that you’d like to save to read later you hit the “Read Later” bookmark. Instapaper then saves that page to your reading list.

When you’re away from your computer, run the Instapaper app on your iPhone and Instapaper grabs your reading list and formats it nicely to read on the iPhone. Pick an article and start reading. If you’re interrupted Instapaper will remember your place. Nice little touches like that make it a pleasure to use.

It’s a simple concept that is done very well. The whole process just gets out of the way and lets you do what you wanted to - read.

Stop Overengineering!

To IT engineers: Please, please, PLEASE stop overengineering environments that don’t need to be so complex.

Before you create a dozen 40GB LUNs for VMware RDMs for “performance” on a 60 user site, before you change the default Citrix XML port because you think it will make it easier to track the traffic, before you tweak and change every setting - please stop and think: “Does this have any additional benefit or am I doing this because I think I should?”

Hint: The answer is usually no, it doesn’t have any additional benefit. So don’t do it.

Cloud Computing - Reality vs Concept

For the last two years, cloud computing has been increasing in media presence and vendor push.  Each of the major vendors in the emerging cloud space has a specific message about what cloud computing is, and what it means to you.

Whether due to cloud computing still being new, or whether it is deliberate on the part of the companies pushing it, cloud computing itself is still very loosely defined, and I’m not going to try define it here.  However, the main basis of cloud computing is paying a recurring fee for a utility computing service.

To those in the infrastructure space, cloud computing seems to be the step after virtualization - once you have virtualized your servers (to an “internal cloud”), move them to or federate with an external cloud for extra capacity.  This philosophy has been mostly generated by VMware’s vSphere marketing.

But the real benefits of cloud computing aren’t achieved with moving your existing applications (or VMs) offsite.  Let me say that in a different way - virtualization is not cloud computing, and cloud computing is not virtualization.

Your existing applications won’t scale well - they’re limited by their architecture.  They’re intertwined with the operating systems they run on.  They often won’t scale horizontally, either - many being limited to a single operating system instance for each tier. For many of them, the user interface and the way they access their data can mean that you need very high bandwidth, LAN-type latency links to your cloud provider for these applications to perform.

The true benefit of cloud computing is when the application is designed for the cloud.  This is a fundamental shift in the way that we use applications.  A cloud-based application generally doesn’t require software installation, you don’t need to think about server management, and is usually decoupled from the operating system on both the server-side and the client-side due to a web-based delivery (There are exceptions, of course).  They can be available offline with frameworks like Adobe Air and Google Gears.  They scale horizontally exceptionally well due to a stateless front-end application architecture (web servers and browsers), and a backend that can be partitioned into different databases.  Another benefit of cloud applications is that the enterprise doesn’t have to worry about application installation management - it’s all on the cloud side.

Cloud computing is here today, and you’re using it. Google.com is the archetypal cloud.  Gmail, Facebook, Twitter are all cloud applications.  Cloud computing is about bringing the scalability and resilience of the web’s best to your business application.

For those in the infrastructure space that were mystified when they did it - this is why VMware purchased SpringSource.  SpringSource is an application development framework to build cloud apps.  The next platform battle will be between the cloud frameworks - not the operating system or hypervisor. Virtualization will play a huge role, but on the back end.

Right now, the main contenders for application service cloud frameworks are: VMware/SpringSource, Microsoft Azure, (Sales)Force.com and Google App Engine.  A minor contender is Heroku - a cloud service for the excellent Ruby on Rails framework.  All of them are worth checking out.