Zetetic.Chain - Some love for .NET

2009-05-13 20:00:00 -0400


Today we released Zetetic.Chain on github as open source under a BSD-style license. The inspiration for Zetetic.Chain is Apache Chain, but Zetetic.Chain also takes advantage of some of the things .NET does really well without lots of dependencies, like reflection attributes (well, reflection in general), XML serialization, Remoting, indexer properties, and so on.

The Chain concept lets you work with commands, and stacks of commands, with a simple model—just say the name of the command you want to run, pass it an object in which to get and set state / results, and the Zetetic.Chain library takes care of the rest, keeping your implementation nice and clean. You configure the details of each command in a lean n’ mean XML file. Example:


<catalog>
<chain name="TellStory">
<command name="first" typeName="Storybook.WalkInTheWoods">
<add key="BoysName" value="Hansel" />
<add key="GirlsName" value="Gretel" />
</command>
<command name="also" typeName="Storybook.BirdsEatTheBreadcrumbs" />
<command name="ohno" typeName="Storybook.WitchInCandyHouse" />
</chain>
</catalog>

Your code can fire off the chain of events simply by calling:


ICatalog catalog = CatalogFactory.GetFactory().GetCatalog("storybook.xml");
IContext context = new ContextBase();
catalog["TellStory"].Execute(context);

So check it out, let us know what you think! Personally I know this library is going to become part of most of my ongoing projects on the .NET platform.


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.


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.