Sublime Text Editor

By far the best text editor I have ever used is sublime text.

One of the best things about it is that it is available for free (you can and should buy it if you like it http://www.sublimetext.com) and it works on almost all operating systems.

One of the many many cool features it has is the ability to create and define it’s own set of “Build” systems. These can work based on the type of file that is open in sublimetext itself.

Madcow Test Automation

I helped to create an open source DSL based testing tool called Madcow. It relies on Webtest and java style .properties files to test webpages. There is also currently a second iteration of it which utilises Selenium Webdriver instead which is under continual development. Check it out here http://madcow.4impact.net.au or on github http://github.com/4impact/madcow.

For those of you still stuck using Madcow Classic however the following little build system script for Sublime may come in handy. It attempts to run the currently open madcow test against the “local” environment. It was made and tested on windows but it should work on both Windows and unix based machines.

{
    "cmd": ["runMadcow.sh", "-u", "local", "-t", "$file_base_name"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.java-props",
    "working_dir": "${project_path:${folder}}",

    "windows":
    {
		"cmd": ["runMadcow.bat", "-u", "local", "-t", "$file_base_name"],
    }
}

You can add it to Sublime’s Build System by simply clicking…

Tools -> Build System -> New Build System

pasting the above code and then doing

File -> Save As -> RunMadcowLocal.sublime-build

Then everytime you open a madcow test all you need to do is click F7 or Ctrl B to run it locally.

Encoding URLs in Java is quite trivial. However, too often I see people using the URLEncoder class for this. This is WRONG.

The URLEncoder class is used for encoding form data into xxx-form-urlencoded -format. Even though very poorly named, it does say this in the Javadocs ;)

The proper class for URL encoding is the URI class.

Lets assume we have an URL such as http://www.somedomain.com/shop/Awesome Sauces

If you encode this with the URLEncoder class, you get:

1
http%3A%2F%2Fwww.somedomain.com%2FAwesome+Sauces

Unreadable and incorrectly encoded. Reserved characters such as : and / should not be encoded. Also, the URLEncoder encodes empty spaces as a “+” even though it should be encoded as “%20”.

Which makes it really annoying and doesn’t end up matching up with what you would expect if you used javascript’s

1
encodeURI
and
1
encodeURIComponent()
method for example.

With the URI class, you get:

1
http://www.somedomain.com/Awesome%20Sauces

which is much better and correct.

To construct as simple URL like the example above with the URI class:

1
URI myURI = new URI("http", "www.somedomain.com", "/Awesome Sauces");

And to get the URL in an encoded format:

1
String url = myURI.toASCIIString();

If you want to do something like encode the functionality found in

1
encodeURIComponent()

Here’s a bit of a dodgy work around.

    private String getEncodedFileName(String filename) {
        try {
            def filelink = new URI("file","//", filename)
            return filelink.toASCIIString().replace("file://#",'')
        }catch (Exception e){
            return  filename!=null? filename:"";
        }
    } 

Recently wanted to install an older version of a homebrew formula…

After checking around on “StackOverflow: Homebrew install specific version of formula” thought I’d list out some of the steps for next time I need to do this.

Here goes:

Update the git repository containing homebrew formulas by running:

$ brew update

Choose the specific version:

$ brew versions scala
2.9.1    git checkout 53a1f0b /usr/local/Library/Formula/scala.rb
2.9.0.1  git checkout cb1ab23 /usr/local/Library/Formula/scala.rb
2.9.0    git checkout 4002978 /usr/local/Library/Formula/scala.rb
2.8.1    git checkout 0e16b9d /usr/local/Library/Formula/scala.rb
2.8.0    git checkout fdb41a3 /usr/local/Library/Formula/scala.rb
2.7.7    git checkout 6a18e38 /usr/local/Library/Formula/scala.rb
2.7.6    git checkout a82e823 /usr/local/Library/Formula/scala.rb
2.7.5    git checkout e9dd256 /usr/local/Library/Formula/scala.rb

For these to work you have to be in the working-directory:

$ cd /usr/local/Library/Formula

Execute the git code for your version:

$ git checkout 4002978 /usr/local/Library/Formula/scala.rb

And install:

$ brew install scala

If you’ve already install an older version, you may have to brew remove scala

You may need to do some funky git reset’s after this to get back to the latest versions too

Compiling Native Extensions under Xcode 5.1

Trying my hand of late with python and ruby and other bits and pieces but found myself hitting a lot of clang compiler issues when trying to install ruby gems etc on my mac, specifically this sort of thing:

compiling generator.c
linking shared-object json/ext/generator.bundle
clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make: *** [generator.bundle] Error 1

Luckily after some googling manbolo.com to the rescue, Xcode 5.1 it appears has changed something from a warning to an error as explained in more detail on the blog post here.

Anyway whack in an

export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future

and you should be right next time you try to

gem install pg

or of course you may need to do this if your using sudo

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install helios

Hope this helps you too.

Neo4j on EC2 quickly and easily

Want to setup neo4j database on a ec2 instance in record time? Follow the instructions here…

http://www.neo4j.org/develop/ec2