Fork me on Github s

Archive for category Developer Tools

Automatically keep your local git repos clean

Most developers using git are probably aware of a command ‘git gc’ that has to be run from time to time when you notice your git commands are running a little slow. This command cleans up your git repo and makes sure everything is nice and tidy. If you have not run this command lately, you will notice a huge performance increase in your git commands after running. It’s a bit annoying to have to run this command when you notice that your git performance is suffering. The command also takes a while if you have not run it recently. With this in mind, I decided to create a method to automatically run this command from time to time. So I decided to overload cd similar to how rvm does. All you have to do is paste the method in your .profile file and it will run the command every time you enter a directory with a git repo.

Here it is in all it’s glory.

Tags:

No Comments

Spring Roo Database Reverse Engineer with Oracle

So you are trying to reverse engineer an Oracle database with roo?

Unfortunately, due to licensing restrictions with the Oracle JDBC Drivers, this is a little difficult. There are a few blog posts and forum threads that address the problem but I figured I would post what worked for me here.

First, you need to download the appropriate Oracle Drivers from Oracle. The required login, stringent password requirements, nosy registration form, and general system instability made this a pretty painful step for me. I’d also like to say that companies that have password requirements that don’t allow symbols (or any other non-standard requirement) have a special place in my heart. Having to recover my password every time I go to your site virtually guarantees I will only go there when I absolutely have to (not often). Anyways, once you have it downloaded you need to install is with maven:

mvn install:install-file -Dfile=~/Downloads/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -DgeneratePom=true

Here comes the fun part. You need to create an osgi wrapper for the driver to install it in roo. Otherwise, roo cannot see the driver. Create a new folder and put the contents of the oracle roo addon pom gist I created. Now build it with maven. You may want to change some of the artifact ids and dependencies for your particular situation.

mvn package

No open a roo shell and execute the following command:

osgi install --url file:///Users/me/my-osgi-project/target/the-jar-it-built.jar

Now run (in roo):

jpa setup --provider HIBERNATE --database ORACLE 
dependency remove --groupId com.oracle --artifactId ojdbc14 --version 10.2.0.2
dependency add --groupId com.oracle --artifactId ojdbc6 --version 11.2.0.3
database properties set --key database.driverClassName --value oracle.jdbc.OracleDriver
database properties set --key database.url --value jdbc:oracle:thin:@%YOUR_CONNECTION_INFO%
database properties set --key database.username --value %YOUR_USERNAME%
database properties set --key database.password --value %YOUR_PASSWORD%
database reverse engineer --schema %YOUR_SCHEMA% --package ~.domain

If you have any package loading exceptions when running the reverse engineer command you can uninstall the osgi bundle, set the package to optional in the osgi pom in the IncludedPackages tag (javax.some.package.*;resolution:=optional) rebuild, then reinstall in roo.

Tags: , , ,

6 Comments

SubCut Scala Dependency Injection Framework

It’s no secret I am a fan of dependency injection.  So I was happy to hear that Dick Wall of the Java Posse recently released a dependency injection framework for scala.  Called SubCut, or Scala Uniquely Bound Classes Under Traits, the project is a ‘mix of service locator and dependency injection patterns designed to provide an idiomatic way of providing configured dependencies to scala applications’.

It’s hosted on github, so ‘git’ (rimshot) over there and try it out:

Dependency injection framework for Scala

Tags: ,

No Comments

Strict Pomodoro and other time management Chrome extensions

I have recently begun using the Pomodoro Technique to increase my productivity. However, I still find myself getting sucked in to the vortex of useless information that is the internet. With that in mind I began searching for a useful chrome extension to replace the Android Pomodoro app I have been using to manage my ‘doros. I even considered writing it myself. Luckily, I stumbled on one that had a similar featureset to what I was looking for.

Strict Pomodoro is an excellent Chrome extension for practicing Pomodoro. Though lacking a few key features, such as the ability to set the duration of your pomodoros and breaks, it still has a key feature that helps me stay on task. It blocks time sucking websites. You can set filter lists and it will keep you from accessing them during a Pomodoro. Effectively reminding you to stay on task. Also, the author readily admits that it was quickly put together and new features may be added down the road. For now, it is still an excellent option.

For those of you who do not practice Pomodoro but are trying to stay on task. The StayFocusd extension will effectively manage the amount of time you spend on useless (non-productive) sites. It also has a rich feature set that may be better for your work habits.

OK, breaks over. Time to get back to work. 25 minutes at a time.

Tags: , , ,

No Comments

Host your own private git repository via SSH

If you are like me you have tons of projects you would like to keep private but track with git, but do not want to pay a git host for a private plan. One of the problems is that most hosts scale their plans by project instead of users. Luckily, it is easy to host your own git repositories on any el cheapo host that provides ssh access.

In the interest of full disclosure, I learned this trick from this blog post. I decided to recreate it in case the source material vanishes for some reason.

To setup your host, login via ssh and run the following commands:

mkdir ~/git/yourprojectname.git
cd ~/git/yourprojectname.git
git --bare init

Then in your project directory (on your local machine):

# setup your user info
git config --global user.name "Firstname Lastname"
git config --global user.email "your_email@youremail.com"

# initialize the workspace
git init
git add .
git commit -m "initial commit"
git remote add origin ssh://youruser@yourhost.com/~/git/yourprojectname.git
git push origin master

It’s that easy!

To keep from entering your password every time add your public key to the server:

Generate your key with ‘ssh-keygen -t rsa‘ on your local machine.  Then add the contents of the generated file to ~/.ssh/authorized_keys on your server.

Tags: ,

4 Comments

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://github.com/webdevwilson/magento-java.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 = "http://domain.com/index.php/api/v2_soap";
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 https://github.com/webdevwilson/magento-java

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

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 https://github.com/chrsan/css-selectors.  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("http://htmlunit.sourceforge.net");
    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) {
            elements.add((HtmlElement)node);
        }

        return elements;
    }
}

Now we can write tests like this:

public class LoginWebTest extends WebTestBase {

    @Test
    public void login_page_has_instructions() throws Exception {

        goTo(baseUrl + "/login")

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

}
1 Comment

AJAX Loading Images

Need a fancy animation for your AJAXy page?

Check out: http://www.ajaxload.info/

No Comments

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