Archive for March, 2007

Jane Street Capital Is On To Me

Monday, March 26th, 2007

If you search for the right strings, you’ve probably already seen the Jane Street Capital ads for OCaml programmers in Gmail or elsewhere, but today I got a new one that really cracked me up:

Jane Street Capital ad: Do you think In Closures? We do too!

I’ll even link to the ad because it was so funny… and I do think in closures, and you certainly got my attention!

“Literate” Programming, Technical Writing

Friday, March 16th, 2007

There’s been some recent discussion on ruby-talk about “literate” programming after the new O’Reilly title Beautiful Code was announced (Matz has written an essay for it). Matz’s response made me listen to all-things-Knuth, so I was pleased to read Philip Wadler’s post today on Three ways to improve your writing, which includes a PDF link to Knuth (and others) lecturing on writing and “literate” programming. I’ve just started reading it, but have already found two laugh-worthy gems:

13. Many readers will skim over formulas on their first reading of your exposition. Therefore, your sentences should flow smoothly when all but the simplest formulas are replaced by “blah” or some other grunting noise.

20. Some handy maxims:
Watch out for prepositions that sentences end with.
When dangling, consider your participles.
About them sentence fragments.
Make each pronoun agree with their antecedent.
Don’t use commas, which aren’t necessary.
Try to never split infinitives.

I know the first is certainly true for me as I’ve been trying to wade through Haskell (a language into “literate programming”) introductions recently, which are very math-heavy.

Borrowing Java’s XSLT Support for Ruby

Friday, March 2nd, 2007

Well, I finally caught up with the crowd and got JRuby running on one of my dev boxes. The reason I’d been interested in it from the getgo was because Ruby lacks any support for internal XSLT processing. All those system()s were starting to get me down, especially as I’m trying to get a DocBook->PDF rendering webservice to be a lot faster. Much to my surprise, I was able to get simple transforms working in almost no time (thanks in part to lots of help). Without further ado, here’s a simple library for XSLT transforms using either Xalan-J or Saxon (make sure you have the jars for both in your CLASSPATH):

require 'java'
module JXslt
  include_class "javax.xml.transform.TransformerFactory"
  include_class "javax.xml.transform.Transformer"
  include_class "javax.xml.transform.stream.StreamSource"
  include_class "javax.xml.transform.stream.StreamResult"
  include_class "java.lang.System"

  class XsltProcessor
    def transform(xslt,infile,outfile)
      transformer = @tf.newTransformer(StreamSource.new(xslt))
      transformer.transform(StreamSource.new(infile), StreamResult.new(outfile))
    end
  end # XsltProcessor
  class Saxon < XsltProcessor
    TRANSFORMER_FACTORY_IMPL = "net.sf.saxon.TransformerFactoryImpl"
    def initialize
      System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
      @tf = TransformerFactory.newInstance
    end
  end
  class Xalan < XsltProcessor
    TRANSFORMER_FACTORY_IMPL = "org.apache.xalan.processor.TransformerFactoryImpl"
    def initialize
      System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
      @tf = TransformerFactory.newInstance
    end
  end
end 

# if you wanted to run this from the command line, do something like
# $ jruby lib/jxslt.rb a.xsl in.xml out.xml
xalan = JXslt::Xalan.new
xalan.transform(*ARGV)
#saxon = JXslt::Saxon.new
#saxon.transform(*ARGV)

Big props to Charles for helping me get going and writing the first version of the above.

darcs get http://kfahlgren.com/code/lib/jxslt/ or jxslt.rb