Archive for April, 2007

The Ten

Sunday, April 29th, 2007

Kristi and I saw “The Ten” on Saturday night at the Boston Independent Film Festival – the premise of the movie is to create a sketch touching on each of the ten commandments. Each sketch is really funny with cameos from many actors. The sketches are often quite different, but like great Improv, they make callbacks to include characters and ideas from previous scenes. Great closing scene with the whole cast, great movie overall.

Check it out.

Loading and drawing maps with Ruby

Saturday, April 28th, 2007

Loading geographic map data and drawing maps is pretty easy to do with two Ruby tools – ruby-shapelib (to load the map data) and RImageMagick (to create the drawings).

I didn’t see any tutorials or sample code, so I’m posting this sample as is – it will draw every shape part of every shape in a given shape file. Note this code does not perform any geographic projections.

require 'rubygems'
require 'RMagick'
require 'rvg/rvg'
require 'shapelib'
include ShapeLib
include Magick

USSTATES_SHAPEFILE="/Users/jkk/projects/shapelib/statesp020/statesp020.shp"
OUTFILE="/Users/jkk/projects/shapelib/test.png"

def drawshape shape, canvas
  #each shape can have multiple shape parts...
  #iterate over each shape part in this shape -
    0.upto(shape.part_start.length-1) do |index|
       part_begin = shape.part_start[index]
      unless shape.part_start[index+1].nil? then
        part_end = shape.part_start[index+1]-1
      else
       part_end=-1
      end
    #NOTE we're assuming all the parts are polygons for now...
    #draw a polygon with the current subset of the xvals and yvals point arrays
    canvas.polygon(shape.xvals.slice(part_begin..part_end),shape.yvals.slice(part_begin..part_end)).styles(:fill =>"green",:stroke=>"black",:stroke_width=>0.01)
  end
end

#create a viewbox with lat/long coordinate space in the correct range
def create_canvas rvg, shapefile
    width = shapefile.maxbound[0] -shapefile.minbound[0]
    height = shapefile.maxbound[1] -shapefile.minbound[1]
    #puts "viewport #{shapefile.minbound[0]},#{shapefile.minbound[1]} - width= #{width} height= #{height}"
    #invert the y axis so "up" is bigger and map the coordinate space to the shape's bounding box
    canvas = rvg.translate(0,rvg.height).scale(1,-1).viewbox(shapefile.minbound[0],shapefile.minbound[1],width,height).preserve_aspect_ratio('xMinYMin', 'meet')
end

shapefile = ShapeFile.open(USSTATES_SHAPEFILE,"rb")
#create a new RVG object
rvg = RVG.new(1000,100)
rvg.background_fill='white'
canvas = create_canvas rvg, shapefile
shapefile.each { |shape| drawshape(shape,canvas) }
shapefile.close

rvg.draw.write(OUTFILE)

I’m using the US State boundary file from the national atlas website.

Shoo-in for a pulitzer

Tuesday, April 24th, 2007

Next year’s pulitzer prize has to go to Marianne Lavelle of US News and World Report for this article titled “Is a penny a gallon worth a detour?” and subtitled “Cutting back on driving rather than searching for bargains is often a better way to save money on gas.

Wow! Who would of thought driving less would save you money, and that going out of your way for a few cents per gallon savings wouldn’t be worth it?

Now that she’s gotten this difficult study wrapped up we can all look forward to her future work on ending the war in Iraq and converting to a hydrogen economy – should be easy by comparison :)

We’ll keep the carbon credits, thanks

Monday, April 23rd, 2007

I saw on the Globe’s website that the founder of ZipCar has started a new company, goloco.com, which aims to promote ride sharing by splitting up the costs of a trip, handling payments to the driver, and taking a 10% cut of the proceeds. I don’t know why, but I happened to skim the terms of service which were all pretty standard stuff, until i found this:

13. Carbon Credits

You agree to assign the rights to any Carbon Credits resulting from any trips arranged using our service to GoLoco.

Pretty crafty – if they do well, and if we ever get some kind of cap and trade system for carbon (which is a lot of ifs) they could stand to make more money selling carbon credits than on their users’ tithe.

The power of green

Monday, April 16th, 2007

Thomas Friedman wrote a phenomenal article on green power in last Sunday’s New York Times magazine. The gist of it is that America leads the world in developing technology to conserve and cleanly generate in the few markets where the US government has acted in the past to mandate strict emissions restrictions, as in the example of diesel locomotives, and creating well-paying domestic jobs to boot. He argues that the free market can’t work properly without the government creating regulations that can provide guidance on future costs of emissions and fuel. People can’t and won’t invest hundreds of millions of dollars if they can be wiped out the next time oil prices drop. It needs to cost money to burn fossil fuels or no alternatives will be developed.
I’ve heard this before at Technical Review’s emerging tech conference last fall – hopefully with Friedman articulating the case for pro enviroment so well and in a manner that should make sense for lots of society, not just the “tree-huggers” we can finally make some real progress on meaningful environmental legislation.

Long hold times at Authorize.net

Tuesday, April 3rd, 2007

Over the past two days, I’ve had the misfortune of gathering a good sample of Authorize.net’s support hold time. (fyi, they are an internet credit card processing gateway) Four calls – each with hold times between 12 and 15 minutes! At between 9 and 10 eastern time, so a good chunk of the country is still sleeping no less. That doesn’t seem like any way to run a business. When I asked about the hold times (on the third call), the guy said its because its the first weekdays after the monthly billing cycle. That was meant to be reassuring but its got to make you wonder what are they doing wrong with their customer billing so that everyone has to call them about it?

In their defense, the problem I was calling about wasn’t their fault, and they indicated they thought some of our information was wrong right from the get go.

Hopefully it’ll be smooth sailing from here on out and I won’t have to call them again.

Object Properties Using Value Expressions in JSTL

Tuesday, April 3rd, 2007

I found out something cool about JSTL’s expression language today that I didn’t expect at all – like a real scripting language, EL allows one to access an object’s fields not only like object.fieldname (which wouldn’t be changeable at runtime) but also as object["fieldname"] and by extension with any string variable as an argument. Wow! I don’t remember seeing any examples of this in the wild – somehow i stumbled upon it in the bowels of a unified expression language tutorial.

This came in handy DRYing out some JSP code today that differed only in the fields accessed on the same kind of objects – I thought immediately, if only I had a scripting language this could all go away! Then I thought about the long and winding road one might take to do that in java, involving reflection and/or long if/else blocks. I was pleasantly surprised to find out JSTL can do that. Phew.
Here’s a poor example:

What you’d have to do w/o this capability

${object.dog}
${object.cat}

and with

<c :set var="fieldName" value="dog" />
${object[fieldName]}

i told you it was a bad example.