Stephen's Statements A little bit of everything from Stephen Duncan Jr, a Programmer/Web Geek working in the defense industry

Updates: Switched to a new hosting service.

Sunday, March 15, 2009

JQuery For Archives

Instead of working on the conversion of the blog to Webby, I spent much of the day playing with jQuery and JavaScript. A good portion was mostly wasted time attempting to make the loading of the syntax-highlighting scripts more dynamic. While this ultimately failed, it did get me to re-learn a lot of JavaScript and jQuery.

Rather than put that time completely to waste, I decided to prettify the archives section. Without JavaScript enabled, you get a linked list of links for each month of each year that I've published something. Now, with JavaScript, I transform that list of links into drop-downs for each year, where you can select the month within the year, and it will take you to the archive page for that month.

Now, for the code. First, on each blog page (via the template), I load my JavaScript file, and I load jQuery via Google AJAX Libraries API:

<script type="text/javascript" src="/js/main.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load('jquery', '1.3.2');

    google.setOnLoadCallback(function() {
            prettify_archives();
    });
</script>
This runs prettify_archives function:
function prettify_archives() {
    var years = [];

    $("#archives > ul > li").each(function() {
        var year = new RegExp(/\s(\d{4})/).exec($(this).text())[1];

        if ($.inArray(year, years) == -1) {
            years.push(year);
        }
    });

    years.reverse();

    var html = ['<h4 style="margin:0;">Archives</h4>'];

    $(years).each(function() {
        html.push('<select style="width: 11em;" ' +
            'onchange="document.location.href=this.options[this.selectedIndex].value;">');
        html.push('<option selected="selected">' + this + '</option>');
        $("#archives > ul > li:contains('" + this + "') > a").each(function() {
            html.push('<option value="' +
                $(this).attr('href')
                + '">'
                + $(this).text()
                + '</option>');
        });

        html.push('</select><br />');
    });

    $('#archives > ul').replaceWith(html.join("\n"));
}

Labels: , ,

Minor Website Updates

So, I stayed up way too late last night uploading version after version of this website. I updated the version of the syntax-highlighter I used on the one code sample I've posted. Nothing special there, but the fall-back when Javascript isn't enabled is nicer, as it's a pre-tag, instead of a text-area like before.

I fixed all the pages to have the extension .html instead of .shtml. The .shtml was leftover from when I used to use server-side-includes instead of a combination of Blogger templates & Webby layouts to handle common layout issues. Here's the content of the .htaccess file I used to make sure old links are given a permanent (301) redirect to the new extension:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.shtml$ /$1.html [R=301,L]

During the process, I noticed that Blogger wasn't producing an archive index page anymore. So I added archives to the sidebar for each blog. I made my css rules a bit more generic by making sidebar sections a class, instead of duplicating rules for different ids.

All of this took a bit longer than it should because any changes on the Blogger side required republishing the whole site (actually twice, once for the main blog, once for the politics blog). Whereas, for the non-blog content, I could run Webby locally, rsync it to my VirtualBox Ubuntu Server VM, and test it locally. So my next task is to figure out how to turn an export of this blog into Webby source files so that I can manage the whole process locally (and get my blog posts into version control as a bonus).

Labels: , ,

Thursday, October 16, 2008

Twitter

Despite the utter wasteland that is this blog, I've decided to start posting to yet another place on the internet: Twitter. The theory goes that if you're interested in knowing the minutiae of my life, you can follow me on Twitter (or subscribe to my Twitter feed or what have you). I, knowing that everyone looking at my Twitter posts has implicitly consented to being bombarded with inane details about my day, can safely post such details with the concern of them being "blog-worthy", or even "Facebook-status-worthy".

Now, if only I can do something interesting, I may have a reason to post something to my blog again...

Labels: ,

Thursday, June 19, 2008

Unmaintained Web Applications

