Skip to Navigation | Skip to Content



Archive for the 'Uncategorized' Category

Rails Timezones | October 5th, 2008

In my spare time I have been working on a geo-location application that runs on a BlackBerry mobile phone connecting to a Rails server where the geo data is stored.

If you happen to still be using Rails < 2.1 then this may be interesting, however, with the recent release of 2.1 timezones have been fixed up pretty well. Of course I wanted to get something that worked for my application in pre 2.1 days so I rolled together a few different libraries that seems to work pretty well. Having said that, the JavaScript will help you determine a users timezone no matter what version of Rails you are using.

The particular use case that I want to hit is that people can login to the web application from wherever they want and the application will automagically display the times in the timezone of the user viewing the site - not the timezone of the user that created the geo data and not the timezone of the server.

The general approach taken is to get the users timezone offset through JavaScript in the browser, then save that in the users profile, and then have a helper method to convert any times that are saved in the servers timezone to the users local zone.

Prerequisites

Gems: tzinfo (0.3.9, 0.3.8), tztime (0.1.0)

Plugins, tzinfo_timezone, tztime

Now for the code

So how do we figure out the users timezone? Through JavaScript of course! In application.js put the following script at the top - don’t put it on the onload event since it should set as soon as a user hits the page:


Cookie.set("tz", (new Date()).getTimezoneOffset());

This sets a cookie in the browsr to be the JavaScript timezone offset, which we will use later on the server. Note that this is using a simple cookie abstraction.

Now in application.rb we need some magic that will take that timezone offset from the cookie and update the users profile with their current timezone. This will be achieved with an around_filter (damn I love around filters) like so:


around_filter :set_timezone

def set_timezone
  if logged_in? && browser_timezone && (browser_timezone.name != current_user.time_zone || current_user.time_zone.nil?)
    current_user.update_attribute(:time_zone, browser_timezone.name)
  end
  TzTime.zone = logged_in? ? current_user.time_zone : browser_timezone
  yield
  TzTime.reset!
end

def browser_timezone
  return nil if cookies[:tz].blank?
  @browser_timezone ||= begin
    min = cookies[:tz].to_i
    TimeZone[-min/60]
  end
end

That takes care of getting the users current timezone. Now all we have left is to make it accessible to the application with a simple function in the application_helper.rb as follows:


def local_time(time_at)
  TimeZone[TzTime.zone].utc_to_local(time_at.utc)
end

Finally, we can just call local_time from anywhere passing in a time that is in the servers timezone from the database:


local_time(location.updated_at)

So if you are stuck on Rails < 2.1 that is a good approach to getting timezones working.

Posted in AJAX, Components, Flex, Uncategorized, Web | 2 Comments » | Add to Delicious | Digg It

Drop Down Menu Affordances | July 12th, 2008

It seems like drop down menus are moving back towards having down arrows on them.

It seems like in the early days of Web 1.0 people would do all they could to get away from the select box and use all sorts of fancy DHTML menus (remember dynamicdrive.com anyone?). However, these days we are seeing most applications that have drop down menus - while not using the HTML select element - are reverting back to the down arrow visual affordance.

For example, GMail, Zazzle, LinkedIn and Amazon are all using the down arrow on their drop down menus nowadays. This simplification of user interfaces becoming a common theme in the latest web based applications.

Posted in Uncategorized | No Comments » | Add to Delicious | Digg It

Complete UI Q2 Progress | April 28th, 2008

We are almost a month behind now on the Q2 release of Complete UI but Mike and I are in the final throws of polishing. We are shooting for releasing today and if that fails tomorrow at the latest. As people will know from the beta we are releasing support for Safari 3, new Dreamweaver Extensions, new themes and, most importantly, a new component called TreeGrid for displaying hierarchical data. I have a can of Red Bull in hand and one last Safari Combo bug to fix before the building will commence!

Posted in AJAX, Nitobi, Uncategorized, completeui, dreamweaver, safari | No Comments » | Add to Delicious | Digg It

CommunityOne Presentation | April 26th, 2008

So I have been accepted to give a presentation at CommunityOne, which occurs the day before JavaOne on May 5. I am going to talk about JavaScript + DOM patterns. I was going to focus on the JavaScript and DOM details around some common Ajax patterns such as those covered conceptually by Michael and Bill. Any ideas would be more than welcome!

Andre and I are also going to take part in the RedMonk CommunityOne festivities as much as possible as well which should certainly be a blast.

This is a bit of a digression but what a sweet picture. Ryan looks badass and Cote is all choked up!

Posted in AJAX, JavaScript, Nitobi, Redmonk, Uncategorized, communityone, javaone | 1 Comment » | Add to Delicious | Digg It

Ajax Functional Testing | February 27th, 2008

We are getting really close to being able to release all of our Selenium functional tests and JSUnit unit tests to our developer community! Ryan has been doing a kick ass job of bring Cruise Control back from the brink and we are being way better about actually running all our tests ;)

With Cruise Control we can now check out our web based dashboard to see the results of automagical test runs and builds or do a manual build. We can even see the results of our Java based Selenium functional tests online.

By abstracting much of the Ajax and DOM leg work into base classes we get really clean Java based functional tests that look something like this:
clickCell(2,2);
assertEquals("Some cell value", getSelectedCellValue());

What could be easier? It is also nice that it is run from Java since I can just create a Java project that references all my Ajax tests then compile and run them individually on my development computer using JUnit. Then they can also easily be called from ANT build files and Cruise Control as well.

I will be posting some more about Ajax testing soon.

Posted in AJAX, Testing, Uncategorized, selenium | No Comments » | Add to Delicious | Digg It

Ajax Experience | October 25th, 2007

Andre and I are in Boston for The Ajax Experience!

I am presenting tomorrow at 3:45 on Ajax Testing and Debugging so be there - or be around after to go for a beer.

Posted in AJAX, Conference, Nitobi, Uncategorized, ajaxexperience, boston | 2 Comments » | Add to Delicious | Digg It

Complete UI Q3 Released | October 2nd, 2007

This time around we left the major Complete UI release in Beta for a month to give us a bit more time to work out all the quirks with our major new feature - Complete UI Dreamweaver Extensions. Now you can go from a database to an Ajax application in minutes using the awesome Dreamweaver Extensions that allow you drag and drop Nitobi components into your web page and have server CRUD (ASP, PHP, JSP, CFM) generated according to the database that you are connecting to!

Check out a screencast here - very cool stuff!

Also if you are at Adobe MAX in Chicago ping Andre or Alexei who are there representing Nitobi and presented an Inspire session today about AIR and Ajax!

Posted in AJAX, Components, Nitobi, Uncategorized, dreamweaver, max, max07 | 2 Comments » | Add to Delicious | Digg It

Nitobi Hack Day | September 17th, 2007

Now that things are starting to settle down at the new office and I am back from my travels in Dallas and Portland we can finally settle into some hack day fun.

It is really just an idea right now but please submit any ideas as comments. It will be open to pretty much anyone that wants to come and we will likely have it on an upcoming saturday. Nitobi will supply the hacking essentials like caffeine and pizza (maybe even some beer ;) . The one stipulation is of course that everyone, either in a small group or alone, builds something cool and presents it to the rest of us (true to the spirit of the hack day). This something cool could be in the RIA space (Ajax, Flash, AIR, JavaFX, etc) but it could also be hardware or otherwise.

I am throwing out there Oct 13 as a tenative date so speak now if you have already got that day booked.

UPDATED: Oct 13 is just stupid cause thats thanksgiving weekend … Oct 20 is the new date.

UPDATED AGAIN: Please signup on Upcoming since space will be limited - and Andre will likely be doing some judging and giving away some sort of prize(s)

Posted in Nitobi, Uncategorized, hackday | 14 Comments » | Add to Delicious | Digg It

Quote of The Day | September 16th, 2007

This is not something that I am going to blog about very often but I could not help myself. Having lived in London for a few years I understand that if there is one thing that can unite Londoners it is their amazing disdain for public transport. Water cooler chatter usually consists of a healthy dose of war stories about the days train and bus rides.

From the linked article, Richard Middleton, the “head of rail” (!) at Steer Davies Gleave, says that “Germany is very good at integration - timetables match up … But the UK is better at providing information for passengers.”

I am not really sure what that means? I guess “providing information for passengers” is supposed to make up for really crap service?

Posted in Uncategorized, london, transport, tube | No Comments » | Add to Delicious | Digg It

Wireless Free 4 All in Vancouver | September 15th, 2007

While it may take the likes of Google to provide free wireless to the city of San Francisco, Joe Bowser has instigated a veritable stampede to get a wireless mesh installed in Vancity. Unlike San Fran this is from the bottom up - from the grass roots rather than the tree leaves.

In particular Joe is focusing on the Gastown area with the help of Nitobi and their local neighbours like Bryght.

If you are in Gastown or Vancity then get your wireless mesh node here for the low low price of $99!

A big kudos to Joe for getting this whole crazy idea off the ground!

Picture of Brian Leroux and Joni Rustulka (Joni do you even have a blog and pls twitter more!?!?) care of nep

Posted in Uncategorized, gastown, meraki, vancouver, wifi, wireless | 2 Comments » | Add to Delicious | Digg It


Search Posts

You are currently browsing the archives for the Uncategorized category.

Archives

Categories