Thursday, July 12, 2007

iPhones at Twitter

From the Twitter Blog:

As you might imagine, there are lots of expenses associated with employees--salary, health insurance, etc. In the grand scheme of things, buying 10 employees a fancy new iPhone is not a gigantic expense. However, arriving at the office on a normal weekday and discovering a brand new iPhone waiting for you feels like an extra fancy perk.


They bought each of their employees an iPhone. Granted, they only have 10, but come on, how cool is that?

Now granted; Orbitz gave me a BlackBerry, but that isn't nearly as cool is it? The BlackBerry is nothing more than a digital leash...

Monday, July 09, 2007

Top 25 Worst Tech Products of All Time

PC World's "The 25 Worst Tech Products of All Time" has the 3Com Audrey on their "(Dis)honorable mention" list. She didn't make the Top 25 at least.

I worked on Audrey at 3Com back in 1999. I saw where it and the company were going and got the hell out of there. There was no hope for it, and nobody was listening :(

Monday, July 02, 2007

Groovy Views in Spring MVC

I thought it might be fun to try and implement Groovy as a View technology in Spring MVC. Most people that use Spring MVC are familiar with the JstlView for Jsps, or the VelocityView for Velocity templates, and the far superior FreemarkerView for FreeMarker templates.

So, let's think about what we'd have to do to use Groovy to render views...
We'd need to be able to load a resource as a groovy script, bind some stuff to it (the request, response.getWriter as out), and evaluate it.

Well, it turns out it wasn't fun at all. In all of about 10 minutes I got it working and it was really boring...
Keep in mind that the code here is totally rudimentary, there's no caching or anything like that. Anyway, check it out...

public class GroovyView extends AbstractTemplateView {

private static final Logger log = Logger.getLogger(GroovyView.class);

protected void renderMergedTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response)
throws Exception {

Binding binding = createBinding(model, request, response);

GroovyShell shell = createGroovyShell(binding, request, response);

Resource resource = loadViewResource(request, response);

if (log.isDebugEnabled()) {
log.debug("resource: [" + resource + "]");
}

evaluateViewResource(shell, resource);
}

protected Binding createBinding(Map model, HttpServletRequest request, HttpServletResponse response)
throws IOException {
Binding binding = new Binding(model);
binding.setVariable("request", request);
binding.setVariable("out", response.getWriter());

return binding;
}

protected GroovyShell createGroovyShell(Binding binding, HttpServletRequest request, HttpServletResponse response) {
return new GroovyShell(binding);
}

protected void evaluateViewResource(GroovyShell shell, Resource resource)
throws IOException {
shell.evaluate(resource.getInputStream());
}

protected Resource loadViewResource(HttpServletRequest request, HttpServletResponse response) {
return getApplicationContext().getResource(getUrl());
}
}

OK, there's the implementation, how would you use it in Spring? Well you can combine it with a UrlBasedViewResolver.

<bean id="groovyViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="prefix" value="WEB-INF/views/">
<property name="suffix" value=".groovy"/>
<property name="viewClass" value="raykrueger.GroovyView"/>
</bean>

Really just follow any Spring MVC 101 example you can find on the internet and use the GroovyView here. Then you can create groovy scripts to use as views that look like...

builder = new groovy.xml.MarkupBuilder(out)

builder.html {
head {
title "Hi there"
}
body {
p "Hello from the GroovyView"
p "Neat Huh?"
a(href:'http://raykrueger.blogspot.com', "Ray Krueger's Blog")
}
}

Then you have all the power of Groovy at your fingertips to build views for your models. Accessing fields and looping iterators is a boatload easier in Groovy than in jstl. Though, honestly, you can do a lot of this stuff with Freemarker...

Now, I'm sure you can clean this up a bit and optimize the crap out of it (view caching and such). Really I just slapped this together as a thought.

Here's the source

OpenId updates to Acegi

I've promoted my first wave of changes to the Acegi OpenId support in the sandbox.
  • Added support for OpenId4java
  • Added OpenIdAuthenticationProcessingFilter to replace current Servlet+Filter approach
I'll remove the existing Janrain and servlet stuff once I've had a chance to try and build a sample using the new code.

Sunday, July 01, 2007

South African Chenin Blanc

This weekend my wife and I opened a bottle of "2005 Man Vintners Chenin Blanc" from South Africa. This rocked our socks off. We really enjoyed it. The wine was off-dry and very fruity, a fantastic summertime wine.

We had gotten into a rut of bad Rieslings and Pinot Grigios recently. I was feeling pretty down on the whole white wine thing again. Then we tried this Chenin Blanc; it really opened my eyes. We're definitely going to try a few more Chenin Blancs from South Africa (though nobody really has a huge selection of them). We might even try it's French cousin Vouvray. Vouvray is Chenin blanc from the Vouvray region in France. Rule number one for Chenin Blanc though, Don't by the crap we make in the US...