Archive for December, 2007

Conversations to Remember

"Your [gas] is horrible."

"No, no it's not. It's like someone made you a peanut butter sandwich and you didn't even know you brought lunch."

Tags:

Still Waiting

For Zero Punctuation to get old. It seems like everything that really entertains me on the Internet has a short life. Hilarious for a week, funny for a month, meh after that. But I'm starting to doubt this will ever happen with Yahtzee. See for yourself:

Clone Table Rows with Form Elements in a .NET Style

Using jQuery to coax .NET into cloning table rows with properly numbered id/ name attributes:

 
var MyNamespace = {
	init: function()
	{
		// attach row clone to passenger table
		$("table#tblPassengers tr:last :input").change(function() {MyNamespace.cloneRow("tblPassengers")});
 
		// attach row clone to contacts table
		$("table#tblContacts tr:last :input").change(function() {MyNamespace.cloneRow("tblContacts")});
	},
 
	cloneRow: function(sTableId)
	{
		var oRow = $("table#{0} tr:last :input".format(sTableId));
		oRow.unbind("change");
 
		var oNewRow = $("table#{0} tr:last".format(sTableId)).clone();
 
		$(":input", oNewRow).each(
			function ()
			{
				MyNamespace.cloneInput($(this));
			}
		);
 
		$("table#{0}".format(sTableId)).append(oNewRow);
		$("table#{0} tr:last :input".format(sTableId)).change(function() {Flights.cloneRow(sTableId)});
	},
 
	cloneInput: function(oInput)
	{
		oInput.val("");
		var oRegex = new RegExp(/[^"]ctl(\d+)/g);
 
		var sId = oInput.attr("id");
		oRegex.exec(sId);
		var iIdCount = parseInt(RegExp.$1[1]);
		var sFind = "ctl" + MyNamespace.padIntegerString(iIdCount, 2);
		var sReplace = "ctl" + MyNamespace.padIntegerString(++iIdCount, 2);
		oInput.attr("id", sId.replace(sFind, sReplace));
		oInput.attr("name", oInput.attr("name").replace(sFind, sReplace));
	},
 
	padIntegerString: function(iInt, iNumberOfCharacters)
	{
		var sTest = iInt + "";
		if (sTest.length >= iNumberOfCharacters)
		{
			return sTest;
		}
		var sPad = "";
		for (var i = 0; i < iNumberOfCharacters - 1; i++)
		{
			sPad += "0";
		}
		return sPad + iInt;
	},
};

Tags:

Rails 2.0 Released

2.0.1, actually. Now I just need an excuse to use it somewhere.

Tags:

Me and .NET

We get along so well:

Try Catch Drop

Tags: