Found in my server logs today:
"Mozilla/5.0 (Win32; U; FreeBSD 5.X i686; tw-TW; rv:1.0.0; hi, Mom) Gecko/20040604"
All posts by ajohnson
Sunset Pictures From A Beach Walk
About 3 miles from our home in Mattapoisett is this great piece of land donated by Paul Munn, now called the Munn Preserve. Chris and Sara introduced us to it a couple months back as a great place to take the dog and it is. Jazz (our labrador retriever) goes bananas when we turn onto the road that leads to the beach. Sometimes I think I enjoy it more than she does though. I took a couple pictures of the walk 2 weekends ago; it was near freezing, but the sun was setting just as we got to the beach (there’s about a 1/2 mile walk through the woods to get to the beach), which, with the sunset, painted pictures of the most amazing color:
It must have gotten really cold one night because there were these huge chunks of ice that washed up on shore; the only way I couldl describe them to Karen was ‘scalloped potatoes’:
And then there was this sunset:
which, if I had to choose a favorite color… well I’d pick all of them. All of these pictures made possible by Jazz, who won’t sit still long enough to get a picture of her:
You can view the entire set (good and bad) here.
Tomcat 5.0.x bug with dollar sign (and non ASCII characters)
Hoping to bring this to the top of the queue for anyone else that runs into this: if you put configuration information into your Tomcat conf\server.xml file and said configuration contains a dollar sign ‘$’, according to bugzilla [1,2], the dollar sign is interpreted and thus doesn’t show up unless you double up on it. So if you have a environment entry like this:
<Environment name="ftp.password" type="java.lang.String" value="amsdk$k23"/>
you’ll need to change it to this:
<Environment name="ftp.password" type="java.lang.String" value="amsdk$$k23"/>
to make it work with Tomcat 5.0.x (same thing applies to JNDI entries in server.xml). According to this comment, this issue probably will not be fixed because Tomcat 5.0.x is in maintenance and not in active development. Supposedly this behavior will be fixed in version 5.5.7.
An observation: if you’re running a business selling software, make the bug list open the public. There’s nothing better than being able to find a solution without having to spend an hour on the phone with a technical support person who is doing nothing more than searching the private bug list.
Tabbing Through Tabs
My boss asked me today if it was possible to tab through the tabs of a Firefox window (the only drawback to tabbed browsing is that you lose ALT-TAB). Turns out you can use CTRL-PAGEDOWN and CTRL-PAGEUP to tab through multiple tabs in a Firefox window, Which is nice. Some of the other ones I use without even realizing they’ve become part of my vocabulary are:
CTRL-T — open a new tab
CTRL-D — bring focus to the URL
CTRL-R — reload the current page
CTRL-F12 — bring focus to the google toolbar search box
There’s a nice list of keyboard shortcuts here.
I think you should have to memorize at least 12 keyboard shortcuts before you’re even allowed to use a computer. It kills me when someone uses a mouse to do something you can do in less than a second with the keyboard. Maybe someone can write a Pragmatic Keyboarding book or a Keyboarding Hacks books.
Maps.google.com Deconstructed
Joel Webber took some time to analyze the new google mapping application (which is amazing, every person I’ve showed it too thinks it’s one of the coolest things they’ve seen on the web recently). They do some really cool stuff with IFrames, JavaScript, XML, XSLT and PNG. Read it here.
Retrieving an RSS feed protected by Basic Authentication using ROME
Today I worked on a feature in a Struts web application where I needed to retrieve an RSS feed that is protected by Basic Authentication and then display the the results of the feed in a web page. I’ve heard alot about ROME in the past couple weeks, so I decided to try it out. It quickly passed the 10 minute test (downloaded rome-0.5.jar, downloaded jdom.jar, used the sample code from the tutorial on the wiki); I was able to retrieve, parse and display the results of my own feed in no time:
String feed = "http://cephas.net/blog/index.rdf";
URL feedUrl = new URL(feed);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
System.out.println(feed);
Easy. But that wasn’t my problem. I needed to be able to set the Basic Authentication header which is usually done like this:
String feed = "http://yoursite.com/index.rdf";
URL feedUrl = new URL(feed)
HttpURLConnection httpcon = (HttpURLConnection)feedUrl.openConnection();
String encoding = new sun.misc.BASE64Encoder().
encode("username:password".getBytes());
httpcon.setRequestProperty ("Authorization", "Basic " + encoding);
httpcon.connect();
.. // do stuff
httpcon.disconnect();
Turns out that the designers of the ROME library were pretty smart. In addition to including the XmlReader(URL url)
constructor, they also included a XmlReader(URLConnection connection)
constructor, which allows you to combine the two blocks of code I wrote above to make this:
String feed = "http://yoursite.com/index.rdf";
URL feedUrl = new URL(feed)
HttpURLConnection httpcon = (HttpURLConnection)feedUrl.openConnection();
String encoding = new sun.misc.BASE64Encoder().
encode("username:password".getBytes());
httpcon.setRequestProperty ("Authorization", "Basic " + encoding);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(httpcon));
Add this code to your Struts action, put the resulting SyndFeed
in the request scope (request.setAttribute("feed", feed);
) and then in the JSP:
<c:forEach var="entry" items="${feed.entries}">
<strong>${entry.title}</strong><br />
${entry.description.value}<br />
<fmt:formatDate value="${entry.publishedDate}" type="both" pattern="MMMM dd, yyyy" />
by ${entry.author} | <a href="${entry.link}">link</a>
</c:forEach>
So there you have it. I hope that makes it easier for someone else!
Paradigmatic Software Development: Week 1
I started my first UMass Dartmouth class last week, it’s called “Paradigmatic Software Development”. You can read all about the syllabus and course objectives here if you’re so inclined. Following are my notes from the first reading assignment (Chapter 1 of Object-Oriented and Classical Software Engineering):
· The book starts off with a story about a man who received a bill for $0 and after receiving it multiple times, he sends in a check for $0, which then proceeds to crash his bank account. Funnier still is that this story appears to be an urban legend. I’m sure the bigger point is that errors like the one mentioned are all too common, hence this course. In case the author ever reads this, there is a much better list of famous bugs on wikipedia; see also Off-by-one error, fencepost error.
· Definition: software engineering is a discipline whose aim is the production of fault free software, delivered on time and within budget, that satisfies the clients need. Additionally the software must be easy to modify when the users needs change.
· There are 5 aspects of software engineering: historical (a very low percentage of software products have been completed sucessfully), economic (tech ‘a’ is 10% better than tech ‘b’ so if we switch to using ‘b’ we should be able to complete project ‘x’ in 10% less time), maintenance (requirements, analysis, design, implementation, post delivery maintenance, retirement)
· Real life example of the life cycle model mentioned above: at Mindseye we a) met with the client to get the project [requirements], b) produced a features and functions document which was agreed upon before work started [analyis], c) produced the black lines / specifications [design], d) implemented the site [implementation], e) entered into support contract [post delivery maintenance] or existing resources took over the project. The one thing we didn’t do was design of the software itself, our design / specification document was made up mostly of an object model and black lines (similar to what most people would call information architecture).
· Maintenance often happens before the project is released ( because of changes to the design etc…). Only good software actually makes it to post delivery maintenance phase because bad software is thrown away well before that time (or is never implemented)
· The book at this points presents a trivial example of how encapsulation is “a good thing” by showing how it would be much better to use this:
public static final float salestax = 6.0;
than to insert 6.0
in multiple places in your code (obviously). The funny thing is that by using a float to represent sales tax, he unwittingly introduced a bug into his code.
· Average cost percentages per phase (requirements, analysis, design, etc..) has hardly changed over the 20 or so years (~20% to requirements, ~20% to design, ~35% to coding / unit testing, ~25% to integration) but much more interesting is the fact that more than 75% of the total cost of a project is related to post delivery, so anything that can reduce the amount of time and money that you spend in that phase should probably be closely looked at.
· requirements / design / analysis:
— fixing costs more when you find it later (if you’re using the classical software development model)
— techniques that help you complete the requirements / analysis / design phase better will help save quite a bit of money and time up front
· planning phase: Not included because planning is usually carried out all through the life cycle; mostly during the beginning of the project and the software project management plan
· testing: needs to be happening all the time althoguh the book seems to think more of a QA group than of unit / automated testing
· documentation phase? No because the documentation should be kept up at all times so there ahould never be a time when it is out of date
· Object Oriented
— strengths of OO: post delivery maintenance is easier because of information hiding, OO makes more sense when modeling (which should lead to higher quality software), encapsulation (OO is sometimes referred to as responsibility-driven design or design by contract), classical paradigm results in a set of modules that is conceptually a single uit, OO results in smaller largely independent units ,OO promotes reuse
— diff between OO and classical:
— OO has workflows, classical has phases
— OO starts integrating classes almost right away while classical doesn’t integrate modules until the design phase.
ProFTPD and jailing users
I moved all my sites to vpscenter.com a couple months back on Joe’s recommendation and I’m hosting sites for a couple buddies on it right now. One of the problems with opening your server up to your buddies is that, trustworthy as they may be, you don’t want them mucking around with the system by CD’ing up to places they shouldn’t be hanging out. The guys at VPS Center have provided a nice web-based app for the creation of FTP users, but you can’t lock down the users to a specific directory via the web. I did some research today and found out that you can edit the ProFTPD configuration file so that users are “jailed” (a ProFTPD term, not mine) into their websites and can’t muck around outside their own sandbox.
The configuration file lives on my system at /etc/proftpd.conf, open that puppy up and add:
DefaultRoot /usr/hosts/yoursite.com groupname
where /usr/hosts/yoursite.com
is the directory containing the site that you want to lock down and groupname
is the name of the group (usually the same as the username) that you want to restrict. Restart the server (/etc/rc.d/init.d/proftpd restart
) and the next time the user in question logs in, they’ll be automatically redirected to the ‘jailed’ directory and they won’t be be able to browse directories above the one you’ve established as the base.
On a related note, if it seems like your FTP connections take forever to establish, add:
UseReverseDNS off
IdentLookups off
to the ProFTPD configuration file as well (restart required). You’ll see a dramatic decrease in the amount of time it takes to make an FTP connection.
dropcash and Java
If you’ve ever needed to raise a couple bucks for a project, a birthday or a fundraiser, you should check out dropcash (by Andre Torres). dropcash lets you set up a personal fundraising campaign using paypal and TypeKey. The campaign can be dropped into your site using a simple JavaScript include just like Flickr or Google Adsense, but you can programatically access the status of your campaign using the XML feed. There are a couple different implementations of the API (COM, MovableType, TextPattern and ColdFusion, more…), but no Java so I wrapped up a Java version and a JSP version. JSP is simpler of the two:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<c:import var="dropcash" url="http://www.dropcash.com/campaign/ajohnson1200/test/xml"/>
<x:parse var="dropcashxml" doc="${dropcash}"/>
campaignid: <x:out select="$dropcashxml//@id" />
typekey_user: <x:out select="$dropcashxml//typekey_user"/>
receiver: <x:out select="$dropcashxml//receiver"/>
title: <x:out select="$dropcashxml//title"/>
goal: <x:out select="$dropcashxml//goal"/>
total_collected: <x:out select="$dropcashxml//total_collected"/>
description: <x:out select="$dropcashxml//description"/>
percentage: <x:out select="$dropcashxml//percentage"/>
Java less straightforward:
URL url = new URL("http://www.dropcash.com/campaign/ajohnson1200/test/xml");
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
uc.connect();
InputStream is = uc.getInputStream();
DocumentBuilderFactory docfactory = DocumentBuilderFactory.newInstance();
InputStream inputXML = url.openStream();
DocumentBuilder docbuilder = docfactory.newDocumentBuilder();
Document document = docbuilder.parse(inputXML);
Element campaign = document.getDocumentElement();
System.out.println("campaignid = " + campaign.getAttribute("id"));
NodeList nodes = campaign.getChildNodes();
for (int i=0; i
Download the full JSP and Java source code.
Enjoy!
It’s Officially Winter..
We got a relatively large dump of snow this past Sunday night and then experienced one of those bitterly cold and blindingly bright winter mornings that make the hour or two or shoveling all worth it. I snapped a couple of pictures (the one below is of the sun setting from our back porch) which you can see here.