<?xml version="1.0"?><rss version="2.0">
<channel>
  <title>Alan&#039;s Ramblings - Web category</title>
  <link>http://bleaklow.com:80/categories/tech/web/</link>
  <description>My opinions may be incorrect, but they are my own</description>
  <language>en</language>
  <copyright>Alan Burlison</copyright>
  <lastBuildDate>Wed, 29 Feb 2012 20:50:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  <image>
    <url>http://bleaklow.com/images/misc/logo.gif</url>
    <title>Alan&#039;s Ramblings (Web category)</title>
    <link>http://bleaklow.com:80/</link>
  </image>
  <item>
    <title>Scala snippet of the day</title>
    <link>http://bleaklow.com:80/2012/02/17/scala_snippet_of_the_day.html</link>
    <description>
          &lt;p&gt;
The following is useful for benchmarking code from inside the REPL:
&lt;/p&gt;
&lt;pre&gt;
def timed(op: =&gt; Unit) = {
  val start = System.nanoTime
  op
  (System.nanoTime - start) / 1e9
}
&lt;/pre&gt;
&lt;p&gt;
Then you can use it like this:
&lt;/p&gt;
&lt;pre&gt;
scala&amp;gt; timed { Thread.sleep(5000) }
res0: Double = 5.010083526
&lt;/pre&gt;
&lt;p&gt;
That&#039;s syntactic sugar for an anonymous function definition and a call of &lt;code&gt;timed&lt;/code&gt;.  If a function takes only a single parameter you can pass it inside &lt;code&gt;{ }&lt;/code&gt;, so if we wrote that out longhand it would be:
&lt;/p&gt;
&lt;pre&gt;
scala&amp;gt; def fn = Thread.sleep(5000)
fn: Unit

scala&amp;gt; timed(fn)
res0: Double = 5.010088248
&lt;/pre&gt;
&lt;p&gt;
The other neat bit is the use of Scala&#039;s pass-by-name mechanism to pass the &lt;code&gt;op&lt;/code&gt; parameter.  That&#039;s the funny-looking &lt;code&gt;op: =&gt; Unit&lt;/code&gt; argument list to &lt;code&gt;timed&lt;/code&gt;.  Normally Scala uses by-value parameters, i.e. the line &lt;code&gt;timed(fn)&lt;/code&gt; would result in the evaluation of fn, and then passing the returned value (in this case, nothing) into &lt;code&gt;timed&lt;/code&gt;.  However by using pass-by-name, the evaluation of &lt;code&gt;fn&lt;/code&gt; takes place inside &lt;code&gt;timed&lt;/code&gt;, and by wrapping it inside timing instrumentation we can time how long &lt;code&gt;op&lt;/code&gt; takes to execute.
&lt;/p&gt;</description>
      <category>Web</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2012/02/17/scala_snippet_of_the_day.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2012/02/17/scala_snippet_of_the_day.html</guid>
    <pubDate>Fri, 17 Feb 2012 14:04:00 GMT</pubDate>
  </item>
  <item>
    <title>Stupid BT router...</title>
    <link>http://bleaklow.com:80/2011/11/23/stupid_bt_router.html</link>
    <description>
          &lt;p&gt;
I have the misfortune to own a BT Business 2Wire router, and bleaklow.com sits behind that.  A while back it threw a fit and reconfigured itself and when I beat it into submission I didn&#039;t notice that it had also lost the port mappings for bleaklow.com.  As a result I&#039;ve been off-air for quite some time.  Bloody BT...
&lt;/p&gt;</description>
      <category>Web</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2011/11/23/stupid_bt_router.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2011/11/23/stupid_bt_router.html</guid>
    <pubDate>Wed, 23 Nov 2011 14:12:00 GMT</pubDate>
  </item>
  <item>
    <title>mod-rewrite equivalent for Tomcat</title>
    <link>http://bleaklow.com:80/2010/06/02/mod_rewrite_equivalent_for_tomcat.html</link>
    <description>
          &lt;p&gt;
I&#039;ve migrated and merged my old blogs.sun.com and bleaklow.com blogs into this new one, using &lt;a href=&#034;http://pebble.sourceforge.net/&#034;&gt;Pebble&lt;/a&gt;.  As a result, there are a number of links out there on the interwebs to bleaklow.com that are now broken, as everything has moved around - google&#039;s &lt;a href=&#034;http://www.google.com/webmasters/tools/&#034;&gt;webmaster tools&lt;/a&gt; gives me a comprehensive list.  If I was hosting this blog using &lt;a href=&#034;http://httpd.apache.org/&#034;&gt;Apache&lt;/a&gt;, the standard solution would be to use the most excellent &lt;a href=&#034;http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html&#034;&gt;mod-rewrite&lt;/a&gt; Apache module to redirect the broken links to somewhere appropriate.  However Pebble is a &lt;a href=&#034;http://java.sun.com/javaee/&#034;&gt;J2EE&lt;/a&gt; application and uses &lt;a href=&#034;http://tomcat.apache.org/&#034;&gt;Tomcat&lt;/a&gt; instead of Apache.  I&#039;ve been looking for an equivalent to mod-rewrite for a while and never managed to find anything.  Whilst looking for something else entirely (always the way) I found &lt;a href=&#034;http://tuckey.org/urlrewrite/&#034;&gt;Url Rewrite Filter&lt;/a&gt;.  This is functional equivalent to mod-rewrite for J2EE servers, and offers most of the same features as mod-rewrite.  I&#039;m using it and it seems to do the job just fine, and the beta even has a mod-rewrite style configuration option, if you need a security blanket :-)
&lt;/p&gt;</description>
      <category>Web</category>
    <category>Tech</category>
    <category>Java</category>
    <comments>http://bleaklow.com:80/2010/06/02/mod_rewrite_equivalent_for_tomcat.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2010/06/02/mod_rewrite_equivalent_for_tomcat.html</guid>
    <pubDate>Wed, 02 Jun 2010 17:15:00 GMT</pubDate>
  </item>
  <item>
    <title>Simple parser for MovableType exports</title>
    <link>http://bleaklow.com:80/2010/05/23/simple_parser_for_movabletype_exports.html</link>
    <description>
          &lt;p&gt;
As part of moving my blog over to &lt;a href=&#034;http://pebble.sourceforge.net/&#034; pebble=&#034;&#034;&gt;&lt;/a&gt; I needed to be able to transfer the content from my old &lt;a href=&#034;http://www.movabletype.com/&#034;&gt;MovableType&lt;/a&gt; blog and my blogs.sun.com blog, which runs on &lt;a href=&#034;http://www.movabletype.com/&#034;&gt;Roller&lt;/a&gt;.  Both MT and Roller can export in &lt;a href=&#034;http://www.sixapart.com/movabletype/docs/mtimport&#034;&gt;MovableType export format&lt;/a&gt; and Pebble has a MT importer, so it looked relatively straightforward.  However when I looked at the content I was importing it was clear I&#039;d need to munge it on its way into Pebble.  The Pebble MT importer is one-pass and loads the entries into Pebble as it reads them, whereas I wanted to read them in, munge them and only then load them into Pebble, so I wrote a simple parser to read in the MT export.  It&#039;s not a thing of great beauty but it got the job done.  I thought it might be useful for other people who want to read MovableType exports from Java, so I&#039;ve put a copy of it &lt;a href=&#034;files/2010/MTParser.tar.gz&#034;&gt;here&lt;/a&gt;.
&lt;/p&gt;</description>
      <category>Web</category>
    <category>Tech</category>
    <category>Java</category>
    <comments>http://bleaklow.com:80/2010/05/23/simple_parser_for_movabletype_exports.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2010/05/23/simple_parser_for_movabletype_exports.html</guid>
    <pubDate>Sun, 23 May 2010 10:03:00 GMT</pubDate>
  </item>
  <item>
    <title>Image thumbnailer for Pebble</title>
    <link>http://bleaklow.com:80/2010/05/23/image_thumbnailer_for_pebble.html</link>
    <description>
          &lt;p&gt;
This blog uses the &lt;a href=&#034;http://pebble.sourceforge.net/&#034;&gt;Pebble&lt;/a&gt; package for delivering content.  Pebble isn&#039;t a particularly common blogging package but it fits my purely personal and subjective requirements:
&lt;/p&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;Not written in PHP (blegh)
&lt;li&gt;Open source, and something in Java would be nice
&lt;li&gt;Doesn&#039;t use a database and uses flat files that I can manage manually if I need to
&lt;li&gt;Good RSS, search, tag and category management
&lt;li&gt;Can be restyled easily
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;The old incarnation of this blog used &lt;a href=&#034;http://www.movabletype.com/&#034;&gt;MovableType&lt;/a&gt; but that doesn&#039;t really tick the Open Source box any more.  blogs.sun.com  uses &lt;a href=&#034;http://rollerweblogger.org/project/&#034;&gt;Roller&lt;/a&gt; but that requires a database back-end.  All these constraints combined to give a pretty short list of candidates, i.e. Pebble.
&lt;/p&gt;
&lt;p&gt;
One thing that Pebble lacks is an image thumbnailer.  I&#039;m not bothered about glossy JavaScript solutions such as &lt;a href=&#034;http://www.huddletogether.com/projects/lightbox2/&#034;&gt;Lightbox&lt;/a&gt;, and I&#039;m quite happy to type in HTML table definitions.  All I wanted was something to save me the tedium of manually generating the thumbnails and typing in the HTML to display them and link to the full-size image in a popup window.  MovableType has this feature but Pebble doesn&#039;t so I sat down one evening and knocked together an equivalent as a Pebble plugin, using the standard &lt;a href=&#034;http://java.sun.com/products/java-media/2D/index.jsp&#034;&gt;Java2D&lt;/a&gt; APIs to do the image manipulation.  All the thumbnails on this site are done with it, and I&#039;ve submitted this as a &lt;a href=&#034;http://open.jira.com/browse/PEBBLE-26&#034;&gt;patch&lt;/a&gt; to Pebble so hopefully it will make it into a future release.
&lt;/p&gt;
&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;
The patch has been accepted and should be appearing in a future version of Pebble.
&lt;/p&gt;
</description>
      <category>Web</category>
    <category>Java</category>
    <comments>http://bleaklow.com:80/2010/05/23/image_thumbnailer_for_pebble.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2010/05/23/image_thumbnailer_for_pebble.html</guid>
    <pubDate>Sun, 23 May 2010 08:54:00 GMT</pubDate>
  </item>
  </channel>
</rss>