This week I'm having to finally end my use of two web applications from major vendors. Bloglines had several of my feeds not update properly from June 3 through June 17th. I still haven't received any follow-up e-mail regarding the issue. Besides, for a feed-reading application, you'd think Bloglines could manage to communicate to its users through, I don't know, some kind of syndicated XML feed? On the 16th I was fed up with the lack of a fix, and the lack of a response, so I switched over to Google Reader. Sure, on the 17th Bloglines finally fixed the issue, but it was way too late by then. Getting my 309 feeds into Google Reader went fairly smoothly; a few folders weren't created so I had make the folders and place the feeds back into them. I'll miss Bloglines true "keep unread" or "pinning" feature, as well as the ability to group posts by the feed when reading a folder. But I'll get used to Google Reader's way of doing things if it means a reliable service that doesn't feel abandoned, despite its ownership by Ask.com. Plus I'll also get a better feed sharing mechanism, and finally have a Feed Search that works (despite Bloglines being owned by a search company, there's was never helpful).

The same basic experience repeated itself this week, this time from Yahoo. While the majority of people use del.icio.us for online bookmarking, I'd jumped on Yahoo's other service: My Web, mostly because it saved the page contents for you to search through in addition to the page title and tagging. However, a month or so ago, the RSS feed for my public bookmarks started showing junk. That was fixed within a week, but it started happening again this week. Now I can't even log in to the site. I filled out some tech support form I found on Yahoo (not that easy to find), but I've gotten no response. I've been able to access the bookmarks through another view (Yahoo's "My Bookmarks"), exported them, and am now importing them to del.icio.us. Hopefully Yahoo will maintain that a little better.

I guess in once sense this is same feeling everyone who bet on one of several competing technologies and lost feels. There were real benefits that led me to pick the apps I did, but the world didn't agree, and now I've paid the price for sticking with losers too long. Luckily some level of data portability has made that price a lot lower than it could have been.

Update: There are two new feeds you might want to track due to this change:

  1. My del.icio.us bookmarks
  2. My Google Reader shared items
You can also get these changes automatically using my all-in-one Yahoo Pipes feed.

Labels:

Saturday, February 23, 2008

Job Change

You know my blog's neglected when I don't even think to announce a change of job until the weekend after starting at the new place. On Monday I started working at Cormine Intelligent Data.

Thursday, February 14, 2008

Definitely, Maybe

I just watched Definitely, Maybe with Diane as our Valentine's day thing. It was fantastically cute and sweet. Ryan Reynolds was funny and charming, as usual. Isla Fischer was very likeable and adorable. Abigail Breslin, however, stole the show as the precocious and completely sweet daughter. I found the movie very enjoyable, though I am a total sucker for all forms of romantic comedies.

Sunday, April 22, 2007

EasyMock-PropertyUtils 1.1 Released

I have released EasyMock-PropertyUtils 1.1, and it's available in the Maven repository or for download directly. If you have issues, post them at the Google Code site, or ask at the Google Group/Mailing List.

The main changes from 1.0 are:

  • Ability to match against an object
  • Static matcher methods are renamed to propEq

Labels:

Sunday, April 01, 2007

April Fool's Day Banned

Due to significant decreases in productivity, the United Nations announced today that it was banning April Fool's Day. They also cited human rights violations, stating that the shame felt by those who were fooled infringed upon the inherent dignity of all human beings. A follow-up proposal to categorize all practical jokes as torture under the Geneva Convention is still under deliberation.

Labels:

Thursday, November 16, 2006

EasyMock-PropertyUtils 1.0 Released

I've released EasyMock-PropertyUtils 1.0, and it's available in the Maven repository. If you have issues, post them at the Google Code site. If you use it, just post a comment here to let me know.

Labels:

Monday, October 23, 2006

Tony Romo

While I've been frustrated by Bledsoe's consistency, I was never among the Dallas Cowboy fans that was calling for Tony Romo to replace Bledsoe. I didn't think an unproven quarterback could make much difference. But the drive I just watched Tony Romo lead was very impressive. No matter how tonight's game finishes, I see Romo as the quarterback for the Cowboys for the rest of the season. The biggest benefit: it looks like Dallas games will be more exciting on the offensive end.

