Dell ASAP Software. @FAIL @UNBELIEVABLE FAIL

So I’m writing this as I sit on hold, waiting to get some information about the Adobe CS5 Premier Suite that I ordered a month ago.  I received some kind of license certificate in the mail with absolutely no instructions.  Of course I called Adobe, and these numbers mean absolutely nothing to them, so I’ve lost an hour there, mostly on hold.

So now I’ve been on hold with Dell for 15 minutes.  Do they have hold music?  NO.  They have some cheerful, clipped female voice that asks me to continue to hold, and then they try to sell me Microsoft Office.

Then they try to Sell me SQLServer.

Then Adobe Creative Suite 5.

Then they tell me they have 150,000 title for favorable bulk licensing programs.

Then they tell me that they work with Federal Agencies, and tell me to get in touch with software accounting.  Good to know in case I ever work for the government.

Then they thank me for holding, and tell me that they value my business.

Then the string of completely annoying commercials, over and over again.,

And again.

And again.

Whomever decided that it was a GREAT idea that they could try to sell me software and services while I’m sitting on hold frustrated with the purchase that I have already made is a complete dimwit.  I hope your boss (who I’m sure you gave this idea to thinking it would further your career is reading this)  because you made him look like a complete douchebag.

Test Driven Development — How to start with a test

Test driven development is mystical to anyone that hasn’t done it from the ground-up. It’s almost like riding a bike; you really don’t know how easy it is and how much fun you can have with it until you get up and going. When the training wheels are off, it then becomes a brand new world full of possibilities.

I have been writing unit tests for years. Having come to the Java game later than most of my colleagues, I really like to make sure that everything I commit to my various development communities are well-tested and as clean as I can make them. Unit testing has allowed me to verify this in two different ways. First, it guarantees that what I’ve writting works, and more importantly, it makes me keep my code simple. Frankly, if I start writing a test and it becomes a dependency-driven, closely-coupled to the implementation monster, I can pretty much guarantee that the code is going to be the same. I’ll try to refactor this and use my tests in this manner as a guage for it’s quality. Continue reading

A Simple “Restlet” Demo application

I’m assuming that if you’re here you already know the basics of REpresentational State Transfer.  I’m also going to assume that you’ve looked at all the goodies at the Restlet community site.  Further, I’m thinking that you want a quick start guide to show you how to implement it.  The following tutorial shows how I “found a home” with Restlet, what worked for me, and hopefully something that will work for you, too.

The Restlet API is a Java framework for the REST architectural style. The Noelios Restlet Engine (NRE) is available as the reference implementation, as well as several extensions to the API and to NRE. Continue reading

A Simple "Restlet" Demo application

I’m assuming that if you’re here you already know the basics of REpresentational State Transfer.  I’m also going to assume that you’ve looked at all the goodies at the Restlet community site.  Further, I’m thinking that you want a quick start guide to show you how to implement it.  The following tutorial shows how I “found a home” with Restlet, what worked for me, and hopefully something that will work for you, too.

The Restlet API is a Java framework for the REST architectural style. The Noelios Restlet Engine (NRE) is available as the reference implementation, as well as several extensions to the API and to NRE. Continue reading

Using Object-Oriented JavaScript to Create Multi-Use Tabs

Taking JavaScript More Seriously

As I migrated from basic HTML to JSPs and finally complex Server-Side Java, I became less and less respectful of client-side languages, and most of my colleagues were pretty much in lockstep with me. While working in the view layer, adding JavaScript was a tedious necessity, and most programmers I worked with built well-made, but structural, scripts to handle the needs of the page.  They knew what they wanted it to accomplish and they just wrote it to “do that thing”.  It “wasn’t worth” digging deep into it, because it is just “throw away” code that the view used; not really worthy of Server-Side Programmers’ attention. Continue reading

Using a prototype to extend your JavaScript methods.

The Problem: Calling a function many times throughout a particular JavaScript file or block.

