Tuesday, December 9, 2008

Jolly Old Mathematics

So I was reminiscing with Jen about Helaman Ferguson and creative math, so I had to google for fun with math for this Christmas season. I found a few lists (this is probably the best one), but here are the specific activities that looked like the most fun out of the dozens I perused:


Happy Holidays!

---

While I'm here, I've got to mention two cool fractal sites, even though they're not Christmas-oriented:

Tuesday, November 18, 2008

a few notes about the Java ClassLoader

I found a case today where the clazz.getResourceAsStream(String) retrieved a resource but the clazz.getClassLoader.getResourceAsStream(String) failed to find it. Weird.

I never figured it out, but I came up with the following as I tried:

  • There is no way to get all the entire path that is being searched. I always come to this point and try, but it's a hard fact of Java. I did find this blog entry that explained how you might patch the ClassLoader.toString() methods. But read on...
  • Even for URLClassLoader classes, it looks like it'll search through directories that are not found by the getURL() method (so that previous blog entry won't catch them all). I found this by running some unit tests in Maven with the method that follows, and it was retrieving things from the 'classes' and 'test-classes' directories that didn't show in the getURL() results.
  • If you try a call to getResource(""), it'll show some of the directory paths that are in the search path. I don't know for sure that this is true because I can't find it documented, but it seems to work. So the following method will show all the URL and path resources up the line from a given loader:

private static void showAllResourcePaths(ClassLoader loader) {
try {
String indent = "";
for (ClassLoader nextLoader = loader; nextLoader != null; nextLoader = nextLoader.getParent()) {
System.out.println(indent + " loader " + nextLoader);
for (Enumeration<URL> urls = nextLoader.getResources(""); urls.hasMoreElements(); ) {
URL url = urls.nextElement();
System.out.println(indent + " path: " + url);
}
if (nextLoader instanceof URLClassLoader) {
System.out.println(indent + " URLs: " + Arrays.asList(((URLClassLoader) nextLoader).getURLs()));
}
indent += "-";
}
} catch (Exception e) {
e.printStackTrace();
}
}

  • Using that method will show you most of what you want because, in my tests, all the class loaders in the ancestry turned out to be URLClassLoaders.

What is the difference between the clazz.getResource and clazz.getClassLoader().getResource methods?

Monday, November 17, 2008

online to-do lists

I've been keeping my to-do list in a text file on my phone, and that together with my phone's calendar and my email are the things that pretty much run my life. Someday I'm sure that there will be a way to have all of those things integrated the way I want, most likely through an online service. To do so, they'll have to:
  • make it easy to make notes wherever I am, ideally with Jott
  • allow me to attach a "context" (and a time estimate)
  • integrate with a calendar
  • allow for task dependencies
Today I figured it was time again to check around and see if today is that day. It looks like it's not. The dependency feature is the hardest to find, and I'm a bit surprised it's still not very widespread. Here's some of the info I've gleaned from about a dozen sites:

Remember The Milk is integrated with Jott for free, which makes it most attractive for a trial; I'd like to try Hivemind for their dependencies, and I will if I do a paid subscription to Jott (eg. pay-as-you-go, because Jott is critical but I use it rarely).

Thursday, October 30, 2008

integration tests with Wicket and Spring

I had a bear of a time getting my Wicket tests to work with services injected by Spring.

I started with the helpful Wicket-Spring unit-test instructions here; this got me through a basic test. Unfortunately, I must use Spring-managed services from my main AuthenticatedWebSession class since I'm using the standard Wicket "Auth-Roles" security (simply, without Acegi); Wicket has a helpful way to tie with Spring when it comes to the WebPage classes, but this doesn't work for the things I'm using in the main WebApplication or WebSession classes.

I found another project that uses Spring's test class AbstractTransactionalDataSourceSpringContextTests as it's parent class, and this proved to be my salvation. Basically, I extend that class and add the following 2 methods:

protected ConfigurableApplicationContext createApplicationContext(String[] locations) {
context.setServletContext(new org.springframework.mock.web.MockServletContext());
context.setConfigLocations(locations);
context.refresh();
return context;
}

protected String[] getConfigLocations() {
return new String[]{"context/backoffice-webapp.xml"};
}


Then I have to override the "onSetUpBeforeTransaction" method instead of the traditional JUnit "setUp" method:


@Override
protected void onSetUpBeforeTransaction() throws Exception {

super.onSetUpBeforeTransaction();

AuthenticatedWebApplication authenticatedWebApp = new WicketApplication() {
@Override
public void init() {
addComponentInstantiationListener(new SpringComponentInjector(this, TestHomePage.this.applicationContext));
initForAppAndTests(); // this is where I set up my global services, called by WicketApplication.init() as well
}
};
tester = new WicketTester(authenticatedWebApp);
}

That made it all work.

BTW, although I'm using Spring 2.5.5, the latest spring-mock library is only 2.0.8.

Tuesday, October 21, 2008

Google GData APIs

This is just so I can find the Java API for Google GData. (Go ahead: try googling "gdata api" and see if you can find it that way. I dare you.)

http://code.google.com/apis/gdata/javadoc/

Note that it's linked from the "Client Libraries" page.

Update: you can find it easily in a Google search on: "gdata javadoc"

Tuesday, October 7, 2008

Wicket i18n and l10n

I'm playing with text properties in Wicket, and I found this good article on it (up to and including v1.4) by Erik van Oosten. You can see more technical details in Wicket's basic references on i18n and l10n.

What I'd really like is the ability to refer to other properties within a text property, but it doesn't appear to have that. I even tried to put it in, but it assumes you have an object with that name laying around, or at least an accessor ("get...") method with that name (up to the first ".") somewhere in your component hierarchy, so I cannot figure out how to hack that in. Yet.