Update: Well, Romo made enough mistakes to make my prediction that he will be the QB the rest of the season questionable. I think I'd still prefer Romo, but I'm not sure if Bill Parcells will agree.

Labels:

Saturday, October 21, 2006

Steve Yegge: On Programming Better

I've recently finished reading all of Steve Yegge's blog-rants. The overarching theme is Steve searching for ways to do better at software development. For instance, Being the Averagest on why many programmers aren't trying to get better, and Practicing Programming on how to get better for those who listened and decided they want to try. He also chronicles his search for a better programming language. I suggest reading all of the essays; hopefully they'll inspire you to be a better programmer, and you can take advantage of the work "Stevey" has done to guide you down the path of improvement. Stevey wrote all these articles while working at Amazon; make sure to also check out his current blog now that he works at Google.

Labels:

Saturday, September 30, 2006

Scott and Dana's Wedding

My brother, Scott, just got married last night. Congratulations Scott and Dana!

Labels: ,

Friday, September 22, 2006

Announcing: XPath-Replacement Maven Plugin

I'm looking for feedback on my XPath Replacement Maven Plugin. It's barebones right now; please send me any ideas you have on how to make it better, or just let me know if you'r even interested in it. The goal of the plugin is to allow you to do configuration (similar to normal Ant/Maven filtering), but without requiring placeholders so that your source version has a valid value that let's a developer get going straight from source.

I also updated the EasyMock Property Utilities site to include the example posted here on the blog.

Labels:

Sunday, September 17, 2006

EasyMock-PropertyUtils Example

Here's the promised example of how to use my EasyMock-PropertyUtils library. It's a TestNG test class with two test methods. The first, testSayHelloTo() uses the single-property matcher test. The second, testSay() uses the multiple-property matcher test by supplying a Map of property names to property values. If you haven't used EasyMock before, this should also serve as an example of how EasyMock can allow you to unit test in isolation a method that interacts with another class. Check out the EasyMock Documentation for more information.

package test;

import static com.stephenduncanjr.easymock.EasyMockPropertyUtils.propertiesEq;
import static com.stephenduncanjr.easymock.EasyMockPropertyUtils.propertyEq;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;

import java.util.HashMap;
import java.util.Map;

import org.testng.annotations.Test;

/**
 * Test the Service class.
 */
public class ServiceTest
{
    /**
     * Test the sayHelloTo method.
     */
    @Test
    public void testSayHelloTo()
    {
        String address = "someone@example.com";
        MessagingService messagingService = createMock(MessagingService.class);
        messagingService.sendMessage(propertyEq(Message.class, "address", address));
        replay(messagingService);

        Service service = new Service();
        service.setMessagingService(messagingService);
        service.sayHelloTo(address);

        verify(messagingService);
    }

    /**
     * Test the say method.
     */
    @Test
    public void testSay()
    {
        String address = "someone@example.com";
        String text = "some text";

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("address", address);
        properties.put("message", text);

        MessagingService messagingService = createMock(MessagingService.class);
        messagingService.sendMessage(propertiesEq(Message.class, properties));
        replay(messagingService);

        Service service = new Service();
        service.setMessagingService(messagingService);
        service.say(address, text);

        verify(messagingService);
    }
}

Labels:

Announcing: EasyMock-PropertyUtils

I've created a new open-source project: EasyMock-PropertyUtils. Basically, this library allows you to use JavaBeans-style property matching for arguments when using EasyMock. I plan to add some end-user documentation and blog some more about both EasyMock and this project soon. This is being done separately from EasyMock because it's use of non-refactoring safe strings doesn't fit the philosophy of EasyMock. The project is quite small, and I have no idea what the interest-level will be, so I'm just hosting it alongside the rest of my personal projects on my Google Code Hosting site. Hopefully there isn't something like this already out there that I missed.

Labels: