Fork me on Github s

Git cheatsheet

Bookmark this sweet visual aid for git. Nicely done!

git cheatsheet


Tags: ,

No Comments

Connecting to Magento Web Services with Java

I was in the unenviable position of needing to connect to Magento, a PHP ecommerce platform, web services using Java.  It was kind of difficult to get the classes generated from the WSDL so I figured I would throw the results up on my github account for any other poor sap in a similar position.

First, pull down the project using git:

git clone git://

and build it with maven:

mvn install

Here is a quick example of how to pull an order using the generated classes:

MagentoServiceLocator serviceLocator = new MagentoServiceLocator();
String url = "";
Mage_Api_Model_Server_V2_HandlerPortType port = serviceLocator.getMage_Api_Model_Server_V2_HandlerPort(url);
String sessionId = port.login("username", "key");
SalesOrderEntity salesOrder = port.salesOrderInfo(sessionId, orderId);

I also have some wrapper code in there that makes it a little easier to call the API.

Checkout the project at

There is another option. it’s called Magja and it is located at google code.

Tags: , , , ,

No Comments

What are the downsides to using dependency injection?

I recently came across an interesting question on stack overflow with some interesting reponses.  I like this post for three reasons. First, I am a big fan of dependency injection, it forces you to decouple your code, create cohesive interfaces, and should result in testable classes. Second, the author took the approach I usually do when trying to evaluate a technique or technology; suspend personal feelings and try to find some compelling arguments against it. Third, it proved that it is very difficult to come up with a compelling argument against dependency injection.

What are the downsides to using dependency injection?

Tags: , , , , ,

No Comments

Use CSS Selectors with HtmlUnit

HtmlUnit is a great library for performing web integration tests in Java.  But sometimes node traversal can be somewhat cumbersome. Fear not fellow automated tester (good for you!).  I found a great little project on Github that will allow you to query your document for elements via css selectors similar to jQuery.

The project is located at  You can use Maven to build it, or download 1.0.2 here.  Beware.  I will not be updating this link so I suggest you download the latest code.

In any case, you can use it like so:

    // from HtmlUnit getting started
    final WebClient webClient = new WebClient();
    final HtmlPage page = webClient.getPage("");
    final DOMNodeSelector cssSelector = new DOMNodeSelector(page.getDocumentElement());
    final Set elements = cssSelector.querySelectorAll("div.section h2");
    final Node first = elements.iterator().next();

    assertThat(first.getTextContent(), equalTo("HtmlUnit"));

The only problem here is that the querySelectAll returns a Set<Node>.  Not HtmlElement like we may want in some cases.   However, if you were to reflect on the Set, you would find that it is indeed a Set of HtmlElement objects.

Typically, I like to create a base class for my web tests.  Just for fun, I am using the $ method similar to jQuery.

public class WebTestBase {

    protected WebClient webClient;

    protected HtmlPage htmlPage;

    protected void goTo(final String url){
        return (HtmlPage)webClient.getPage(url);

    protected List $(final String cssSelector) {

        final DOMNodeSelector cssSelector = new DOMNodeSelector(htmlPage.getDocumentElement());
        final Set nodes = cssSelector.querySelectorAll("div.section h2");

        // for some reason Set cannot be cast to Set?
        final List elements = new ArrayList(nodes.size());
        for (final Node node : nodes) {

        return elements;

Now we can write tests like this:

public class LoginWebTest extends WebTestBase {

    public void login_page_has_instructions() throws Exception {

        goTo(baseUrl + "/login")

        assertThat( $("p.instructions").size(), equalTo(1) );

1 Comment

My 2011 Professional Development Goals

I thought it might be a good idea to post some professional goals for 2011.  Hopefully, I can look at this list at the end of the year and have accomplished most of them.

  1. Release an Android app to the marketplace – I figured I would put this first because I have one that I have been working on for a while and it is about ready.  Along with this, I would like to start another one and continue to develop my Android skills.
  2. Contribute free software to the community – Again, I have an SMF plugin that will fill this requirement nicely.  Just need to give it some polish and release it.  That’s not all, I would like to add a few more libraries on github, or possibly contribute to an open source project.
  3. Regularly attend a user group meetings outside of Java – A great way to meet people and learn new things.
  4. Obtain the Oracle Certified Web Developer Certification – I got the SCJP a few years ago and would like to obtain another one.  One step closer to Certified Enterprise Architect.
  5. Learn scala – As a language geek, I like to stick to the Pragmatic Programmer’s ‘learn a new language every year’ rule (last year was Ruby).  Scala presents some new concepts all wrapped in a JVM-based OOP language.  Time to dig in.
  6. Write an app using JSF – New JEE 6 features are pretty slick.  I want to really leverage them in an app.
  7. Present at a user group meeting – Last but not least, I would like to improve my public speaking and skills in presenting.  Also, is a great reason to dig in to some latest and greatest tech.
  8. Use git more, and more effectively – Trying to move all my personal projects from Subversion to Git.

That’s it.  A little daunting, but I am confident I can at least touch on most of these and it’s a great roadmap to my professional development.


AJAX Loading Images

Need a fancy animation for your AJAXy page?

Check out:

No Comments

Using Java classes in JRuby

I needed to do some reflection today so I fired up interactive JRuby (jirb) to inspect a jar.  Surprisingly, I couldn’t remember exactly how to use Java classes in JRuby.  So I did some searching on the internet and found this to be a common question with many answers.  So I figure I will document it here in case I forget how in the future.

Add it’s folder to the load path, require it, then use it!

$: << '/path/to/my/jars/'
require 'myjar'

# so we don't have to reference it absolutely every time (optional)
include Java::com.goodercode

my_object =

Tags: ,

1 Comment

Zune API Library for Ruby

Those of you who know me, know my favorite music player is the Zune.

For some reason it seems most of my spare time lately seems to be creating Zune API libraries for different languages (I have a PHP one as well).  Here’s another one for Ruby!  If you use it, let me know.  I would love to hear what people are working on.

It’s hosted at github, and very easy to use.

zune_card = Zune::ZuneCard.for('a_zune_tag')

Checkout the README for deets on what fields the object will have.

Tags: , ,

No Comments

Graffiti is a Sinatra-inspired Groovy Framework

Playing around with Sinatra the other day and realized I could really use something like this for Groovy. Thus, Graffiti was born. It’s basically a thin wrapper around Jetty. At first, I thought I might write my own server for it (everybody needs to do that once, don’t they?), but decided to invoke the ‘simplest thing that could possibly work’ principle.

Here is the requisite ‘Hello World’ example:

import graffiti.*

def hello() {
  'Hello World'

Graffiti.serve this

The code, plus more documentation is hosted under my github account.

Tags: , , ,


Zune API Library for Python

I am about to start working on a Python project for work. So I thought it was probably time to learn Python! This weekend I took on this task. I decided to rewrite a library I wrote in PHP to access Zune user data. I got it finished and decided to put it on github.

Usage is simple:

zuneCard = ZuneCard('ZuneTagHere')

You can access things like user information, favorites, recent plays, and most played. The properties are documented (pydoc, under /docs). So for the 1 other person that may use this, you’re welcome!