Cool Project: Timelines.com

2009-05-04 20:00:00 -0400


Scott McMillin posts over on mad.ly:

Timelines is a place for people to record and share history about any topic. We want it to be the Wikipedia of event-based information, but unlike Wikipedia we want everyone to have a voice and add their own perspectives (and photos, videos, etc) about events.

I’m a history dork, so I created an account already. I read history text books for fun (recently I started reading Voices of a People’s History of the United States), and nailing down what really happened is like trying to nail jelly to the wall. The more voices you have (even the biased voices), the more source material, the more you have to work with to try and discern what happened. This has the potential to be an extremely excellent resource.

Scott also gives some details on the infrastructure supporting Timelines.com. Looks like PostgreSQL drives most operations, but the actual event data and media appear to be stored in CouchDB. Very interesting.


JS Date Object Extensions

2009-04-30 20:00:00 -0400


In our time-tracking app, Tempo, we’ve got a date range drop-down menu, and that allows you to set the start and end dates for a report. Next to it are two text fields for the start and end date, which are over-ridden when the user selects one of the ranges.

Tempo date range selection

This got a little confusing for users because the drop-down selection wasn’t reflected in the text fields, so I threw together some quick javascript for calculating the date end points client-side and setting the fields. In the end, I needed something like:


Tempo.activate_range_select = function() {
$j("select#interval").change(function(){
var $select = $j(this);

// for each interval, create a start and end date, and insert into date fields
var now = new Date();
var start_date = null;
var end_date = null;

switch($select.val()) {
case "today":
start_date = now.beginning_of_day();
end_date = now;
break;
case "yesterday":
start_date = now.days_ago(1).beginning_of_day();
end_date = now.days_ago(1).end_of_day();
break;

To get here, though, I had to work out these date calculation methods that you can see being used above. Those aren’t naturally occurring methods on the Date class in Javascript, but they can be if you write them yourself! And as you build out the simpler ones, they lend themselves to a full library.

So here’s a little library that extends the Date object with a big pile of handy methods: date.js It’s not all entirely original, I did find some tips out there in the wild and lifted a couple of handy things from the jQuery Date Picker’s date.js. But only a little.

A sampling of some of the methods:


Date.prototype.weekDay = function () {
// in ISO we want Mon = 0 and Sun = 6!
var day = this.getDay() - 1;
day = (day < 0) ? 6 : day;
return day;
};

Date.prototype.isLeapYear = function() {
var year = this.getFullYear();
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
};

Date.prototype.end_of_week = function() {
var d = this.copy();
d.setDate( this.getDate() + (6 - this.weekDay()) );
d.setHours(23,59,59);
return d;
};

/*
* figuring out the end of quarter:
*
# q1 = 31 + 28 + 31 = 90 + 2(leap)
# q2 = 30 + 31 + 30 = 91
# q3 = 31 + 31 + 30 = 92
# q4 = 31 + 30 + 31 = 92
*/
Date.prototype.end_of_quarter = function() {
var d = this.copy();
d.setHours(23,59,59);
switch( this.getQuarter() ) {
case 1:
// is this a leap year?
if ( this.isLeapYear() ) {
d.setMonth(0, 92); // allow overflow to set correct month and day
} else {
d.setMonth(0, 90)
}
break;
case 2:
d.setMonth(3, 91);
break;
case 3:
d.setMonth(6, 92);
break;
default:
d.setMonth(9, 92);
}
return d;
};

It's a Big World

2009-04-30 20:00:00 -0400


ENTP’s founder Courtenay has an interesting comment up on his blog today:

As a side note, none of these people are from the US, which is a reminder to those of us North American-centric coders that there is a huge world of smart people out there.

Which is funny (or ironic), because on WNYC just now they were discussing 1) the surprising lack of H1B applications for the first time in a long time, and 2) proposals in Congress to make access to temporary worker visas more restrictive. Interesting times.


Tempo Maintenance Tonight: APR-23

2009-04-22 20:00:00 -0400


We’ll be interrupting service briefly tonight (23-APR-2009) on Tempo for a bit of background maintenance that should improve stability of the service. This will take place at 11pm EDT.


My Thoughts Exactly

2009-04-18 20:00:00 -0400


On the Apple Push Notification Service for iPhone OS/SDK 3.0, there’s an interesting comment thread over on Mobile Orchard. Ryan Daigle writes:

This has the potential to become a very expensive and heavy-weight hack to masquerade as a local cron system on the iPhone.

As Adrian Hosey reasons in that same thread, it really is a lot of fail-prone nonsense. There should be some kind of local device API for scheduling with launchd or whatever the OS uses.