Wednesday, 14 November 2012

JAXB generation using gradle

Gradle XJC Ant Task

I had a problem yesterday with the gradle war task not picking up all our jaxb classes.
The build phase was correctly creating all the correct java files but wasn't including them all in the final war which was causing errors on our testing environments but not locally.
The reason they worked locally was because eclipse compiles its own classes rather than using your build tools copies.

The solution

Actually, i'll start with what the problem actually was. It turns out that gradle or one of its plugins is a bit too clever. We haven't added the generated sources to the source sets so really speaking we shouldn't have any compiled jaxb classes. However since we have a direct dependency on some of these classes it has included them for us.

The solution regardless is to add the generated-sources to the sourceSets.

Wednesday, 17 October 2012

Merge Sort

If you have an array of 8 elements, merge sort works by grouping these 8 into 4 sorted sets of 2. The sort is done through sibling pairs.

With these 4 pairs, you pair these with their siblings and take the first elements of each. Compare element 1 in both and place the lowest value in a third new array. You then compare element 1 with element 2 and place the lowest in the third array. This will go on until you are left with single pair merge sorting into a single final array.

Insertion Sort

Insertion sort works by maintaining a fully sorted list and inserting unsorted data one at a time then immediately sorting it.

So to begin with you have a single element, and that is considered sorted.
Then you add an item to the right of it. You compare these with each other and you might have to swap them. Then you have a sorted list of 2.
Then you add another item to the right of your list. You compare this with the one before it, if they're already sorted then you're done comparing for that iteration, otherwise swap them and move to the left. This goes on till you have no more data to insert.

Bubble Sort

Bubble sort is a simple sorting algorithm that compares the first two elements in the array and keeps hold of the largest, for each pass the largest will 'bubble' to the top. Each pass will require n-i comparisons.

This algorithm is considered O(N^2)

Sunday, 2 September 2012

Clojure multimethods

Defmulti

Defmulti defines a multimethod call, the methods don't need to be defined yet. It can be as simple as the following

(defmulti salutation :gender)

With this defined now, we can add conditions in the form of multimethods

Defmethod

To add a condition to this we can use the following

(defmethod salutation :f [_] "Madam")
(defmethod salutation :m [_] "Sir")

This allows us to make calls to the function and have it transparently dispatch to the correct function based on the gender keyword in the map.

(salutation {:name "Kirsty" :gender :f})
"Madam"
(salutation {:name "Josh" :gender :m})
"Sir"

Web Design

Web Dev

I've annoying been lumbered with some front-end web stuff lately. Generally, I protest vehemently at any suggestion of me doing front facing work but this task has got me a bit interested. It probably won't last.

Pseudo

There are two kinds of pseudo in CSS: pseudo-classes and pseudo-elements

Pseudo-classes

  • :link
  • :visited
  • :hover
  • :focus
  • :active
  • :first-child
  • :lang()

Pseudo-elements

  • ::first-line
  • ::first-letter
  • ::before
  • ::after

Tuesday, 21 August 2012

Classpath error snippet

File Not Found (Classpath Resource)

If this is encountered, either try modifying the classpath or prepending the file location with 'file://'