JavaScript is often used to manipulate a variety of HTML objects on a page, i.e. to “show” or “hide” them, or perform some type of toggled functionality on a variety of buttons, divs, etc. It is not uncommon to see code like this littered in a variety of places throughout a typical large Script block:
if(foo == bar){
document.getElementById("blah").style.visibility="block";
document.getElementById("blue).style.visibility="none";
document.getElementById("red").style.visibility="block";
document.getElementById("black").style.visibility="none";
}
Implementing the above in numerous places throughout said block of Script with a couple of hundred lines can eat up a lot of space, be harder than all get out to maintain, and if the guy that wrote it gets hit by a bus, you can often watch the next engineer in line cry for days in front of their screen just trying to figure out what the original coder was thinking when they wrote it.

Continue reading

Ruby on Rails: Create a Select Drop Down from an Array

Problem: You wish to populate a “collection_select” box with an Array.

I recently had an issue where I wanted to create a select box populated from an array of continuous years. I wanted to use thecollection_select method so it would have a minimal “code footprint” and play nice with the form that I had built. The application that I’m working on is in Rails2 and I didn’t want to divert heavily or make to many changes, and after some fiddling I came up with a nice solution: In the environment.rb file I created an Array constant to contain the year range that I wanted to use:

#Constant Values
YEARS_ARRAY = Array.new(89) {|i| 1920+i}

This code is a shortcut to create an array of values between 1920 and 2008 (88 years). It creates a new array with a size of 88, and then uses the i value to populate each year incrementally. I was pleased to find a method like this!

The form declaration contained the object that I wanted to populate with the form values using the Rails2 syntax:

<table class=”new”>
<% form_for(@movie_poster) do |f| %>
 <tr>
<th>Title:</th>
  <td><%= f.text_field :title %></td>
 </tr>
…..
<% end %>
</table>

*note the newer Rails2 syntax for the form…

I will populate my select box with an Array of Objects. I need to create my Object first to populate my Labels and Values, and I used an “old trick” from Struts by creating a Ruby LabelValue object that mimics Struts LabelValueBean utility POJO. The object has a label and value accessor, which works extremely well for any set of arrays since any kind of mapping scheme would consume duplicate keys and often select boxes, radio buttons, etc may need some duplication. Here is my label_value.rb class, located in my model directory:

# Creates a Label and value for select boxes and
# forms without clearly delinieated# objects, such as Arrays.
class LabelValue
# name the accessors. Label and Value
attr_accessor :label, :value
end

Now that I have a model to work with and an Array Constant to use, I created the “helper” to use with the form tag in the application_helper.rb file, so I might use it throughout the application’s forms. There are two methods, one public, and one private. Note the “Select year” prompt:

# selection for a year value
# ‘f’ represents the passed in form value
def year_select(f)
f.collection_select(:year,year_lookup,:label,:value,{:prompt=>”Select year”})
end
# ———— PRIVATE METHODS —————–

private

def year_lookup
#create an emptycollection to hold the LabelValue Objects
years = Array.new()#populate the ArrayYEARS_ARRAY.each do |yr| y = LabelValue.new
y.label = yr
y.value = yr
years.push(y)
end
years
end

Finally, we need to call the _helper method from the form:

<tr>
<th>Grade:</th>
<td><%= grade_select(f) %></td>
</tr>

The resulting code renders a select box:

<select id=”movie_poster_year” name=”movie_poster[year]”>
<option value=””>Select year</option>
<option value=”1920″>1920</option>
<option value=”1921″>1921</option>
<option value=”1922″>1922</option>
<option value=”1923″>1923</option>
<option value=”1924″>1924</option>

# continues…

<option value=”2005″>2005</option>
<option value=”2006″>2006</option>
<option value=”2007″>2007</option>
<option value=”2007″>2007</option>
</select>

The nice thing is reusability of the LabelValue class, the YEAR Constant and the collection_select itelf. Everything can be accessed as it is needed, whether you want to use the Constant Array for something else, the LabelValue object for a different array or tuple, or the actual rendered select box in different views.

UPDATE, 1/15:

See the comments below for a nice alternative and discussion!

Struts vs. Cocoon: Why Cocoon lost the battle.

Cocoon has been around for years with an active development community. I tried to work with it in 2002 using the books and resources available at the time, but I was using Windows at that point and the books really focused more on a Unix/Linux deployment, and at the time I didn’t have the chops to really transfer this knowledge cleanly and was really never able to set up a coherent development environment for it. Struts, on the other hand, had the resources available to get up and running. Although the documentation wasn’t that great, I could “get home” on most issues, and when the level of frustration on completing some of the things that I needed to get done was at a boiling point, I did something about it and wrote a book with George Franciscus to share what I had learned with the larger community. I wasn’t alone with this either; many great books on the subject came out. As the framework diversified and solved many problems, so did the available web and print documentation from many wonderful people.

Step forward to today. Struts 1 is ubiquitous; nearly every Java Web Application Programmer has had some experience with Struts, building upon the base and working to create other Frameworks as well extend Struts1 into Struts2. Lately, I’ve been working with projects that consume a great deal of XML services and need to be available to many different viewing platforms in a coherent manner. Not only that, but there is a tremendous amount of conditional logic that must be matched depending upon input. Cocoon handles these things very well — it’s dispatch system allows for various URL matching which gives it’s configurations a very similar feel to a lightweight Business Rule engine. I decided to give it another shot and go through the tutorials and documentation — trying to evaluate whether or not it could fit into the way that my company does business.

I proceeded to find tutorials on the Cocoon Site, DeveloperWorks and other places. What I found was at best adequate, but at worst quite disappointing. The Cocoon Community insists that you download their source code and use their scripts to Continue reading

Creating a Java TesterTimer for Performance Testing.

I often find myself writing lightweight performance tests as part of a suite of the unit tests, to make sure that my code hasn’t been written in a way to destroy the performance of an application. I also create performance tests as a standalone Application to test (for instance) how many HttpServletRequest/Response calls can be made over a certain period of time.

My requirements are normally simple, and rarely have a strong need to be COMPLETELY perfect; i.e. the actual calls to and from the timer can cause a slight time loss in the actual application, but frankly I’m willing to put up with this in most circumstances. The “TesterTimer” class featured below is pretty damned efficient, especially if you never call the “elapsed(id)” method, since the start and stop happen pretty much outside the application being tested. Here is the fully commented code with a demonstration “main” class:

Continue reading

Adding a DRL FileType with Syntax Highlighting to IntelliJ

IntelliJ’s support of JBoss-rules in no way compares to Eclipse, but even that isn’t enough to get me off my butt and move from my fave. That said, I created a semi-literate FileType for the drl files so that IntelliJ will recognize them and you will get a decent amount of syntax highlighting. Is it perfect?

No.

But it will probably get you home. Here’s what you do. Create a new filetype and make sure that it includes ?*.drl files. Once that is created, it makes a filetype with the name you gave it in the

%User%/Library/Preferences/IntellijIDEA%your-release-version-here%/filetypes/%name_of_file.xml%

directory (at least that’s what it looks like on my Mac – I haven’t touched a windows box in years, but it should have some parallels.

Open the XML file and replace anything between the <filetype> nodes with:

Continue reading