<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AsynchronousBlog &#187; ~/stuff/programming</title>
	<atom:link href="http://www.asynchronous.org/blog/archives/category/stuffprogramming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.asynchronous.org/blog</link>
	<description>Random stuff for search engines to index.</description>
	<lastBuildDate>Sat, 28 Nov 2009 16:10:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>django timezone view handling</title>
		<link>http://www.asynchronous.org/blog/archives/2009/10/10/django-timezone-view-handling</link>
		<comments>http://www.asynchronous.org/blog/archives/2009/10/10/django-timezone-view-handling#comments</comments>
		<pubDate>Sat, 10 Oct 2009 15:39:38 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/homebrew]]></category>
		<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=89</guid>
		<description><![CDATA[One simple way to handle user-time-zone localization in an app is to always
store the timestamp in UTC, and localize viewing/editing of that timestamp in
a specific timezone.

By default, Django traffics in the single settings.py-configured timezone.

Timezone handling appear incomplete.  The two options you&#8217;ll run across are
this snippet for a timezone-localizing filter
and django-timezones.

django-timezones has support for a [...]]]></description>
			<content:encoded><![CDATA[<p>One simple way to handle user-time-zone localization in an app is to always
store the timestamp in UTC, and localize viewing/editing of that timestamp in
a specific timezone.</p>

<p>By default, Django traffics in the single settings.py-configured timezone.</p>

<p>Timezone handling appear incomplete.  The two options you&#8217;ll run across are
<a href="http://www.djangosnippets.org/snippets/183/">this snippet for a timezone-localizing filter</a>
and <a href="http://code.google.com/p/django-timezones/">django-timezones</a>.</p>

<p>django-timezones has support for a TimeZone model/view field, and a model/view LocalizedDateTimeField.  The View field, however, will only do the parse-time conversion of the datetime value in to the settings-defined TZ. This only solves half of the problem, since you still need to convert the settings-defined TZ into the user&#8217;s TZ, and there&#8217;s no component for that.</p>

<p>The following is a LocalizedDateTimeInput widget which will handle this last
step, building on django.forms.DateTimeInput and django-timezones&#8217; utility
code:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django <span style="color: #ff7700;font-weight:bold;">import</span> forms
<span style="color: #ff7700;font-weight:bold;">from</span> timezones.<span style="color: black;">utils</span> <span style="color: #ff7700;font-weight:bold;">import</span> adjust_datetime_to_timezone
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> LocalizedDateTimeInput <span style="color: black;">&#40;</span>forms.<span style="color: black;">DateTimeInput</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, tz<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>._tz = tz
        <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>LocalizedDateTimeInput, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> render<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name, value, attrs=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>value, <span style="color: #dc143c;">datetime</span><span style="color: black;">&#41;</span>:
            value = adjust_datetime_to_timezone<span style="color: black;">&#40;</span>value, <span style="color: #483d8b;">'UTC'</span>, <span style="color: #008000;">self</span>._tz<span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;"># @fixme: output the string rep of the timezone, probably after the &amp;lt;input /&amp;gt;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>LocalizedDateTimeInput, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">render</span><span style="color: black;">&#40;</span>name, value, attrs<span style="color: black;">&#41;</span></pre></div></div>


<p>Unfortunately, you&#8217;ll need to add a level of indirection to your view Form constructors to bind the &#8216;tz&#8217; argument on the widget.  Instead of a normal:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> MumbleForm <span style="color: black;">&#40;</span>forms.<span style="color: black;">Form</span><span style="color: black;">&#41;</span>:
    name = forms.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    date = forms.<span style="color: black;">DateTimeField</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>


<p>You&#8217;ll want to do something like:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> MumbleForm<span style="color: black;">&#40;</span><span style="color: #dc143c;">user</span>, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
    tz = settings.<span style="color: black;">TIME_ZONE</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">user</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">user</span>, <span style="color: #483d8b;">'get_profile'</span><span style="color: black;">&#41;</span>:
        tz = <span style="color: #dc143c;">user</span>.<span style="color: black;">get_profile</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">timezone</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">class</span> _MumbleForm <span style="color: black;">&#40;</span>forms.<span style="color: black;">Form</span><span style="color: black;">&#41;</span>:
        name = forms.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        date = LocalizedDateTimeField<span style="color: black;">&#40;</span>tz, widget=LocalizedDateTimeInput<span style="color: black;">&#40;</span>tz<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> _MumbleForm<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span></pre></div></div>


<p>You can see <a href="http://github.com/jsled/brew-journal/commit/e754b4097caaea50b62225a31ce71c81e244ba8b">more usage examples from the brew-journal commit</a>.</p>

<p>Any tips or improvements welcome, of course.</p>

<p><i>Update, 2009-11-28: </i> I finally got around to moving to using mysql instead of sqlite for this project, and discovered that the above solution needs one more piece.  The default LocalizedDatetimeField seems to return datetimes which are &#8220;[tz] aware&#8221; in python&#8217;s vernacular, but mysql complains that datetimes with a tz portion are not allowed.  So, we add a SafeLocalizedDateTimeField that returns &#8220;naive&#8221; datetimes instead:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> SafeLocalizedDateTimeField <span style="color: black;">&#40;</span>LocalizedDateTimeField<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> clean<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, value<span style="color: black;">&#41;</span>:
        val = <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>SafeLocalizedDateTimeField, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">clean</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> val <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">None</span>:
            val = val.<span style="color: black;">replace</span><span style="color: black;">&#40;</span>tzinfo=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> val</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2009/10/10/django-timezone-view-handling/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>configuring tomcat6 for https with cargo</title>
		<link>http://www.asynchronous.org/blog/archives/2008/10/16/configuring-tomcat6-for-https-with-cargo</link>
		<comments>http://www.asynchronous.org/blog/archives/2008/10/16/configuring-tomcat6-for-https-with-cargo#comments</comments>
		<pubDate>Thu, 16 Oct 2008 22:22:51 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/misc]]></category>
		<category><![CDATA[~/stuff/programming]]></category>
		<category><![CDATA[~/stuff/work/mysql]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/archives/2008/10/16/configuring-tomcat6-for-https-with-cargo</guid>
		<description><![CDATA[cargo is a nifty tool for launching containers from, say, ant.  While it doesn&#8217;t contain official support for Tomcat6, the Tomcat5 support works just fine with Tomcat6.

There is a property, cargo.protocol, where you can specify https, however, the resulting server.xml that it generates will not be quite correct.  A hack-fix is to edit [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cargo.codehaus.org/">cargo</a> is a nifty tool for launching containers from, say, ant.  While it doesn&#8217;t contain official support for Tomcat6, the Tomcat5 support works just fine with Tomcat6.</p>

<p>There is a property, <code>cargo.protocol</code>, where you can specify <code>https</code>, however, the resulting server.xml that it generates will not be quite correct.  A hack-fix is to edit <code>org/codehaus/cargo/container/internal/resources/tomcat5x/server.xml</code> in the jar file to include Â«SSLEnabled=&#8221;true&#8221;Â».  As well, you might want to add the appropriate attributes for the relevant keyfile-path, otherwise, it seemed to use <code>$(HOME)/.keystore</code>, which I was happy to provide.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2008/10/16/configuring-tomcat6-for-https-with-cargo/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>java array iteration</title>
		<link>http://www.asynchronous.org/blog/archives/2007/10/04/java-array-iteration</link>
		<comments>http://www.asynchronous.org/blog/archives/2007/10/04/java-array-iteration#comments</comments>
		<pubDate>Fri, 05 Oct 2007 00:08:00 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=85</guid>
		<description><![CDATA[Java5 now has language support for iteration of the form:


    for &#40;Type var : someIterable&#41; &#123; ... &#125;


As well, there is now an Iterable&#60;t&#62; interface, and Arrays are directly iterable, allowing you to write:


    String&#91;&#93; thingys = &#123;&#34;a&#34;,&#34;b&#34;,&#34;c&#34;&#125;;
    for &#40;String thingy : thingys&#41; &#123; ... &#125;


At [...]]]></description>
			<content:encoded><![CDATA[<p>Java5 now has language support for iteration of the form:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Type var <span style="color: #339933;">:</span> someIterable<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span></pre></div></div>


<p>As well, there is now an <code>Iterable&lt;t&gt;</code> interface, and Arrays are directly iterable, allowing you to write:</t></p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> thingys <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;a&quot;</span>,<span style="color: #0000ff;">&quot;b&quot;</span>,<span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> thingy <span style="color: #339933;">:</span> thingys<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span></pre></div></div>


<p>At work, we have a collection of utility iterators, most written before these were available.  As such, we have an ArrayIter utility, and a ZipIterator, inspired by Python&#8217;s <a href="http://docs.python.org/lib/itertools-functions.html#l2h-1061">itertools.izip</a>.</p>

<p>I&#8217;ve been going through these classes and their usages on a lazy basis to update them to the new syntax.  I finally got around to a usage of the ZipIterator, which happened to compose an ArrayIter &#8230; it zipped together an array of String names with the results of a test.</p>

<p>So, I changed it to:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> names <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;foo&quot;</span>, <span style="color: #0000ff;">&quot;bar&quot;</span>, <span style="color: #0000ff;">&quot;baz&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">List</span> results<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> pair <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">new</span> ZipIterator<span style="color: #009900;">&#40;</span>names, results<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// ...</span></pre></div></div>


<p>No dice, says Java:</p>

<pre><code>/home/jsled/stuff/work/[...]TestMumble.java:46: cannot find symbol symbol  : constructor ZipIterator(java.lang.String[],java.util.List)
location: class com.spokesoftware.util.iterator.ZipIterator
for (Object pairObj : new ZipIterator(data, results))
</code></pre>

<p>WTF?  Okay, let me help you out:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> pair <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">new</span> ZipIterator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Iterable<span style="color: #009900;">&#41;</span>names, results<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #666666; font-style: italic;">// ...</span></pre></div></div>


<p>FUCK YOU, says Java:</p>

<pre><code>/home/jsled/stuff/work/[...]/TestMumble.java:46: inconvertible types
found   : java.lang.String[]
required: java.lang.Iterable
for (Object pairObj : new ZipIterator((Iterable)data, results))
</code></pre>

<p>It turns out that the string &#8220;iter&#8221; isn&#8217;t even in the <a href="http://java.sun.com/docs/books/jls/third_edition/html/arrays.html#10.7">text of the section about Arrays in the Java Language Spec</a>.  Array instances aren&#8217;t Iterable.  They&#8217;re a <a href="http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2">special case in the handling of the for-each loop syntax</a>.</p>

<p>This code ended up as:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> pair <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">new</span> ZipIterator<span style="color: #009900;">&#40;</span><span style="color: #003399;">Arrays</span>.<span style="color: #006633;">asList</span><span style="color: #009900;">&#40;</span>names<span style="color: #009900;">&#41;</span>, results<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>


<p>Java is totally shitrude.</p>

<p><i>edit 2009-10-10: added some formatting/syntax highlighting of the java blocks</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2007/10/04/java-array-iteration/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gnucash-2.0.0</title>
		<link>http://www.asynchronous.org/blog/archives/2006/07/10/gnucash-200</link>
		<comments>http://www.asynchronous.org/blog/archives/2006/07/10/gnucash-200#comments</comments>
		<pubDate>Mon, 10 Jul 2006 14:19:21 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=77</guid>
		<description><![CDATA[After much sporadic work, testing, updates, frustration and hacking, GnuCash 2.0.0 was released last night.  Now the real fun can begin. :)
]]></description>
			<content:encoded><![CDATA[<p>After much sporadic work, testing, updates, frustration and hacking, <a href="http://www.gnucash.org/">GnuCash 2.0.0</a> was released last night.  Now the real fun can begin. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2006/07/10/gnucash-200/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>working around java class/memory leak in GATE 3.0</title>
		<link>http://www.asynchronous.org/blog/archives/2006/06/28/working-around-java-classmemory-leak-in-gate-30</link>
		<comments>http://www.asynchronous.org/blog/archives/2006/06/28/working-around-java-classmemory-leak-in-gate-30#comments</comments>
		<pubDate>Wed, 28 Jun 2006 21:38:35 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=76</guid>
		<description><![CDATA[I&#8217;ve developed some patches to GATE to allow an application to work around memory issues resulting from using JAPE in a long-lived VM.

The problem stems from use of the GateClassLoader and the dynamic
creation of classes in loading JAPE grammars.  Generally, classes are
loaded into the Permanent Generation section of the heap, and are only
eligible for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve developed some patches to <a href="http://gate.ac.uk/">GATE</a> to allow an application to work around memory issues resulting from using JAPE in a long-lived VM.</p>

<p>The problem stems from use of the GateClassLoader and the dynamic
creation of classes in loading JAPE grammars.  Generally, classes are
loaded into the Permanent Generation section of the heap, and are only
eligible for garbage collection when the classloader from which they
were sourced is itself unreachable.  As the GateClassLoader is never
reset or reinitialized, over time the classes will accumulate and fill
the heap, and cause OutOfMemory errors in VM.  While a first attempt to
resolve this would be to cache the loaded JAPE objects, there are still
classes created on each <em>use</em> of that grammar, which will slowly cause
the same problem.</p>

<p>The caller needs a facility to reset the class loader, as provided by
the patches to src/gate/Gate.java (and the compiler classes).  It is
expected that the caller invokes <code>Gate.resetClassLoader()</code> periodically,
either on a fixed frequency or after a set number of uses of the
library; our application resets every 15 minutes.</p>

<p>One complication is the difference in time between the
generation/loading of the classes for a particular JAPE grammar and the
instantiation of objects of those classes.  Obviously, the objects needs
to be instantiated from a valid class, and in particular from the
classloader from which they were created; if the classloader is reset in
the middle, there will be instantiation exceptions thrown when using a
different classloader.  A change was thus made to
src/gate/jape/RightHandSide.java to retain a reference to the relevant
GateClassLoader.  Note, that there&#8217;s still a race condition present, but
the window of time is significantly less than before.</p>

<p>Our (application-level) reset operation resets both the Gate classloader
as well as invalidating our JAPE cache: current threads will finish
using their JAPE objects, references to the classloader are eventually
lost (from gate.Gate via reset and the jape RightHandSide objects
through reference), and the garbage collector is allowed to collect the
whole shebang.</p>

<p>This patch is much more of a workaround than a fix for the underlying
problems.  I don&#8217;t care if these patches are applied, so much as they&#8217;re
useful in demonstrating the problem so it can be more appropriately
fixed.  Really, though, JAPE shouldn&#8217;t need to create classes per use.</p>

<ul>
<li>Patches against SVN:</li>
<li><a href="/2006/06/gate-svn-classloader.patch">/2006/06/gate-svn-classloader.patch</a></li>
<li><p><a href="/2006/06/gate-svn-jape-rhs.patch">/2006/06/gate-svn-jape-rhs.patch</a></p></li>
<li><p>Patches against 3.0 (B1846):</p></li>
<li><a href="/2006/06/gate-b1846-classloader.patch">/2006/06/gate-b1846-classloader.patch</a></li>
<li><p><a href="/2006/06/gate-b1846-jape-rhs.patch">/2006/06/gate-b1846-jape-rhs.patch</a></p></li>
<li><p><a href="http://sourceforge.net/mailarchive/message.php?msg_id=14891633">Previous memory issues thread</a></p></li>
</ul>

<p>Also, while I&#8217;m at it, here are patches to:</p>

<ul>
<li><a href="/2006/06/gate-svn-prj.el.patch">fix the mangled end of prj.el</a></li>
<li><a href="/2006/06/gate-svn-chained-exceptions.patch">replace the ad-hoc chained exceptions with java&#8217;s</a></li>
</ul>

<p><em>Update, 2006-07-10</em> I was pressed for detail about my claim that JAPE creates classes on use, and found that I couldn&#8217;t.  Here&#8217;s my reply to <a href="http://gate.ac.uk/mail/index.html">gate-users</a>:</p>

<p>I went to reproduce this, and found I can&#8217;t.  Now I believe I mis-spoke.</p>

<p>The classes I remember being created were&#8230;</p>

<p>japeactionclasses.postprocessNewLineActionClass[#]
japeactionclasses.postprocessVBnegActionClass[#]
japeactionclasses.postprocesssimpleJoinActionClass[#]</p>

<p>&#8230;which are from the tokenizer&#8217;s grammar.  Thinking back to the period
I was debugging the issue, I don&#8217;t believe I was caching the tokenizers,
but I had instituted the other JAPE caching.  As well, I didn&#8217;t remember
that the tokenizer was implemented in terms of JAPE.   As such, I
tricked myself into believing that the simple use of JAPE grammars from
a different processing step was causing the loading of the
aforementioned classes, when really it was just not caching the
tokenizers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2006/06/28/working-around-java-classmemory-leak-in-gate-30/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging in JSON</title>
		<link>http://www.asynchronous.org/blog/archives/2006/01/25/logging-in-json</link>
		<comments>http://www.asynchronous.org/blog/archives/2006/01/25/logging-in-json#comments</comments>
		<pubDate>Wed, 25 Jan 2006 23:46:50 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=73</guid>
		<description><![CDATA[I primarily do backend processing at work, often dealing with extended
processing that doesn&#8217;t naturally have a user-interface.  As such, I&#8217;ve been
finding ways to provide quick and convenient interaction with the processes.

One simple obvious way is logging, but I found that text-based statement
logging doesn&#8217;t get me quite the level of detail and structure I want [...]]]></description>
			<content:encoded><![CDATA[<p>I primarily do backend processing at work, often dealing with extended
processing that doesn&#8217;t naturally have a user-interface.  As such, I&#8217;ve been
finding ways to provide quick and convenient interaction with the processes.</p>

<p>One simple obvious way is logging, but I found that text-based statement
logging doesn&#8217;t get me quite the level of detail and structure I want and
ultimately need to be productive.  When I was playing with RDF more heavily
earlier last year, I started to format my log messages as N3
pseudo-statements:</p>

<p>** 2006-01-25 12:34:56  INFO  Thread-0 Processor: [ object "foo"; count 12; disposition "thumbs-up" ]
** 2006-01-25 12:34:56  INFO  Thread-0 Processor: [ object "bar"; count 7; disposition "thumbs-down" ]</p>

<p>Of course, the &#8220;real&#8221; form of this would be to have the entire logging
pipeline emit actual N3 statements, including the logging-provided
(meta-)data:</p>

<p>[ # a log:Entry
log:ts "2006-01-25 12:34:56"
; log:lvl log:INFO
; log:thread "Thread-0"
; log:class "Processor"
; log:msg [ :object "foo"; :count 12; :disposition "thumbs-up" ] ].</p>

<p>N3&#8217;s great because of its simple syntax for representing structured data, but
I&#8217;ve recently started using <a href="http://www.json.org/">JSON</a> instead, which has a more straightforward syntax and semantics for loose, non-RDF data representation. If you&#8217;re unfamiliar with JSON, it is a subset of javascript  representing dictionaries, lists, and the basic data types (integers, floats, booleans and strings).  An example would be:</p>

<p>{&#8221;favorite int&#8221;: 42,
&#8220;floating value&#8221;: 42.01,
&#8220;this is an example&#8221;: true,
&#8220;a list of things&#8221;: [42, 42.01, true, {foo: bar, baz: quuz}]}</p>

<p>For example, I&#8217;ve been developing a content parser, and running it against
a fixed set of test cases to assess the impact of changes I make.  Each test
result consists of 4 parts:</p>

<ol>
<li>the test-case label (the input filename)</li>
<li>the expected-and-produced pairs</li>
<li>the expected-but-missed cases</li>
<li>the unexpected-but-produced cases</li>
</ol>

<p>Each test-case and result is on the order of 10 &#8220;things&#8221;, so they&#8217;re well
suited to manual review.  The test run outputs a set of log statements like:</p>

<p>** 2006-01-25 12:34:56  INFO  Thread-0 Testing: {&#8221;case&#8221;:&#8221;/path/to/test/case/file.name&#8221;,&#8221;expectedProduced&#8221;:[[«expected object», «produced object»], «&#8230;»], &#8220;expectedMissed&#8221;:[ «...» ], &#8220;unexpectedProduced&#8221;:[ «...» ]}
** 2006-01-25 12:34:57  INFO  Thread-0 Testing: {&#8221;case&#8221;:&#8221;/path/to/test/case/file.name&#8221;,&#8221;expectedProduced&#8221;:[[{"foo":"bar"}, {"foo":"bar"}], «&#8230;»], &#8220;expectedMissed&#8221;:[{"foo":"baz"}], &#8220;unexpectedProduced&#8221;:[{"foo":"quux"]}</p>

<p>The process of logging general objects is made much easier by using a reflection-based utility class I wrote that will <em>json-stringify</em> random objects thrown at it, but that&#8217;s for another post&#8230;</p>

<p>A nice feature of JSON &ndash; being a subset of javascript &ndash; is that it is
trivially parsed in javascript with an eval statement.  As such, it&#8217;s simple
to write an HTML page that accepts pasted JSON and renders it as nested
tables.  As this accepts and evaluates arbitrary javascript, I won&#8217;t link to
it, but instead present the (mostly) short page here:</p>

<p><html>
<head>
<script type="text/javascript">
// @param n The node into which to add the table.
// @param o The javascript object to expand
function addTable(n, o)
{
var tbl = document.createElement('table')
tbl.border = '1'
tbl.cellSpacing = '0'
tbl.cellPadding = '2'
for (propName in o)
{
var atEnd = -1
var row = tbl.insertRow(atEnd)
row.vAlign = 'top'
var name = row.insertCell(atEnd)
name.innerHTML = propName
var val = row.insertCell(atEnd)
var obj = o[propName]
var objCtor = obj.constructor
if (objCtor == window.Array
|| objCtor == window.Object)
{
addTable(val, obj)
}
else
{
val.innerHTML = obj.toString()
}
}
n.appendChild(tbl)
}</p>

<p>function decode()
{
var ta = document.getElementById('json');
var e = eval('(' + ta.value + ')')
var div = document.getElementById('decoded');
while (div.hasChildNodes()) { div.removeChild(div.firstChild); }
addTable(div, e);
ta.value = '';
}
</script>
</head>
<body>
<h1>json:</h1>
<form method="POST">
<textarea rows="5" cols="80" id="json">
</textarea><br />
<input type="submit" onClick="decode(); return false;"/>
<input type="reset" />
</form>
<h1>decoded:</h1>
<div id="decoded" />
</body>
</html></p>

<p>This can be copied and pasted into a local HTML file; it runs entirely
locally.  Alternatively, uncompress <a href="/2006/json.html.tar.gz">this compressed version</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2006/01/25/logging-in-json/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>moving GnuCash from CVS to SVN using cvs2svn.py</title>
		<link>http://www.asynchronous.org/blog/archives/2005/12/06/moving-gnucash-from-cvs-to-svn-using-cvs2svnpy</link>
		<comments>http://www.asynchronous.org/blog/archives/2005/12/06/moving-gnucash-from-cvs-to-svn-using-cvs2svnpy#comments</comments>
		<pubDate>Wed, 07 Dec 2005 06:28:34 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=71</guid>
		<description><![CDATA[I was responsible for moving the GnuCash CVS
repository over to Subversion, which was an
interesting experience.

The basics are covered in all the applicable documentation, though
there&#8217;s are some things I distilled out, primarily around cvs2svn.

cvs2svn is seperately available from
http://cvs2svn.tigris.org/ but has not-quite-direct docs about how to do what
I&#8217;d imagine is a pretty straightforward thing: dump multiple CVS [...]]]></description>
			<content:encoded><![CDATA[<p>I was responsible for moving the <a href="http://www.gnucash.org/">GnuCash</a> CVS
repository over to <a href="http://subversion.tigris.org/">Subversion</a>, which was an
interesting experience.</p>

<p>The basics are covered in all the applicable documentation, though
there&#8217;s are some things I distilled out, primarily around cvs2svn.</p>

<p><a href="http://cvs2svn.tigris.org/">cvs2svn</a> is seperately available from
http://cvs2svn.tigris.org/ but has not-quite-direct docs about how to do what
I&#8217;d imagine is a pretty straightforward thing: dump multiple CVS modules into
seperate top-level SVN directories following the recommended
&#8220;module/{trunk,branches,tags}/&#8221; convention.  It turns out, from the cvs2svn
FAQ, the incantations are:</p>

<ul>
<li><code>~/cvs2svn-1.3.0/cvs2svn [options below] --dump-only --dumpfile=moduleA.dump /path/to/cvs/repo/moduleA</code></li>
<li><code>svn mkdir file:///path/to/svn/repo/moduleA</code></li>
<li><code>svnadmin --parent-dir moduleA load /path/to/svn/repo &lt; moduleA.dump</code></li>
</ul>

<p>There were two sets of options that we needed to add: the first around
symbol renaming, and the second dealing with binary files.</p>

<p>The list of symbol transform arguments to cvs2svn to do branch- and
tag-renaming was:</p>

<p>&#8211;symbol-transform=&#8217;gnucash-([0-9]+)-([0-9]+)-branch:\1.\2&#8242;
&#8211;symbol-transform=&#8217;gnucash-docs-([0-9]+)-([0-9]+)-branch:\1.\2&#8242;
&#8211;symbol-transform=&#8217;gnucash-([0-9]+)-([0-9]+)-([0-9]+)-rc:\1.\2.\3-rc&#8217;
&#8211;symbol-transform=&#8217;gnucash-([0-9]+)-([0-9]+)-([0-9]+[a-z]+?):\1.\2.\3&#8242;
&#8211;symbol-transform=&#8217;gnucash-([0-9]+)-([0-9]+)-(.*):\1.\2.\3&#8242;
&#8211;symbol-transform=&#8217;gnucash-docs-([0-9]+)-([0-9]+)-([0-9]+):\1.\2.\3&#8242;
&#8211;symbol-transform=&#8217;root-of-gnucash-([0-9]+)-([0-9]+):\1.\2-root&#8217;</p>

<p>Turns out some of the historical CVS gnucash files aren&#8217;t appropriately
tagged binary, and for some reason cvs2svn or svn itself wasn&#8217;t really
doing the right thing.  As such, I needed to override the mime-types and
eol-handling with the options:</p>

<p>&#8211;no-default-eol
&#8211;eol-from-mime-type
&#8211;mime-types=/root/test.mime.types</p>

<p>It turns out that you just have to use all these options together,
basically.  <code>/root/test.mime.types</code> was cobbled together by grepping the
<code>image/*</code> types out from the normal mime.types, then extending the
<code>application/octet-stream</code> entry for some gnucash-specific extensions.
Specifically:</p>

<p>application/octet-stream        bin dms lha lzh exe class so dll xac gmo</p>

<p>Apart from that, cvs2svn does all the work, here.  After running the
svnadmin import, the dumpfile for moduleA will be imported into the
directory &#8216;moduleA&#8217; in the SVN repo, and Bob&#8217;s your uncle.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2005/12/06/moving-gnucash-from-cvs-to-svn-using-cvs2svnpy/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jython ui shell, async map</title>
		<link>http://www.asynchronous.org/blog/archives/2005/10/04/jython-ui-shell-async-map</link>
		<comments>http://www.asynchronous.org/blog/archives/2005/10/04/jython-ui-shell-async-map#comments</comments>
		<pubDate>Tue, 04 Oct 2005 18:42:53 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=67</guid>
		<description><![CDATA[From time to time at work I use a little swing Jython shell to do various and sundry interactive tasks against our system &#8230; either poking at vm-local code in development or against one of the runtime development or staging instances.  It&#8217;s quite useful when it is.

One thing I often find myself doing is [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time at work I use a <a href="/blog/archives/2005/02/18/simple_swing_jython_shell.html">little swing Jython shell</a> to do various and sundry interactive tasks against our system &#8230; either poking at vm-local code in development or against one of the runtime development or staging instances.  It&#8217;s quite useful when it is.</p>

<p>One thing I often find myself doing is processing some chunk of data, which sometimes can take either a good chunk of &#8212; or unknown amount of &#8212; time.   The simple implementation of my little jython shell blocks the UI while the python is processing, which is less than ideal for long-running jobs.  I&#8217;ve done various ad-hoc threaded solutions for this before, but finally generalized it today.</p>

<p>AsyncMap functions like <code>map</code>, but asynchronously.  As it applies the given function to the elements of the given list, it will update a JLabel with its position in the list, as well as the last- and average-times taken processing the elements.</p>

<p>The one potential dependence on my scenario it has is that the global <code>win</code> is expected to contain the JFrame of the UI; but if you supply it another JLabel already placed in the UI appropriately, &amp;c., it&#8217;ll happily use that.</p>

<p>from java.lang import Runnable
class AsyncMap (Runnable):
&#8221;&#8217;asynchronous <code>map</code>; reporting position and time-stats to given ui label.&#8221;&#8217;
def <strong>init</strong>(self, fn, inList, label = None):
from javax.swing import JLabel
from java.lang import Thread
self.fn = fn
self.inList = inList
self.outList = []
self.errs = []
if not label:
label = JLabel(&#8217;&#8212; uninit &#8212;&#8217;)
win.contentPane.add(label)
win.pack()
self.label = label
self.thread = Thread(self)
def start(self):
self.thread.start()
def run(self):
from java.lang import System
totalTime = 0
self.label.text = &#8216;0/%d&#8217; % (len(self.inList))
for idx,item in [(i,self.inList[i]) for i in range(len(self.inList))]:
start = System.currentTimeMillis()
res = None
try:
res = self.fn(item)
except:
self.errs.append(&#8221;error at %d&#8221; % (idx))
end = System.currentTimeMillis()
self.outList.append(res)
time = end-start
totalTime = totalTime + time
avgTime = totalTime / (idx+1)
self.label.text = &#8216;%d / %d &#8211; last: %f, avg: %f&#8217; % (idx+1, len(self.inList), time, avgTime)
self.label.text = &#8216;DONE: %s&#8217; % (self.label.text)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2005/10/04/jython-ui-shell-async-map/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>hotswap changed java code into a JVM with hotswap.jar</title>
		<link>http://www.asynchronous.org/blog/archives/2005/06/16/hotswap-changed-java-code-into-a-jvm-with-hotswapjar</link>
		<comments>http://www.asynchronous.org/blog/archives/2005/06/16/hotswap-changed-java-code-into-a-jvm-with-hotswapjar#comments</comments>
		<pubDate>Thu, 16 Jun 2005 20:36:10 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=64</guid>
		<description><![CDATA[I&#8217;ve found an ant task and java utility code for hotswapping code into a JVM using the JPDA debugging interface.

Though it requires a pretty recent version of ant, it does work really well &#8230; within some constraints of the JVM/JPDA interface itself.  Specifically, you apparently cannot add, remove or change the signature of methods [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found an <a href="http://hotswap.dev.java.net/">ant task and java utility code for hotswapping code into a JVM</a> using the JPDA debugging interface.</p>

<p>Though it requires a pretty recent version of ant, it does work really well &#8230; within some constraints of the JVM/JPDA interface itself.  Specifically, you apparently cannot add, remove or change the signature of methods via said interface &#8230; so whole-sale changes to the program code aren&#8217;t going to work.  But, for a wide variety of minor changes and tweaks, hotswap.jar is incredibly useful.</p>

<p>Nevermind the bits about constructing timestamps in his instructions &#8230; <code>touch</code> a sentinel file to keep track of load-times, and use ant&#8217;s built-in <code>depend</code> mechanism.  For example, with a server in <code>server/</code> depending on shared utility code in <code>common/</code> and per-module build-output going into <code>server/build/java</code>, <code>common/build/java</code>, &amp;c&#8230;</p>

<p><target name="run-server">
<touch file="server/build/classloadMarker" />
<java classname="foo.bar.Main" fork="true" failonerror="true">
<classpath refid="run.classpath"/>
<sysproperty key="log4j.configuratorClass" value="foo.bar.log.OurLogConfigurator"/>
<jvmarg value="-Xmx256m"/>
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=9000,server=y,suspend=n" />
</java>
</target></p>

<p><target name="hotswap-server">
<taskdef name="hotswap" classname="dak.ant.taskdefs.Hotswap"/>
<hotswap verbose="true" port="9000">
<fileset dir="server/build/java" includes="**/*.class">
<depend targetdir="server/build">
<mapper type="merge" to="classloadMarker" />
</depend>
</fileset>
<fileset dir="common/build/java" includes="**/*.class">
<depend targetdir="server/build">
<mapper type="merge" to="classloadMarker" />
</depend>
</fileset>
</hotswap>
<touch file="server/build/classloadMarker" />
</target></p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2005/06/16/hotswap-changed-java-code-into-a-jvm-with-hotswapjar/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>software development in 2005</title>
		<link>http://www.asynchronous.org/blog/archives/2005/05/05/software-development-in-2005</link>
		<comments>http://www.asynchronous.org/blog/archives/2005/05/05/software-development-in-2005#comments</comments>
		<pubDate>Thu, 05 May 2005 18:20:21 +0000</pubDate>
		<dc:creator>jsled</dc:creator>
				<category><![CDATA[~/stuff/programming]]></category>

		<guid isPermaLink="false">http://www.asynchronous.org/blog/?p=63</guid>
		<description><![CDATA[It&#8217;s really frustruating to write software, sometimes.  Computers are exceedingly literal, and true abstraction is quite hard to come by.  Adding documentation, written by wonderfully-silly humans,doesn&#8217;t always help, either.

For instance, Struts has a nifty feature for &#8220;map-based form properties&#8221;.  Basically, if you write in your page:


  &#60;input type=&#8221;text&#8221; name=&#8221;nameMap(foo)&#8221; value=&#8221;bar&#8221; /&#62;


And [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s really frustruating to write software, sometimes.  Computers are exceedingly literal, and true abstraction is quite hard to come by.  Adding documentation, written by wonderfully-silly humans,doesn&#8217;t always help, either.</p>

<p>For instance, <a href="http://struts.apache.org/">Struts</a> has a nifty feature for <a href="http://struts.apache.org/userGuide/building_controller.html#map_action_form_classes">&#8220;map-based form properties&#8221;</a>.  Basically, if you write in your page:</p>

<blockquote>
  <p>&lt;input type=&#8221;text&#8221; name=&#8221;nameMap(foo)&#8221; value=&#8221;bar&#8221; /&gt;</p>
</blockquote>

<p>And when submitted, <code>form.setNameMap("foo", "bar")</code> will be called.  Quite nice when you have a lot of dynamic content in the page and you&#8217;re trying to figure out how it needs to be related at form-submit time&#8230;</p>

<p>In fact most of Struts&#8217; handling of forms is simple bean-addressing strings&#8230; you can create &#8220;nested&#8221; paths with &#8216;.&#8217; (e.g., &#8220;<code>person.name.first</code>&#8220;), and do indexed properties with &#8216;[]&#8216; (e.g., &#8220;names[42]&#8220;).</p>

<p>So, what happens when you want to use</p>

<blockquote>
  <p>&lt;input type=&#8221;text&#8221; name=&#8221;nameMap( [ :name &quot;joe bob&quot;; :email &quot;root@127.0.0.1&quot; ] )&#8221; /&gt;</p>
</blockquote>

<p>&#8230;? That&#8217;s an expression repressenting a single mapped-property call, with a string argument, right?</p>

<p>Ha Ha, no.</p>

<p>Turns out that the simplest thing that could possibly work here is to do <code>String.indexOf()</code> calls with the various delimiters.  So the first thing that hits is the &#8216;.&#8217; in the email address.  Should that not have been there, the &#8216;[&#8217; would be next up.  Of course, neither are at all right.  And, of course, in traditional programmer style, the documentation is perfectly willing to make believe that the expression syntax is robust and well-behaved.</p>

<p>A request to other programmers: any time your &#8220;parser&#8221; is based around calls to <code>indexOf</code>, then you need a big &#8220;THIS IS A HACK PARSER&#8221; disclaimer in your documentation, so people will give it this distance it deserves.</p>

<p><em>Update, a few minutes later</em>:</p>

<p>It also does not help that the entire error you get when you make this mistake is&#8230;</p>

<blockquote>
  <p>HTTP ERROR: 500 BeanUtils%2Epopulate</p>
  
  <p>RequestURI=/secure/dedup/un-c11n.spoke</p>
</blockquote>

<p>&#8230;in the browser, and the misleading&#8230;</p>

<blockquote>
  <p>Caused by: java.lang.NoSuchMethodException: Property &#8216;namePerson&#8217; has no setter method</p>
</blockquote>

<p>&#8230;in the exception.  Thanks, BeanUtils, for perhaps having the worst error messages evar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.asynchronous.org/blog/archives/2005/05/05/software-development-in-2005/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
