Filling in the Gaps

Java MidiSystem on Windows – No Sound

Posted by: Admin on: June 11, 2009

If you’re not getting any sounds from Java’s javax.sound.midi package on windows, you might just need a soundbank. You can download one here: http://java.sun.com/products/java-media/sound/soundbanks.html

Place the .gm file on the classpath, e.g. next to the JAR you’re running and you should have sound.

Stop maven downloading poms

Posted by: Admin on: May 3, 2009

Maven is often seems like it’s trying to download the entire internet when all you want to do is a simple rebuild.  This is slow! You can stop it doing this by running in offline mode with “-0″ e.g.

mvn package -o

Why do you get a compiler error about super() needing to be the first line in a constructor with this code?

public class Foo {
public void Foo() {
super();
}
}

answer after the jump…

Read the rest of this entry »

Getting the color of a pixel in an image in JavaScript

Posted by: Admin on: January 24, 2009

This is far from cross browser as it requires HTML 5 Canvas support, but might be fine for environments where you can target just supporting browsers.  Note that the same origin policy means you can only use this on images from the same domain as the javascript – you can’t just point it at any image url.  So here’s a basic example that will give you the RGB value for a pixel in an image.

<div id="result"></div>
<script type="text/javascript">
var url = "http://example.com/image.png";

var img = new Image();
img.src = url;

var canvas = document.getElementById(“c”);

var ctx = canvas.getContext(“2d”);

ctx.drawImage(img, 0, 0);

var xPoint = 10;
var yPoint = 180;

var data = ctx.getImageData(xPoint, yPoint, 1, 1);

document.getElementById(“result”).innerHTML = data.data[0] + “, ” + data.data[1] + “, ” + data.data[2];
</script>

References:

http://www.whatwg.org/specs/web-apps/current-work/#dom-context-2d-getimagedata

How to get the current controller or action in Grails

Posted by: Admin on: January 17, 2009

The current controller, action and id are available in params.  So this is as simple as ${params.controller} or ${params.action} in a view for example.  There is an open issue to make this easier, but it probably just needs better docs rather than a shortcut.

Passing Xmx to JUnit with Maven

Posted by: Admin on: January 15, 2009

If your tests are running out of memory when they run via Maven you can pass through the relevant JVM args, likely just -Xmx, in the pom, like this:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx512m</argLine>
</configuration>
</plugin>

MySQL errno 121

Posted by: Admin on: January 9, 2009

It’s not immediately obvious why you’d run into this when running CREATE TABLE – but it’s likely to be having foreign keys/constraints with the same name.  The constraint names need to be unique across the database.

Grails jobs

Posted by: Admin on: January 7, 2009

Grails has plenty of success stories, and is getting use on sites from sky movies to mashups to party dresses.  The job market for Grails is still in its infancy though – just 27 job ads in the last 3 months in the whole of the UK.    Coming under the Spring Source umbrella will help so it’s worth keeping an eye on that chart.

Is it going to kick off like rails?

How to show SQL queries in Grails

Posted by: Admin on: January 2, 2009

If you want to see the actual SQL queries Grails is using (via Hibernate) you can configure this in DataSource.groovy. Just add
loggingSql = true along with the driver and URL.

java.lang.Exception: No runnable methods – maven + junit

Posted by: Admin on: December 29, 2008

If you’re getting this error all of a sudden with a maven project that does have tests tests, most likely all it needs is a simple mvn clean test