Thursday, March 24, 2016

GohuFont and IntelliJ

GohuFont is my new favorite font. It looks great in a terminal, but I was unable to get IntelliJ to recognize it.

After installing the TTF variant by Guilherme Maeda, linked from the GohuFont homepage (also here), it did show up in the list of available fonts:

Saturday, October 3, 2015

Validating XML against an XSD with xmllint

Quick reference for how to validate an XML document against a schema using xmlint:
  $ xmllint --noout --schema stats.xsd example-stat.xml 
  example-stat.xml validates
Here is what you might see for an invalid document:
  $ xmllint --noout --schema stats.xsd junk.xml
  junk.xml:1: element event: Schemas validity error : Element 'event': No matching global declaration available for the validation root.
  junk.xml fails to validate

Thursday, October 1, 2015

Groovy: Closure Currying Example

Really simple example of closure currying so I do not forget it and hope that it helps someone else:
def addTo = { Map m, String k, Object v ->
    m[k] = v

Map elements = [:]

addTo elements, 'a', 1

def addTo2 = addTo.curry(elements)

addTo2 'c', 3

assert elements == ['a':1, 'c':3]

Sunday, March 8, 2015

Comparing JSON Strings with Jackson

Here's a quick way to compare two JSON String using Jackson. While we could always do a simple String compare, this method allows us to keep the expected JSON in a readable format, such as pretty-printed in a test resource:

import com.fasterxml.jackson.databind.ObjectMapper

class JsonAssert {

    static ObjectMapper mapper = new ObjectMapper()

    static void areEqual(String json1, String json2) {
        def tree1 = mapper.readTree json1
        def tree2 = mapper.readTree json2

        assert tree1.equals(tree2)


The above can be called from an expect: or then: block in a Spock specification.

Saturday, February 14, 2015

Simple Shell Script for Maven Integration Tests

Here's a simple shell script it took me forever to add to make it easier for me to run an integration test with Maven:

$ cat ~/bin/it
mvn clean verify -Dit -Dit.test=$1
I just have to remember the test name now instead of repeatedly typing the above:
$ it MyIntegrationSpec

Sunday, November 30, 2014

Subversion: Recovering Password from Local Cache

Subversion: Recovering Password from Local Cache

If you've forgotten your Subversion password, you should be able to retrieve it from another machine where you've succesfully made a commit before.

If you look in the local cache for your server's authentication type, you should see a series a files with hexadecimal names.

For example, for a server using simple or basic authentication:

  $ ls ~/.subversion/auth/svn.simple
  2af94d688c4073220b0a6af1b5884861  887652dff29c33e3f09394ea7379fac9

If you then look in one of the file, you should see your password:

  $ cat ~/.subversion/auth/svn.simple/2af94d688c4073220b0a6af1b5884861 | grep -A 2 password
    V 9

The above commands and locations are for a Linux box, but something similar should work on other OSes.

Wednesday, November 5, 2014

Spock and Objenesis: Resolving IllegalAccessError

Spock and Objenesis: Resolving IllegalAccessError

When mocking some classes with Spock in one of the usual ways, we often may need to include cglib. We also have to add objensis as well.

In one our modules, the latter was removed, leading to the below type of error that did not directly point out the cause:

java.lang.IllegalAccessError: tried to access method<init>(Lorg/company/service/export/ExportRequest$Builder;)V from class$$EnhancerByCGLIB$$1969beb7
 at org.spockframework.mock.runtime.MockInstantiator.instantiate(
 at org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory.createMock(
 at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(
 at org.spockframework.mock.runtime.JavaMockFactory.create(
 at org.spockframework.mock.runtime.CompositeMockFactory.create(
 at org.spockframework.lang.SpecInternals.createMock(
 at org.spockframework.lang.SpecInternals.createMockImpl(
 at org.spockframework.lang.SpecInternals.MockImpl(

For our mocking, we would define the mock at the field level like:

    ExportRequest request = Mock()

After adding objenesis, the error was resolved: