Archive for July, 2011

Loading a blog feed on your website

Friday, July 29th, 2011

Recently I needed to load recent blog posts onto a website. I discovered the Google Feed API which, as most things Google, is awesome. I also discovered this jQuery plugin which uses it along with what appears to be an old version of their Dynamic Feed Control. This plugin, like all of Mike Alsup’s other plugins, is great. However, I couldn’t get it to work exactly the way I wanted. So I built my own.

I also borrowed and modified some code from John Resig to format the dates. Oh yeah, it also depends on the jQuery Templating Plugin.

It takes an options argument with a required url property and a couple of other optional properties, gets the feed, and loads the items into semantic markup inside the selected element. You can then style it any way you want.

/**
*  Plugin which uses the Google AJAX Feed API for creating feed content
*  depends on jquery template plugin
*  very loosely based on http://jquery.malsup.com/gfeed/
*/

(function ($) {
    if (!$.template) {
        alert('You must include the jQuery Templating Plugin script');
        return;
    }

    //feed item template
    var templateHtml = '<div>' +
                            '<div class="feed-item">' +
                                '<a href="${link}" target="_blank">' +
                                    '<h2 class="feed-title">${title}</h2>' +
                                '</a>' +
                                '<div class="feed-snippet">${contentSnippet}</div>' +
                                '<div class="feed-footer">Posted ${publishedDate} by ${author}</div>' +
                            '</div>' +
                        '</div>';

    //from based on code from John Resig
    // - http://ejohn.org/blog/javascript-pretty-date/
    function prettyDate(dateString) {
        var date = new Date(dateString);
        diff = (((new Date()).getTime() - date.getTime()) / 1000),
		            day_diff = Math.floor(diff / 86400);

        if (isNaN(day_diff) || day_diff < 0) {
            return;
        }

        return day_diff == 0 && (
			        diff < 60 && "just now" ||
			        diff < 120 && "1 minute ago" ||
			        diff < 3600 && Math.floor(diff / 60) + " minutes ago" ||
			        diff < 7200 && "1 hour ago" ||
			        diff < 86400 && Math.floor(diff / 3600) + " hours ago") ||
		            day_diff == 1 && "Yesterday" ||
		            day_diff < 7 && day_diff + " days ago" ||
		            day_diff < 42 && Math.ceil(day_diff / 7) + " weeks ago" ||
                    day_diff >= 42 && Math.floor(day_diff / 31) + " months ago";
    }
    new Date().tou
    $.fn.feed = function (options) {
        var opts = $.extend({
            url: '',
            target: this,
            title: 'The latest from our blog',
            max: 5   // max number of items
        }, options || {});

        //show a loading indicator
        opts.target.append('<div id="feed-loading">loading blog feed...</div>');

        //get the feed items
        var feedItemTemplate = $(templateHtml).template();
        var gFeedsUrl = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&num=' + opts.max + '&q='
        $.ajax({
            url: gFeedsUrl + encodeURIComponent(opts.url),
            dataType: 'json',
            success: function (response) {
                //remove the loading indicator
                $('#feed-loading').remove();

                if (response && response.responseData
                                  && response.responseData.feed
                                  && response.responseData.feed.entries) {
                    var feedItems = response.responseData.feed.entries;
                    //map them to format the date
                    $.map(feedItems, function (item, idx) {
                        item.publishedDate = prettyDate(item.publishedDate);
                        return item;
                    });
                    //load the feeds into the dom
                    opts.target.append('<h1>' + opts.title + '</h1><div id="rss-feed"></div>')
                        .find('#rss-feed')
                        .append($.tmpl(feedItemTemplate, feedItems));
                } else {
                    opts.target.append('<div id="feed-error">Unable to retrieve blog feed.</div>');
                }
            }
        });

        return this;
    };
})(jQuery);

Sending javascript dates to Asp.NET

Friday, July 29th, 2011

I’ve struggled with this at various times and come up with a number of solutions, none of which were entirely satisfying. Now, thanks to Stackoverflow, I found a really nice solution:

Javascript:

obj.date = new Date().toUTCString();

C#:

DateTime date= DateTime.ParseExact(obj.date,
                                  "ddd, MMM d yyyy HH:mm:ss GMT",
                                  CultureInfo.InvariantCulture);

And now for something completely different…

Friday, July 15th, 2011

I’ve been meaning to post about this for years and am finally getting to it.

In January of 2007 we bought our house from Jamestown Builders. When it was about a month out of warranty, we noticed that like some of our neighbors’, our driveway had begun to spall.

I called them to see what they were going to do about it and their response was basically that I shouldn’t have parked my car on it in the winter. Well, I didn’t very often, but IT’S A DRIVEWAY! Can I cook in my kitchen? Can I poop in my bathroom? The rationale is that the freeze/ thaw cycles are exacerbated by the stuff they put on the roads (and then drips off my car) to melt ice and that cracks the driveway. According to my research, while that certainly can happen, it should not happen to properly formulated and installed concrete.

Furthermore, I had a concrete driveway in MINNESOTA that was who knows how many years old when I bought the house and on which I parked my truck every day for the 6 years I lived there. Last time I looked (in 2010) that driveway was fine. By now, The Jamestown driveway is 4 years old and it is quite simply disintegrating. I think it’s outrageous that I’m going to have to spend at least $3000 on my driveway when the house is barely 5 years old.

driveway

The bottom line is that they clearly had a quality problem with their concrete contractor. They know this perfectly well and if they’d just say so but say, “sorry you’re warranty expired”, I could accept that. But it rankles that they claim it’s my fault and that it’s to be expected for a driveway to disintegrate if you use it for it’s intended purpose.

So I do not recommend purchasing a house from Jamestown Builders.