RedFurSnake

Sunday, March 14, 2010

Reliable Time Machine backups on a NAS

I have a Synology NAS which is supposed to support Mac OS X Time Machine backups. However, I was finding that after a while, backups would stop working. Despite tips on the web for getting it working again, the only way I found was to start again with a new backup. I would be interested to hear if anyone has a reliable NAS Time Machine backup working with Snow Leopard, because I'm not sure if the problems are with Apple or Synology.

Anyway, iSCSI to the rescue! iSCSI volumes are supported by the Synology NAS, but to access them on the Mac you need a third-party iSCSI initiator like globalSAN (which is free!). Occasionally, TimeMachine still complains that it cannot mount the volume, but a simple disconnect/reconnect in globalSAN sorts it out.

I'm not sure how the performance of iSCSI compares with standard network shares, but that's not really important for Time Machine, where all I care about is reliability.

Changing the order of scriptaculous Droppables

If you have two overlapping Drop areas using scriptaculous Droppables, you would naturally want the uppermost droppable to receive the dragged object. However, you will only get this behaviour if you the Droppables.add them in the right order. Droppables added first are checked first, which seems wrong to me since divs added first will naturally be rendered underneath divs added later (if they overlap).

Anyway, I came up with a nasty hack to move an added Droppable to the front of list so it is checked before the others (great for dynamically created popups, etc):

// Make the new element Droppable as usual
Droppables.add(popup);

// Move the just added element to the front of Droppables internal drops list
Droppables.drops.unshift(Droppables.drops.pop());

This isn't ideal and could easily break if the implementation of Droppables is changed. Hopefully, in future releases of scriptaculous, it will be possible to prepend/insert Droppables rather than just append them.

Tuesday, February 16, 2010

Get your user's time zone from their IP address in Rails

I have a Rails web app that would like to have a good guess at what 'today' is for users that could be scattered across time zones. Here's how I am currently doing it, with services from hostIP.info and the geonames gem. In the model that has the user's time_zone attribute:
require 'open-uri'
require 'geonames'

class User < ActiveRecord::Base
  def set_time_zone_from_ip(ip)
    location = open("http://api.hostip.info/get_html.php?ip=#{ip}&position=true")
    if location.string =~ /Latitude: (.+?)\nLongitude: (.+?)\n/
      timezone = Geonames::WebService.timezone($1, $2)
      self.time_zone = ActiveSupport::TimeZone::MAPPING.index(timezone.timezone_id) unless timezone.nil?
    end
  end
end
This uses two third party free web services,  so may not be suitable, or may require commercial versions if you want to do a lot of look ups.

The time zone is set at the start of each request, via a before_filter in ApplicationController that calls:
def set_time_zone
  Time.zone = current_user.time_zone
end
I have also monkey patched the standard Date.today function in an initializer, so that all my calls to Date.today return the correct time zone adjusted date:
class Date
  def self.today
    Time.zone.today
  end
end
I'm not sure if this is the best way to do this, but thought it might help someone out...

Thursday, January 28, 2010

Apple iPad


So here is is, the new Apple iPad. As expected, it's pretty sexy. I wasn't sure if there would be a market for this sort of thing, but now I think this device could replace most home PCs. Why? Because most consumers only do email, ebay, facebook, photos/video/tunes/games on their computers anyway, and this device is going to be great for all that and even easier to use than a Mac.

With the optional keyboard dock and iWork suite, it could even do for home office chores.

Used in conjunction with a media server/time capsule,  I would say it satisfies the needs of most home users.

Is it for me? Not yet, but I think it's inevitable: every home will have one.

Omissions? Same as iPod touch: I'd like it to have a front facing camera for Skype iChat calls and an IR emitter so it can be used as a universal remote.

Sunday, January 17, 2010

New iMac


I have been the proud owner of a new iMac 27" i7 for a few weeks now... time to report back. Here's how it compares to my old setup: a MacBook Pro 2.33MHz with 30" cinema display:

  1. Slightly smaller screen (same width, but a couple of inches shorter than the 30"). This compromise has made no difference to me. It could be said that the aspect ratio of 16:9 (as opposed to 16:10) is actually slightly more pleasing to the eye and leads to less neck straining.
  2. Glossy screen. Although it tends to suffer from reflections, careful positioning gives a more pleasing smoother picture than the matt 30" screen, with deeper blacks, etc.
  3. Memory. 8GB (as opposed to 3GB) means I can run everything at the same time without slowdown: Parallels VM with 2GB, RubyMine, Safari, Photoshop, iTunes all at once with memory to spare (but only a small amount I admit!)
  4. Graphics card. This coupled with extra memory makes a huge difference to Aperture. Finally, no more waiting!
  5. Magic Mouse. I wasn't expecting this to replace my current Logitech mouse, but it has. I love it! Shame it's not rechargeable though...
  6. Wireless keyboard. Again, I wasn't expecting this to replace my wired full size apple keyboard, but it has. At first, I really missed the forwards delete key, until I realised it is available via fn-backspace. I'm surprised I haven't missed the numeric keypad more. I appreciate the smaller form factor of the keyboard and the lack of wires.
  7. Speed. Overall, it is significantly faster than my old machine, and showing 8 cores regularly busing themselves in iStat!
  8. Built-in iSight, mic and more decent sound. Icing on the cake.
Downsides? As a computer, none at all, but I suppose it would have been nice if it had had Blu Ray and an HDMI input...

Should you buy one? Oh yes! And make sure its the i7: Most agree that the performance boost is worth the extra expense. Shame that Apple have just increased the lead time to 3 weeks!

Saturday, November 7, 2009

Unusual Coding Tips, Part 1



Make your font larger in your IDE/text editor. Not only is it easier to read, but you'll tend to write shorter methods and simpler code. In RubyMine, I'm using Monaco 13.

Tuesday, September 1, 2009

Snow Leopard

I upgraded to Snow Leopard a few days ago. Conclusion? Largely inoffensive. In no particular order, the changes I have seen are:

  1. The icons in the top-right of the menu bar are now greyed out when inactive, e.g. when airport is off, iChat isn't running.
  2. There's a new keyboard and character viewer next to the clock. Does this replace the international preferences
  3. Spotlight can now (and should have been all along) configured to search the current folder when used in a Finder window.
  4. New desktop background.
  5. Changing Spaces animation is quicker and/or smoother.
  6. Selecting a 32-bit panel in System Preferences, causes SP to restart in 32-bit mode. Shame the user has to see this, but I suppose everything will be 64 bit soon enough.
  7. More disk space available, not sure how much (about 5 degrees on the Activity Monitor disk usage pie chart!!)
  8. Time Machine is a bit more informative. It's also quicker, but since it goes on in the background anyway, it hardly matters how long it takes (within reason).
  9. Mail is quicker and I think the tool buttons look a bit different (worse actually).
  10. Aqua style scroll bars still around the place (I thought they would all now look more like iTunes).
  11. I installed without Rosetta, so now if I try to run a PowerPC app (like Word 2004), I get the change to download Rosetta first. So far, I have resisted!
  12. Glims doesn't work in Safari any more.
  13. Context menus on dock icons are now black.
  14. You can press and hold an application's dock icon to Exposé it.
  15. The Software Update 'checking...' window is bigger.
  16. Errr....
All a bit of an anti-climax. I knew it wouldn't be that different, but I was hoping for a general speed boost, especially in apps like Aperture and Logic. It is supposed to be more stable, but stability wasn't an issue for me before. Perhaps other types of Mac benefit more than mine?
Let me know if you think I'm missing something important...