<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Alan's RamblingsWeb</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>
    <pubDate>Fri, 29 Mar 2013 18:22:00 GMT</pubDate>
    <dc:creator>Alan Burlison</dc:creator>
    <dc:date>2013-03-29T18:22:00Z</dc:date>
    <dc:language>en</dc:language>
    <dc:rights>Alan Burlison</dc:rights>
    <image>
      <title>Alan's RamblingsWeb</title>
      <url>http://bleaklow.com:80/categories/tech/web/</url>
    </image>
    <item>
      <title>Scala snippet of the day</title>
      <link>http://bleaklow.com:80/2012/02/17/scala_snippet_of_the_day.html</link>
      <content:encoded>&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'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's pass-by-name mechanism to pass the &lt;code&gt;op&lt;/code&gt; parameter.  That'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;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/">Tech</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <pubDate>Fri, 17 Feb 2012 14:04:00 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2012-02-17:default/1329487440000</guid>
      <dc:date>2012-02-17T14:04:00Z</dc:date>
    </item>
    <item>
      <title>Stupid BT router...</title>
      <link>http://bleaklow.com:80/2011/11/23/stupid_bt_router.html</link>
      <content:encoded>&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't notice that it had also lost the port mappings for bleaklow.com.  As a result I've been off-air for quite some time.  Bloody BT...
&lt;/p&gt;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/">Tech</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <pubDate>Wed, 23 Nov 2011 14:12:00 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2011-11-23:default/1322057520000</guid>
      <dc:date>2011-11-23T14:12:00Z</dc:date>
    </item>
    <item>
      <title>mod-rewrite equivalent for Tomcat</title>
      <link>http://bleaklow.com:80/2010/06/02/mod_rewrite_equivalent_for_tomcat.html</link>
      <content:encoded>&lt;p&gt;
I've migrated and merged my old blogs.sun.com and bleaklow.com blogs into this new one, using &lt;a href="http://pebble.sourceforge.net/"&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's &lt;a href="http://www.google.com/webmasters/tools/"&gt;webmaster tools&lt;/a&gt; gives me a comprehensive list.  If I was hosting this blog using &lt;a href="http://httpd.apache.org/"&gt;Apache&lt;/a&gt;, the standard solution would be to use the most excellent &lt;a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html"&gt;mod-rewrite&lt;/a&gt; Apache module to redirect the broken links to somewhere appropriate.  However Pebble is a &lt;a href="http://java.sun.com/javaee/"&gt;J2EE&lt;/a&gt; application and uses &lt;a href="http://tomcat.apache.org/"&gt;Tomcat&lt;/a&gt; instead of Apache.  I'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="http://tuckey.org/urlrewrite/"&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'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;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/">Tech</category>
      <category domain="http://bleaklow.com:80/categories/tech/java/">Java</category>
      <category domain="http://bleaklow.com:80/tags/apache/">apache</category>
      <category domain="http://bleaklow.com:80/tags/java/">java</category>
      <category domain="http://bleaklow.com:80/tags/mod-rewrite/">mod-rewrite</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/tomcat/">tomcat</category>
      <category domain="http://bleaklow.com:80/tags/urlrewrite/">urlrewrite</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <pubDate>Wed, 02 Jun 2010 17:15:00 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2010-06-02:default/1275498900000</guid>
      <dc:date>2010-06-02T17:15:00Z</dc:date>
    </item>
    <item>
      <title>Simple parser for MovableType exports</title>
      <link>http://bleaklow.com:80/2010/05/23/simple_parser_for_movabletype_exports.html</link>
      <content:encoded>&lt;p&gt;
As part of moving my blog over to &lt;a href="http://pebble.sourceforge.net/" pebble=""&gt;&lt;/a&gt; I needed to be able to transfer the content from my old &lt;a href="http://www.movabletype.com/"&gt;MovableType&lt;/a&gt; blog and my blogs.sun.com blog, which runs on &lt;a href="http://www.movabletype.com/"&gt;Roller&lt;/a&gt;.  Both MT and Roller can export in &lt;a href="http://www.sixapart.com/movabletype/docs/mtimport"&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'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'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've put a copy of it &lt;a href="files/2010/MTParser.tar.gz"&gt;here&lt;/a&gt;.
&lt;/p&gt;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/">Tech</category>
      <category domain="http://bleaklow.com:80/categories/tech/java/">Java</category>
      <category domain="http://bleaklow.com:80/tags/export/">export</category>
      <category domain="http://bleaklow.com:80/tags/import/">import</category>
      <category domain="http://bleaklow.com:80/tags/java/">java</category>
      <category domain="http://bleaklow.com:80/tags/movabletype/">movabletype</category>
      <category domain="http://bleaklow.com:80/tags/pebble/">pebble</category>
      <category domain="http://bleaklow.com:80/tags/roller/">roller</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <pubDate>Sun, 23 May 2010 10:03:00 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2010-05-23:default/1274608980000</guid>
      <dc:date>2010-05-23T10:03:00Z</dc:date>
    </item>
    <item>
      <title>Image thumbnailer for Pebble</title>
      <link>http://bleaklow.com:80/2010/05/23/image_thumbnailer_for_pebble.html</link>
      <content:encoded>&lt;p&gt;
This blog uses the &lt;a href="http://pebble.sourceforge.net/"&gt;Pebble&lt;/a&gt; package for delivering content.  Pebble isn'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'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="http://www.movabletype.com/"&gt;MovableType&lt;/a&gt; but that doesn't really tick the Open Source box any more.  blogs.sun.com  uses &lt;a href="http://rollerweblogger.org/project/"&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'm not bothered about glossy JavaScript solutions such as &lt;a href="http://www.huddletogether.com/projects/lightbox2/"&gt;Lightbox&lt;/a&gt;, and I'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't so I sat down one evening and knocked together an equivalent as a Pebble plugin, using the standard &lt;a href="http://java.sun.com/products/java-media/2D/index.jsp"&gt;Java2D&lt;/a&gt; APIs to do the image manipulation.  All the thumbnails on this site are done with it, and I've submitted this as a &lt;a href="http://open.jira.com/browse/PEBBLE-26"&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;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/java/">Java</category>
      <category domain="http://bleaklow.com:80/tags/java/">java</category>
      <category domain="http://bleaklow.com:80/tags/pebble/">pebble</category>
      <category domain="http://bleaklow.com:80/tags/photo/">photo</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/thumbnail/">thumbnail</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <pubDate>Sun, 23 May 2010 08:54:00 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2010-05-23:default/1274604840000</guid>
      <dc:date>2010-05-23T08:54:00Z</dc:date>
    </item>
  </channel>
</rss>

