Software Steeplechase

Hayden Steep’s development obstacle course. (Java, JEE, and beyond)

February 12, 2008

TheLadders.com where not everyone can play, just the suckers.

Filed under: General

While watching the Super Bowl (go Giants!), I noticed a somewhat humorous advertisement for TheLadders.com
The ad was set at a professional tennis match, but everyone in the stands pulled out a racket and ran onto the court to join the game. The voice-over sounded “When you let everyone play, nobody wins.” A graphic then showed the company logo and the slogan “The most 100K+ jobs.” I made a mental note and just over a week later, decided to visit the website.

What I found was a business that picked up the torch of failed Super Bowl advertiser Pets.com that deserves the same fate.

1) I performed a search having chosen a field of industry and a regional location. 2) I was presented with a screen that forced me to create an account in order to see the job results. 3) I created an account and was able to see the job results. 4) I clicked on a job result and was told that I needed to sign up for a premium membership to view the job details.

I’m very hesitant to throw around platitudes like bait-and-switch, but after doing some Googling, it would seem the bad taste in my mouth was not unique, and that this particular .com has been annoying people for far longer than I’ve heard of them.

The icing on the cake (or should I say “slime”?) is that should you actually fork over money for viewing the same job postings that show up for free on other popular job boards… you will continue paying until you explicitly cancel your “subscription.”

Yes sir, it’s the Columbia House music club of job boards. When TheLadders.com prompts you to pay, it doesn’t read… “Which subscription plan would you like? 1 month, 3 month, etc.” It reads something to the affect of “How long would you like to subscribe? 1 month, 3 months, etc.” with smaller, italic print indicating you have to manually cancel your service, even if you only payed for 1 month.

TheLadders.com may be a very good resource, but the fundamentals of “duck-typing” come to mind when I visit their website. If it looks like a rip-off, smells like a rip-off, talks like a rip-off… it’s probably a rip-off.

November 13, 2007

Enabling Validation in Struts 2

Filed under: Java, Struts 2

I’ve been learning Struts 2 recently.

I spent too much time figuring out that in order to enable the framework’s validation behavior, your action classes must extend the ActionSupport class.

The documentation fails to mention this small fact. Maybe it’s common knowledge to experienced Xwork developers, but wasn’t to me. I was very excited to be writing my new web application using POJO’s that didn’t extend any classes, but it looks like you have to unless you feel like rolling your own validation utilities.

Before I started using Struts 2, I learned everything i could about it so that I could be productive with it right away. However, I’ve been learning too much about this framework via the TIAS (try it and see) approach.

I signed up for an Apache confluence account hoping that I’d be able to edit the wiki to supplement the documentation, but am not sure who to contact to get right permissions to the docs.

March 9, 2007

Preserving actual size when displaying 4x3 aspect ratios on a 16x9 TV/Monitor

Filed under: General

With prices continuing to drop, I’ve been looking into upgrading my television to a wide screen flat panel model. Besides high-definition, I’ve also been looking forward to an increase in raw size that a new TV will offer, but what constitutes an increase in size? A 32 inch television with an aspect ratio of 4 by 3 has a larger viewing area than a 32 inch 16 by 9 (wide screen) TV, since the dimension is that of the hypotenuse of the corners.


For example, if you were to ’stuff’ a 16x9 image into a 4x3 TV set, it doesn’t fit. You have to scale the image down in order to preserve the aspect ratio. This scaling down is what creates the letter boxing above and below the image. In the example below, you can see how a 36 inch television is capable of displaying a wide screen image that is the same physical dimensions that would result from a 32 inch wide screen TV displaying that image.

Screen-sizes alone are poor indicators of the raw picture size unless we are comparing television sets that have the same dimensions. So, in order to compare these apples and oranges, you need the idea of a scalar. A scalar can be used to bridge the gap between comparing the wide screen TVs with the televisions many of us are used to. In the previous example, our scalar would be 1.25 or %12.5 since you need a 4by3 TV that is %12.5 bigger than a wide screen TV in order to display the exact same picture size.

When displaying a 4x3 image in a wide screen TV, the same scaling takes place, but now it is the 4by3 image that is being scaled down to fit inside of the 16x9 aspect ratio of the wide screen TV. This results in the vertical letter boxing depicted below.

So if I upgrade to a wide screen TV, I surely don’t want to view a picture broadcast in a 4x3 ratio in a size that is physically smaller than the image I would have seen in my “old-fashioned” television. Therefore, what size wide screen TV do you need to ensure that the 4x3 images are at least as big as they were on your old set?

Tv Ascpect Ratios

1) When normalized with the 16x9 ratio, the 4x3 ratio becomes 12x9.
2) Using the good old Pythagorean theorem, we can find a hypotenuse of ratio 15 for the 12x9 (4x3) set, and a ratio of 18.358 for the 16x9 set.
3) Dividing 18.358 by 15 results in a scalar of about %122 or 1.22
4) To find the minimum size wide screen TV you would need in order to match the raw picture size of your 4x3 TV, just multiply the size of your 4x3 TV by 1.22.

For example, if you currently have a 27 inch television, you would need a wide screen TV that is at least 27 X 1.22 = 33 inches in order to prevent having a smaller image on your new TV set.

I hope you find this scalar useful when shopping for your new television/monitor so that you don’t end up with a smaller image than what you had!

October 25, 2006

Creating a servlet with a self-contained web server

Filed under: Java, JEE

For those of us who haven’t become guru’s at developing user interfaces in Swing/SWT/.NET or other technologies used to develop GUI’s, (in other words web developers), there is an easy way to leverage your JEE skills to create stand alone programs. Just create a web application as you normally would, but instead of deploying your creation to an application server, deploy the application server to your application.

Jetty WebServer is one such application server that can be instantiated inside of a Java program and configured to handle web requests on a certain port. When your application has completed its task, just stop the web server and your super-servlet will exit.

Here are the 4 basic steps to turning your server application development skills into client-application development skills.

Step 1: Constructor

The constructor instantiates an instance of the Jetty embeddable web server. It adds itself as the servlet that should handle all incoming requests on port 8111. It then starts the server.

    private Server server;
    private Context context;

    public ExecServlet() {
        server = new Server(8111);
        context = new Context(server, "/", Context.SESSIONS);
        context.addServlet(new ServletHolder(this), "/*");
        try {
            server.start();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

Step 2: Get/Post functionality

In the methods below is where your servlet will do whatever it is you want it to do. The programmer has the full power of the Java API and libraries at his disposal in order to launch a process, process user input, write files, etc.

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        if(request.getPathInfo().equals("/DoSomething")) {
            //Do Something and return a response.
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        if(request.getPathInfo().equals("/PostSomething")) {
            //Do Something and return a response.
        }
    }

Step 3: Executing

The servlet’s main() method instantiates an instance of itself and then launches a browser to point to itself. The code in the example is Windows specific, but some conditionals and a check of system properties can make the servlet operational in other operating systems.

    public static void main(String[] args) {

      ExecServlet servlet = new ExecServlet();

        Runtime runtime = Runtime.getRuntime();
        String[] cmd = new String[4];
        cmd[0] = "cmd.exe";
        cmd[1] = "/C";
        cmd[2] = "start";
        cmd[3] = "http://localhost:8111/";
        try {
            runtime.exec(cmd);
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

Step 4: All Done

Some process or user created condition will signal that the application has completed running, and now it is time to close up shop and stop the web/application server.

if (request.getPathInfo().equals("/finish")) {

    try {
      server.stop();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
}

October 4, 2006

Comskip Monitor - A Java service

Filed under: Java, General

I used to own a VCR, but it broke down in the year 2000 and I never looked back. I had the mind set that Television will rot your brain and that there was nothing on worth watching, yet alone taping.

A marriage, busy job, and 2 kids later, I’ve rediscovered the joy of Vegging Out in front of the boob-tube. However, during my 1 hour time slot for watching, there was rarely anything on worth watching. So, I finally took the plunge and configured a PVR (Personal Video Recorder) system. I research Tivo (subscription fees), vs a stand-alone computer hooked up to my television (noise/up-front cost) and decided upon SageTV.

SageTV allowed me to leverage my existing home computer. All I had to do was install a TV Tuning Card, the Sage TV software, and a wireless device that connects to my television. The initial cost was about the price of a Tivo, but I don’t have subscription fees and I don’t have a noisy computer in my den.

There is a 3rd party commercial skipping program called Comskip that can be run on recorded video files that creates a text file containing the time indexes where commercials appear in the videos. The only problem with this program is that it has to be run manually. Manual goes against the very ease-of-use nature of PVR devices, so I decided to author a program that would run as a service which would automatically run Comskip on video files as SageTV created them.

Thus, Comskip Monitor was born. One of the more interesting challenges was making use of the Java Runtime and Process classes.

  Runtime runtime = Runtime.getRuntime();
  Process process = runtime.exec(cmd);
  int exitCode = process.waitFor();

Despite my best efforts, the executed program “Comskip” would always hang about a minute into processing. As it turns out, Windows processes have a stdout, errout, and stdin. The buffers for these streams aren’t very big, and if you don’t consume the output streams, the process will halt until you do.

  Process process = runtime.exec(cmd);
  StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
  StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "OUTPUT");

  errorGobbler.start();
  outputGobbler.start();

  int exitCode = process.waitFor();

  //Stream Gobbler
  class StreamGobbler extends Thread
  {
    InputStream is;
    String type;

    StreamGobbler(InputStream is, String type)
    {
      this.is = is;
      this.type = type;
    }

    public void run()
    {
      try
      {
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line=null;
        while ( (line = br.readLine()) != null)
        {
          System.out.println(type + ">" + line);
        }
      }
      catch (IOException ioe)
      {
        ioe.printStackTrace();
      }
    }
  }

This JavaWorld article is the best resource I could find for explaining the intricacies of launching external processes.

Writing a Java service is a great way to learn about threading, process handling, and synchronizing blocks of code.

If you happen to be running a Windows based video recording software, I also recommend trying out Comskip Monitor.

Get free blog up and running in minutes with Blogsome
Theme designed by Jay of onefinejay.com