Feb
19

Create a Ridiculously Simple Status Image in a Java Servlet

We were recently working on a project at work that required we submit some data by appending a dynamic image tag with JavaScript. The data was transmitted in a GET request through a query string defined in the src attribute. We wanted to return a 1×1 image that could be tiled as a background image to indicate the status of the request. With such a simple image requirement, I wanted to find a more elegant solution than streaming an existing image from a file. My experience dealing with images in Java is extremely limited, and a quick Google search didn’t turn up a concise example, so this is mostly just here for reference (mine and others’).

BufferedImage buffer = new BufferedImage(IMG_SIZE, IMG_SIZE, BufferedImage.TYPE_INT_RGB);
Graphics g = buffer.createGraphics();
g.setColor(new Color(Integer.parseInt(success ? SUCCESS_COLOR : FAILURE_COLOR, 16)));
g.fillRect(0,0,IMG_SIZE,IMG_SIZE);

resp.setContentType(”image/png”);

OutputStream os = resp.getOutputStream();
ImageIO.write(buffer, “png”, os);
os.close();

IMG_SIZE in this case is 1 and assumes a square image. You’ll notice the parseInt method call specifies a radix of 16, so that allows SUCCESS_COLOR and FAILURE_COLOR to be defined as hex strings, which to a web developer are second nature.

Jan
10

Ice Storm

Northwest Express lift house after an ice storm Check out this photo, taken at Mt. Bachelor yesterday after a freezing rain storm hammered the northwest side of the mountain. This is the lift house at the top of Northwest Express lift! It’s not uncommon to see ice-covered chairs over there but this is ridiculous. It kind of reminds me of Superman’s fortress of solitude. Sounds like it will be a few days before they can crack the ice off the house and the towers to get this thing moving again (apparently Outback is the same story). Between the economy and the wacky weather, the ski resorts (at least here in the NW) must be having a tough season.

Dec
1

Think Big

After having recently audited a web application for proper character encoding support, I have one piece of advice for web developers in this area and that is: you should always support UTF-8 encoding across the board right from the start.

If you just take a few steps at the beginning of a project to enable Unicode encoding, you won’t ever have to worry about international character support, your application is “future-proofed.” When the time comes for your application to go global, it’s ready to go.

For example, if you use PHP you can set the encoding with the following statement in your php.ini file:
default_charset = "utf-8"

Or with Java set the following jvm setting:
-Dfile.encoding=UTF-8

In your Apache config file, set:
AddCharset UTF-8 .utf8
AddDefaultCharset UTF-8

You also need to set the database encoding to match up. In MySQL you can do this by setting the following directive in your my.cnf file:
default-character-set=utf8

It is important to note that you also need to specify the encoding for the connection. For a JDBC connection you can do this by adding the following parameters to the database URL:
useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8

Finally, if you are going to be sending emails from an application, you will want to specify the encoding in the Mime type as well. Using JavaMail, this can be done while setting the text of a MimeBodyPart:
mimeBodyPart.setText(htmlContent, MimeUtility.getDefaultJavaCharset(), "html");

If you make a concerted effort to implement the same encoding across the board, it will certainly help in the long run, as you won’t ever have to deal with character encoding issues.

For more information and specifics about UTF-8 encoding, visit UTF-8: The Secret of Character Encoding

Nov
1

Tools for Shooting Success

180 Shooter For the past couple months, I’ve been working on a web site for my cousin, basketball coach and author Brian McCormick. The site centers around his latest book, 180 Shooter: 5 Steps to Shooting 90% from the Free Throw Line, 50% from the Floor and 40% from the 3-Point Line.

180 Shooter Shot ChartMy favorite part of the job was creating the shot tracker program, which is an interactive shot chart, similar to the one shown at left. Coaches can input their players’ makes and misses with a rich user interface, tracking a wide variety of criteria such as opponent, quarter, shot type, etc. The coach can then report on the players’ shooting statistics, broken down by these criteria, and visualize that data in a heat map overlay. The result is knowing exactly where and under what conditions their players should take their shots.

There’s also a great individual practice program, which helps players follow along with the drills outlined in the 180 Shooter book. The program guides players towards practice in the necessary areas to improve their shooting. I would recommend for anyone wanting to become a better basketball shooter, you should check out this web site.

Oct
16

Multiplayer Email 2.0

Email Center Pro

For almost 2 years, I’ve been working on a product called Email Center Pro - anyone who reads this blog probably already knows that. It’s an email management solution for small to medium sized businesses that makes it super easy for a group of people to manage hundreds, even thousands of emails a day.

This is a big week, because we just launched version 2.0 of the software to our user base. The new version has a completely rewritten JavaScript client and makes use of an entirely new RESTful web services API. It’s got a lot of powerful new search features and introduces the dashboard which will soon allow users to customize their home page with analytics tools. 2.0 is a big step forward but it also lays the groundwork for the exciting things Email Center Pro will do in the very near future.

For anyone who has a web site, manages more than one email address, or has at least one other person involved with their business, I would whole-heartedly recommend this product. Sure, I may be biased, but I have seen first-hand the real gains in efficiency that it provides for an organization.

Jun
10

Carolina on my Mind

I’m happy to say that I’ll be heading out to Chapel Hill with Amanda for the rest of the week for a wedding. I’m very excited to get back to CH and of course happy to see all my friends again! Congratulations, Kate and Joel!

The Old Well

May
26

Memorial Day

As I’m sitting in stop-and-go traffic outside of Sisters, I’m thinking to myself the sad irony of the situation. It just so happens that this weekend of remembrance for our fallen soldiers is also one of the largest fuel consumption times of the year in America. Whether it’s cars, trucks, RVs or boats, Americans are guzzling gasoline today while our soldiers are dying in Iraq largely because of our nation’s dependence on foreign oil.

Memorial Day Traffic outside Sisters, Oregon

May
19

JavaScript iPhone Lock Slider with jQuery

I was thinking the other day about the amount of form spam that most web sites get (and again just now as I moderated a ton of blog comments), and I was reminded of a proof of concept I saw a while back. It required the user to utilize drag and drop functionality to submit a form, thus verifying human interaction. Then I thought of the iPhone’s unlock function and how it would make a cool CAPTCHA.

I’ve written a handy JavaScript class for including these types of sliders into a web site- stick around after the break for more details and cool configuration options.

Read the rest of this entry »