All posts by ajohnson

Delicious + Movable Type + Java

I’ve been keeping a list of interesting links in a text file for the last couple years and only recently thought better of it and started using del.icio.us to store links. And I wanted to show the links as part of this blog, but I wasn’t satisfied with just including their RSS feed of my links in blog (what happens when / if del.icio.us disappears?) so I whipped up a some code using the delicious-java library and the Apache XML-RPC library that extracts my delicious links from the previous day and then posts them directly my Movable Type blog using the XML-RPC API that comes standard with Movable Type. After putting it up on my server, I wrote a simple shell script that invokes the Java class and then popped that into /etc/cron.daily/ so that it will get called a nightly basis, voila!

#!/bin/bash
cd /usr/apps/delicious/
java -cp commons-codec-1.3.jar:commons-httpclient-3.0-rc2.jar:
commons-logging-1.0.4.jar:delicious-1.6.jar:xmlrpc-1.2-b1.jar:bin net.cephas.blog.DeliciousPoster config.properties

If you’d like to run it your own server, feel free to download the binaries (which include the source code), edit config.properties to match your Movable Type and de.licio.us profiles and scheduled it to run on a nightly basis.

Strategy Design Pattern applied to hashCode() and equals()

The latest issue of the JavaSpecialists newsletter (by Dr. Heinz Kabutz) features a lengthy look at possibility of applying the Strategy design pattern to the equals() and hashCode() methods commonly used in Java. In it he concludes that the equals and hashCode methods autogenerated by IntelliJ Idea are better from a performance standpoint.

If your IDE of choice doesn’t include the ability to autogenerate the bodies of the above mentioned methods, you might also check out the EqualsBuilder, HashCodeBuilder and ToStringBuilder classes in the Jakarta Commons Lang library.

Wildlife of Buzzards Bay

It’s getting warmer here in Mattapoisett, not warm enough walk on the beach in the evening without a jacket, but warmer nonetheless. Tonight I walked down to Brandt Island Cove with Jazz and took a couple snapshots of the things I’ve been coming across on our walks lately.

First, for the last couple weeks there have been at least two American Oyster Catcher (also here) birds on our small stretch of beach. They don’t let you get very close to them and I don’t have a great zoom lens, but they’re a distinctive breed: the large orange beak makes it stand out from every bird I’ve seen on our walks and it seems to prefer hopping to flying (it hops until Jazz spots it and chases it away). I’m only a novice birdwatcher, but apparently there are only about 7,500 of these birds left in North America, so I guess it’s a privilege. Here’s a quick snapshot I got of one of them:

america_oyster_catcher.jpg

Second, Jazz pulled either an Atlantic Stingray (Dasyatus sabina) or a skate (Raja eglanteria) out of the water yesterday, luckily she didn’t try to chew it up like she does everything else she finds on the shore.

atlantic_stingray.jpg

Finally, the sun was shining brilliantly on the water and I’m still no good at taking pictures, but maybe someone in a landlocked state will appreciate the view of the ocean:

brand_cove_in_may.jpg

and of this amazing tree that reminds me of a something you’d see under an electron microscope:

trees.jpg

Showing Google’s Web Accelerator the door using Java / ServletFilter

The guys over at 37 Signals posted an explanation of why they think the Google Web Accelerator is a bad idea and a link to a page which shows how you can disable the Google Web Accelerator by analyzing HTTP headers using Ruby. I’m don’t really care to discuss why you think the GWA is good or bad, but in case you think it’s bad, here’s the same thing implemented as a ServletFilter (here’s the same thing for ColdFusion):

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
  throws IOException, ServletException {
  HttpServletRequest httpreq = (HttpServletRequest)req;
  HttpServletResponse httpres = (HttpServletResponse)res;
  if (httpreq.getHeader("X-moz") != null &&
    httpreq.getHeader("X-moz").equalsIgnoreCase("prefetch")) {
    httpres.sendError(HttpServletResponse.SC_FORBIDDEN);
  } else {
    chain.doFilter(req, res);
  }
}

Add the following to your web.xml:

<filter>
  <filter-name>gwa</filter-name>
  <filter-class>com.mycompany.web.filters.GWAFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>gwa</filter-name>
  <url-pattern>/</url-pattern>
</filter-mapping>

and you’re good.

Paper Review: Two Case Studies of Open Source Software

The term paper for the class I’m taking (Paradigmatic Software Development) required that we write a review of a article that has appeared in a software engineering journal. I spent about 45 minutes trying to poke around the journal locator that UMass Dartmouth outsourced before giving up (they don’t let you search by topic, how lame is that?) and then remembering that Google has an academic focused search. Scholar.google.com found a bunch of articles about ‘open source’ and ‘software engineering’, I chose one entitled “Two Case Studies of Open Source Software
Development: Apache and Mozilla
“. My review of the paper is over 7 pages long, you can download the entire thing in MS Word format or read the extended entry below.
Continue reading Paper Review: Two Case Studies of Open Source Software

Merge multiples MP3 files into one

This last week someone sent me a CD with fifty 60 second tracks (it was a presentation that someone inexplicably saved as fifty separate tracks instead of one contiguous fifty minute block) that they wanted ripped into a single MP3. Ripping is easy with CDex and my initial google search left with with Audacity, which looked promising but I couldn’t figure out how to merge multiple MP3 files into a single file (using Audacity that is). Finally, I came across this little gem on binarybonsai.com, where a commenter mentioned that you can use the DOS copy command to append one files (or multiple files) to one another, creating one big file from many. Syntax is as follows:

> copy /b file1.mp3 file2.mp3 file3.mp3 end_result.mp3

which combines file1.mp3, file2.mp3 and file3.mp3 into end_result.mp3. The /b switch indicates that you’re copying binary files.