Archive for June, 2009

New version of PixelWindow

PixelWindow (was PixelPerfect) was one of the first AIR applications I wrote, and has turned out to be one of the most useful. I wrote it primarily as a test case for multi-window, custom chrome, transparent, pure ActionScript AIR applications, and I’ve been using it almost daily ever since.

If you’re unfamiliar with PixelWindow, it’s a simple, light-weight AIR application for measuring things on your screen. It creates a translucent window that acts like a pixel ruler with its width and height reported in the center. Just drag it around and resize it to measure whatever you want.

I finally got around to updating PixelWindow, and creating its own site and installer badge. I also added a few new features:

  • You can now measure down to 15×15 pixels. When the ruler gets too small to display the dimensions, they jump outside the window.
  • The ability copy dimensions to your clipboard.
  • The ability to use your keyboard to move rulers by one or five pixels at a time.
  • A help window to remind you of the keyboard shortcuts.

If you use an old version of PixelWindow (probably installed as PixelPerfect), I recommend that you grab the new version. And if you don’t use it, it’s an extremely useful app for any designer or developer to have around. And remember that PixelWindow is open source, so feel free to grab the code to fix bugs, add features, or just to see how it works.

ActionScript function for turning a date into a time interval

While working on a small Twitter utility, I wrote a function to turn a date into a time interval string. For instance, rather than formatting the date, it returns strings like “Just posted,” “6 minutes ago,” “4 hours ago,” or “20 days ago”. It’s not a complex function, but I thought I’d post it here in case it might save someone a few minutes of coding. The less time we spend writing code someone else has already written, the more time we can spend innovating.

private function formatDate(d:Date):String
{
var now:Date = new Date();
var diff:Number = (now.time - d.time) / 1000; // convert to seconds
if (diff < 60) // just posted
{
return "Just posted";
}
else if (diff < 3600) // n minutes ago
{
return (Math.round(diff / 60) + " minutes ago");
}
else if (diff < 86400) // n hours ago
{
return (Math.round(diff / 3600) + " hours ago");
}
else // n days ago
{
return (Math.round(diff / 86400) + " days ago");
}
}