<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>418 I&apos;m a teapot</title>
    <link rel="alternate" type="text/html" href="http://little418.com/" />
    <link rel="self" type="application/atom+xml" href="http://little418.com/atom.xml" />
    <id>tag:little418.com,2009-05-14://4</id>
    <updated>2010-03-04T23:13:21Z</updated>
    <subtitle>The resulting entity body MAY be short and stout.</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.25</generator>

<entry>
    <title>GoDaddy SSL Certificate in Zeus ZXTM Traffic Managers</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2010/03/godaddy-ssl-certificate-in-zeus-zxtm-traffic-managers.html" />
    <id>tag:little418.com,2010://4.415</id>

    <published>2010-03-04T22:58:45Z</published>
    <updated>2010-03-04T23:13:21Z</updated>

    <summary>Almost a year ago I purchased a wildcard SSL certificate from GoDaddy. When it was first issued I simply loaded it into into my Zeus ZXTM load balancer with the import button. Everything seemed fine for quite awhile. I visited my web site in Firefox and in all of the flavors of IE. It seemed to work great. That is, until, someone called me to let me know that Safari was not accepting the certificate! I thought I was in trouble until I googled around and found many blog entries about the root cause. It turns out that my server,...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
    <category term="godaddy" label="GoDaddy" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="ssl" label="SSL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="zeus" label="Zeus" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>Almost a year ago I purchased a wildcard SSL certificate from GoDaddy.  When it was first issued I simply loaded it into into my Zeus ZXTM load balancer with the import button.  </p>

<p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://little418.com/assets_c/2010/03/cert1-23.html" onclick="window.open('http://little418.com/assets_c/2010/03/cert1-23.html','popup','width=728,height=514,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://little418.com/assets_c/2010/03/cert1-thumb-400x282-23.jpg" width="400" height="282" alt="cert1.jpg" class="mt-image-center" style="text-align: center; display: block; margin: 0 auto 20px;" /></a></span></p>

<p>Everything seemed fine for quite awhile.  I visited my web site in Firefox and in all of the flavors of IE.  It seemed to work great.  That is, until, someone called me to let me know that Safari was not accepting the certificate!  I thought I was in trouble until I googled around and found <a href="http://www.symphonious.net/2008/06/04/tomcat-os-x-safari-and-godaddy-ssl-certificates/">many</a> <a href="http://blog.boxedice.com/2009/05/11/godaddy-ssl-certificates-and-cannot-verify-identity-on-macsafari/">blog entries</a> about the root cause.  It turns out that my server, or in this case my Zeus ZXTM load balancer, was not configured to display the whole certificate chain back to the root authority.  </p>

<p>This makes me wonder how this worked at all in every other web browser.  Perhaps this is such a common problem that the other browsers hack around it? </p>

<p>Anyway, the fix was easy enough but the terminology was different.  Rather than an SSLCertificateChainFile, my ZXTM called it an &#8216;Intermediate Certificate&#8217;.  One click of a button, browsing to <code>gd_bundle.crt</code> (provided with my original certificate), and it was loaded up and the issue was fixed.</p>

<p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://little418.com/assets_c/2010/03/cert2-26.html" onclick="window.open('http://little418.com/assets_c/2010/03/cert2-26.html','popup','width=564,height=405,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://little418.com/assets_c/2010/03/cert2-thumb-500x359-26.jpg" width="500" height="359" alt="cert2.jpg" class="mt-image-center" style="text-align: center; display: block; margin: 0 auto 20px;" /></a></span></p>
]]>
        

    </content>
</entry>

<entry>
    <title>channel 2: open failed: administratively prohibited: open failed</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2010/03/channel-2-open-failed-administratively-prohibited-open-failed.html" />
    <id>tag:little418.com,2010://4.414</id>

    <published>2010-03-02T23:16:57Z</published>
    <updated>2010-03-02T23:22:28Z</updated>

    <summary>I attempted to set up an SSH tunnel today to access a web application that was only bound to a private IP. I tunneled to my opensolaris box, which worked fine, and then attempted to establish a connection with telnet. Telnet reported that the connection was refused and I saw this on my command line for the tunnel: $ ssh johndoe@foo.bar.com -L 8080:foo.bar.com:8080 -N channel 2: open failed: administratively prohibited: open failed I made a pretty silly mistake, but I figure it may save someone&#8217;s time to post it here. Of course the connection was refused. My ssh tunnel attempts...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
    <category term="opensolaris" label="opensolaris" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="solaris" label="solaris" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="sshtunnel" label="ssh tunnel" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>I attempted to set up an SSH tunnel today to access a web application that was only bound to a private IP.  I tunneled to my opensolaris box, which worked fine, and then attempted to establish a connection with telnet.  Telnet reported that the connection was refused and I saw this on my command line for the tunnel:</p>

<pre class="brush: bash">
$ ssh johndoe@foo.bar.com -L 8080:foo.bar.com:8080 -N
channel 2: open failed: administratively prohibited: open failed
</pre>

<p>I made a pretty silly mistake, but I figure it may save someone&#8217;s time to post it here.  Of course the connection was refused.  My ssh tunnel attempts to establish the connection to the public domain name, which uses the public IP (the same one I&#8217;m SSHing into).  The web server I&#8217;m trying to reach is not bound to that adapter!</p>

<p>Here&#8217;s a correct command:</p>

<pre class="brush: bash">
$ ssh johndoe@foo.bar.com -L 8080:localhost:8080 -N
</pre>
]]>
        

    </content>
</entry>

<entry>
    <title>Java Mime Type Content Type</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2010/02/java-mime-type-content-type-1.html" />
    <id>tag:little418.com,2010://4.413</id>

    <published>2010-02-25T22:55:37Z</published>
    <updated>2010-02-25T23:03:59Z</updated>

    <summary>I&#8217;ve been working on a Java servlet these days which for many reasons needs to determine the mime type of files so that files being rendered are correctly used by my clients. For example, I&#8217;m generating a crossdomian.xml, which if not matched with the text/xml content type, really confuses flash players. Anyway, I fumbled around for a bit in Google and found one great solution: mime-util. It&#8217;s Apache License and works great. The documentation is even very good. Since I can trust my file names I opted for the simple file name extension detection method. It&#8217;s a perfect fit except...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>I&#8217;ve been working on a Java servlet these days which for many reasons needs to determine the mime type of files so that files being rendered are correctly used by my clients.  For example, I&#8217;m generating a crossdomian.xml, which if not matched with the text/xml content type, really confuses flash players.</p>

<p>Anyway, I fumbled around for a bit in Google and found one great solution: <a href="http://www.medsea.eu/mime-util/">mime-util</a>.  It&#8217;s <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License</a> and works great.  The <a href="http://www.medsea.eu/mime-util/documentation.html">documentation</a> is even very good.  </p>

<p>Since I can trust my file names I opted for the simple file name extension detection method.  It&#8217;s a perfect fit except for one thing: I need to detect the application/json content type which is not part of the default property bundle.</p>

<p>It took me a few minutes of digging trough the JavaDocs to find the answer, so to save you some time, here&#8217;s my solution:</p>

<ol>
<li>Create a file named <code>mime-types.properties</code> and put it somewhere in your class path.  </li>
<li>Add the types you need as extension=type pairs like <code>json=application/json</code></li>
</ol>
]]>
        

    </content>
</entry>

<entry>
    <title>Java Mime Type Content Type</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2010/02/java-mime-type-content-type.html" />
    <id>tag:little418.com,2010://4.412</id>

    <published>2010-02-25T22:55:37Z</published>
    <updated>2010-02-25T23:03:11Z</updated>

    <summary>I&#8217;ve been working on a Java servlet these days which for many reasons needs to determine the mime type of files so that files being rendered are correctly used by my clients. For example, I&#8217;m generating a crossdomian.xml, which if not matched with the text/xml content type, really confuses flash players. Anyway, I fumbled around for a bit in Google and found one great solution: mime-util. It&#8217;s Apache License and works great. The documentation is even very good. Since I can trust my file names I opted for the simple file name extension detection method. It&#8217;s a perfect fit except...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="Java" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="java" label="java" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="json" label="json" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="library" label="library" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>I&#8217;ve been working on a Java servlet these days which for many reasons needs to determine the mime type of files so that files being rendered are correctly used by my clients.  For example, I&#8217;m generating a crossdomian.xml, which if not matched with the text/xml content type, really confuses flash players.</p>

<p>Anyway, I fumbled around for a bit in Google and found one great solution: <a href="http://www.medsea.eu/mime-util/">mime-util</a>.  It&#8217;s <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License</a> and works great.  The <a href="http://www.medsea.eu/mime-util/documentation.html">documentation</a> is even very good.  </p>

<p>Since I can trust my file names I opted for the simple file name extension detection method.  It&#8217;s a perfect fit except for one thing: I need to detect the application/json content type which is not part of the default property bundle.</p>

<p>It took me a few minutes of digging trough the JavaDocs to find the answer, so to save you some time, here&#8217;s my solution:</p>

<ol>
<li>Create a file named <code>mime-types.properties</code> and put it somewhere in your class path.  </li>
<li>Add the types you need as extension=type pairs like <code>json=application/json</code></li>
</ol>
]]>
        

    </content>
</entry>

<entry>
    <title>E575: viminfo: Illegal starting char in line:</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2010/02/e575-viminfo-illegal-starting-char-in-line.html" />
    <id>tag:little418.com,2010://4.410</id>

    <published>2010-02-18T20:19:56Z</published>
    <updated>2010-02-18T20:27:27Z</updated>

    <summary>Once upon a time I tried to open a file for editing with MacVim and saw this message: $ vi foo.xml E575: viminfo: Illegal starting char in line: ion.properties $ I assumed there was something wrong with the file that I was editing, so I tried a different file. I observed the same result. **The Problem Your .viminfo file is corrupt. This file does not contain settings or anything, mostly temporary and working data. **The Fix Delete your ~/.viminfo file...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
    <category term="editor" label="editor" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="error" label="error" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="vi" label="vi" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="vim" label="vim" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>Once upon a time I tried to open a file for editing with <a href="http://macvim.org/">MacVim</a> and saw this message:</p>

<pre class="brush: bash">
$  vi foo.xml 
E575: viminfo: Illegal starting char in line: ion.properties
$
</pre>

<p>I assumed there was something wrong with the file that I was editing, so I tried a different file.  I observed the same result.</p>

<p><em>*</em>*The Problem
Your .viminfo file is corrupt.  This file does not contain settings or anything, mostly temporary and working data.</p>

<p><em>*</em>*The Fix
Delete your ~/.viminfo file</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Grails restart loop</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2010/01/grails-restart-loop.html" />
    <id>tag:little418.com,2010://4.409</id>

    <published>2010-01-27T23:35:55Z</published>
    <updated>2010-01-27T23:47:11Z</updated>

    <summary>The Problem The other day I was doing some bulk file operations on a grails project. I was moving some classes in bulk from a plug-in into an application. After I made the move I ran into a puzzling issue: grails kept restarting in a loop. Each time the plugin scanner ran (every 5 seconds after startup), grails would complain that it needed to compile 1 file. This went on for a few minutes until my app ran out of PermGen and crashed. To make matters worse, grails would not tell me which file it was recompiling even with logging...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="Groovy on Grails" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="grailsv12" label="grails v1.2" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<h3>The Problem</h3>

<p>The other day I was doing some bulk file operations on a grails project.  I was moving some classes in bulk from a plug-in into an application.  After I made the move I ran into a puzzling issue: grails kept restarting in a loop.  Each time the plugin scanner ran (every 5 seconds after startup), grails would complain that it needed to compile 1 file.  This went on for a few minutes until my app ran out of PermGen and crashed.  To make matters worse, grails would not tell me which file it was recompiling even with logging set to trace!</p>

<p>This seems to be a <a href="http://old.nabble.com/Endless-restart-loop---how-to-find-broken-class--to18482221.html">classic grails issue</a> that is rare, but frustrating. </p>

<h3>The Cause</h3>

<p>The likely cause is a groovy file outside the correct package or with a file name that does not match the case name.  The latter can happen when tinkering around between case sensitive and case insensitive file systems as is common when developing with OS X.</p>

<h3>The Fix</h3>

<p>To fix it you need to find the messed up class and fix it.  The below method is crude, but works.</p>

<ol>
<li>If your app crashes quickly due to PermGen issues, provide more PermGen space.  You&#8217;ll need at least 2 or 3 minutes of run time for this to work.  Use the JVM argument -XX:MaxPermSize=1024m if you have to.</li>
<li>Let your app run for a few minutes.  Let it recompile that file a few times.</li>
<li>If your app has not already crashed, stop it</li>
<li>Now to find the compiled class file.  Go to the directory where grails claims to be compiling the file.  In my case it was in <code>~/.grails/1.2.0/projects/fooApp/classes</code></li>
<li>Run this shell command to see when most of the files were updated: <code>find ./  | xargs ls -al</code>  The vast majority of the listed files should all have an updated time within the same minute.  In my case it was 15:17  Lets fileter those out and see what&#8217;s left behind.</li>
<li>Run another find command and see the newer files: <code>find ./  | xargs ls -al | grep -v 15:17</code>.  I saw a few files and headers that had to be ignored, but in the middle I found the class name which was compiled from a .groovy file of a different name.</li>
<li>Go back to your app code and resolve the conflicted state of your groovy file(s)</li>
<li>Quit cursing under your breath and go have a beer if you need one</li>
</ol>
]]>
        

    </content>
</entry>

<entry>
    <title>Simple Basic Authentication from Java Servlet Example</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2010/01/simple-basic-authentication-from-java-servlet-example.html" />
    <id>tag:little418.com,2010://4.408</id>

    <published>2010-01-04T19:13:17Z</published>
    <updated>2010-01-04T19:24:56Z</updated>

    <summary><![CDATA[Basic Auth is a very simple way to secure your web application. When combined with a secure transport technology like SSL, it&#8217;s also good enough in most cases. Here is a dirt simple example of how to access the basic authentication information from the HTTP header in your servlet. protected void doGet(HttpServletRequest request, HttpServletResponse response) { String pathInfo = request.getPathInfo(); //will contain "Basic Ym9iOnNlY3JldA==" String header = request.getHeader(&quot;Authorization&quot;); //always wise to assert your assumptions assert header.substring(0, 6).equals(&quot;Basic &quot;); //will contain "Ym9iOnNlY3JldA==" String basicAuthEncoded = header.substring(6); //will contain "bob:secret" String basicAuthAsString = new String( new Base64().decode(basicAuthEncoded.getBytes())); ... } You can test...]]></summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="Java" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="example" label="example" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="java" label="java" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="security" label="security" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p><a href="http://en.wikipedia.org/wiki/Basic_access_authentication">Basic Auth</a> is a very simple way to secure your web application.  When combined with a secure transport technology like SSL, it&#8217;s also good enough in most cases.</p>

<p>Here is a dirt simple example of how to access the basic authentication information from the HTTP header in your servlet.</p>

<pre class="brush: java">
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
    String pathInfo = request.getPathInfo();
    //will contain "Basic Ym9iOnNlY3JldA=="
    String header = request.getHeader(&quot;Authorization&quot;); 
    //always wise to assert your assumptions
    assert header.substring(0, 6).equals(&quot;Basic &quot;); 
    //will contain "Ym9iOnNlY3JldA=="
    String basicAuthEncoded = header.substring(6);
    //will contain "bob:secret"
    String basicAuthAsString = new String(
        new Base64().decode(basicAuthEncoded.getBytes()));
    ...
}
</pre>

<p>You can test it with this curl command:</p>

<pre class="brush: bash">
$  curl -vv http://bob:secret@localhost:8090/blah
* About to connect() to localhost port 8090 (#0)
*   Trying ::1... connected
* Connected to localhost (::1) port 8090 (#0)
* Server auth using Basic with user 'bob'
 GET /blah HTTP/1.1
 Authorization: Basic Ym9iOnNlY3JldA==
 User-Agent: curl/7.19.4 (universal-apple-darwin10.0) libcurl/7.19.4 OpenSSL/0.9.8k zlib/1.2.3
 Host: localhost:8090
 Accept: */*
...
</pre>
]]>
        

    </content>
</entry>

<entry>
    <title>grails Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: org/codehaus/groovy/grails/cli/support/GrailsStarter</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2009/12/grails-exception-in-thread-main-javalangnoclassdeffounderror-orgcodehausgroovygrailsclisupportgrails.html" />
    <id>tag:little418.com,2009://4.407</id>

    <published>2009-12-31T21:35:57Z</published>
    <updated>2009-12-31T21:50:45Z</updated>

    <summary>Maybe you just upgraded Groovy on Grails, or maybe you&#8217;re doing a fresh install. Either way you may be confronted with this curious error message: $ grails test Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: org/codehaus/groovy/grails/cli/support/GrailsStarter What&#8217;s wrong? You have a grails mismatch. Your GRAILS_HOME environment variable is not pointing to the same place as the grails in your PATH. Make them agree and try your grails command again....</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="Groovy on Grails" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="configuration" label="configuration" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="error" label="error" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="grails" label="grails" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>Maybe you just upgraded Groovy on Grails, or maybe you&#8217;re doing a fresh install.  Either way you may be confronted with this curious error message:</p>

<pre class="brush: bash">
$ grails test
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/grails/cli/support/GrailsStarter
</pre>

<p>What&#8217;s wrong?  You have a grails mismatch.  Your GRAILS_HOME environment variable is not pointing to the same place as the grails in your PATH.   Make them agree and try your grails command again.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>System call sent warnings to stderr: pst3: This program can only be run  by the root user!</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2009/12/system-call-sent-warnings-to-stderr-pst3-this-program-can-only-be-run-by-the-root-user.html" />
    <id>tag:little418.com,2009://4.406</id>

    <published>2009-12-08T02:49:59Z</published>
    <updated>2009-12-08T02:55:30Z</updated>

    <summary>I ran into this very cryptic one while setting up Nagios at Joyent. I copied my plugins from one nrpe client to a new server. Three of my checks used check_procs which all failed with a message like this: check_procs System call sent warnings to stderr: pst3: This program can only be run by the root user! To make this even more annoying, sudo did not fix it. The same error message was displayed. What was the problem? File permissions! The error message should say &#8220;This program must be owned by the root user!&#8221; The fix: sudo chmod root:root pst3...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="Joyent" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Nagios" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Solaris 10" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="error" label="error" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="joyent" label="joyent" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="nagios" label="nagios" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>I ran into this very cryptic one while setting up Nagios at Joyent.  I copied my plugins from one nrpe client to a new server.  Three of my checks used <code>check_procs</code> which all failed with a message like this:</p>

<pre class="brush: bash">
check_procs
System call sent warnings to stderr: pst3: This program can only be run by the root user!
</pre>

<p>To make this even more annoying, <code>sudo</code> did not fix it.  The same error message was displayed.  What was the problem?  File permissions!  The error message should say &#8220;<code>This program must be owned by the root user!</code>&#8221;  The fix:</p>

<pre class="brush: bash">
sudo chmod root:root pst3
</pre>
]]>
        

    </content>
</entry>

<entry>
    <title>Cancel Postgres query</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2009/12/cancel-postgre-query.html" />
    <id>tag:little418.com,2009://4.405</id>

    <published>2009-12-04T21:37:18Z</published>
    <updated>2009-12-04T22:01:33Z</updated>

    <summary><![CDATA[Do you need to cancel / abort / terminate a long running query in PostgreSql? Perhaps you ran a very nasty select or kicked off an index creation that&#8217;s blocking inserts. Either way, stopping a long running query is easy. Log into postgres as the super user: psql -U postgres Find your query postgres=&gt; select procpid, current_query from pg_stat_activity; procpid | current_query ---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 8093 | &lt;IDLE&gt; 8172 | &lt;IDLE&gt; 9357 | &lt;IDLE&gt; 9358 | &lt;IDLE&gt; 17360 | select procpid, current_query from pg_stat_activity; 9359 | &lt;IDLE&gt; 22429 | drop index fooindex; 20363 | &lt;IDLE&gt; 29098 | &lt;IDLE&gt; 1083 | &lt;IDLE&gt; 10812...]]></summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="PostgreSQL" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="postgresql83" label="postgresql 8.3" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>Do you need to cancel / abort / terminate a long running query in PostgreSql?  Perhaps you ran a very nasty select or kicked off an index creation that&#8217;s blocking inserts.  Either way, stopping a long running query is easy.</p>

<ol>
<li>Log into postgres as the super user: <code>psql -U postgres</code></li>
<li>Find your query</li>
</ol>

<pre class="brush: sql">
postgres=&gt; select procpid, current_query from pg_stat_activity;
 procpid |                                                                                                                                   current_query                                                                                                                                    
---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    8093 | &lt;IDLE&gt;
    8172 | &lt;IDLE&gt;
    9357 | &lt;IDLE&gt;
    9358 | &lt;IDLE&gt;
   17360 | select procpid, current_query from pg_stat_activity;
    9359 | &lt;IDLE&gt;
   22429 | drop index fooindex;
   20363 | &lt;IDLE&gt;
   29098 | &lt;IDLE&gt;
    1083 | &lt;IDLE&gt;
   10812 | &lt;IDLE&gt;
   10855 | &lt;IDLE&gt;
(13 rows)
</pre>

<ol>
<li>Use <code>pg cancel backend</code> to stop the query</li>
</ol>

<pre calss="brush: sql">
postgres=# select pg_cancel_backend(22429);
 pg_cancel_backend 
-------------------
 t
(1 row)
</pre>

<p>All done.  Your query was cancled.  If you were creating an index you may have an invalid index which will require clean up later.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Rendering Groovy GSP Code From A String</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2009/11/rendering-groovy-gsp-code-from-a-string.html" />
    <id>tag:little418.com,2009://4.402</id>

    <published>2009-11-11T18:41:36Z</published>
    <updated>2010-01-06T01:30:55Z</updated>

    <summary>Ever used WordPress? It has that cool feature that allows users to heavily customize their blogs by editing templates. If you&#8217;re trying to do something like that in Groovy on Grails, you&#8217;ve found the right blog entry. It&#8217;s quite easy as of Grails v1.1.1, although it does have some quirks and caveats. First, we&#8217;ll need to import a few classes for this to work. Add these imports to your controller: import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine import org.springframework.web.context.request.RequestContextHolder import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest Next, in our controller we&#8217;ll need the template engine. Luckily just like our grails services the framework will inject this in for us. To...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="Groovy on Grails" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="grailsv111" label="grails v1.1.1" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="groovy" label="groovy" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="gsp" label="gsp" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>Ever used <a href="http://wordpress.org">WordPress</a>?  It has that cool feature that allows users to heavily customize their blogs by editing templates.  If you&#8217;re trying to do something like that in Groovy on Grails, you&#8217;ve found the right blog entry.  It&#8217;s quite easy as of Grails v1.1.1, although it does have some quirks and caveats.  </p>

<p>First, we&#8217;ll need to import a few classes for this to work.  Add these imports to your controller:</p>

<pre class="brush: groovy">
import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine
import org.springframework.web.context.request.RequestContextHolder
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
</pre>

<p>Next, in our controller we&#8217;ll need the template engine.  Luckily just like our grails services the framework will inject this in for us.  To let it know what to inject, add this to the top of your controller:</p>

<pre class="brush: groovy">
    GroovyPagesTemplateEngine groovyPagesTemplateEngine // allows us to call the Groovy page-rendering stuff within the controller
</pre>

<p>Now for the fun part.  To render a template from a string just add this private method to your controller:</p>

<pre class="brush: groovy">
    private void renderTemplate(String content, Map model) {
        groovy.text.Template template = groovyPagesTemplateEngine.createTemplate(content, groovyPagesTemplateEngine.getCurrentRequestUri(request))
        def renderedTemplate = template.make(model)
        GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.currentRequestAttributes()

        /**
         * There are extra characters rendered into my page:
         * ServletWebRequest: uri=/app_name/grails/controller/actionname.dispatch;client=127.0.0.1;session=xgjq4afedjry
         * this is a hack to keep that stuff from being rendered into the page
         */
        def crapAtTheBeginningLength = webRequest.out.toString().length()
        renderedTemplate.writeTo(webRequest.out)
        def stringToRender = webRequest.out.toString()
        render stringToRender.substring(crapAtTheBeginningLength)
    }
</pre>

<p>Simply call this function from any action like you&#8217;d call render, except pass in the String version of the template as the first argument:</p>

<pre class="brush: groovy">
    def index = {
       String templateString = "..."; //get the template string somehow
       //... code to build out the model to be passed into the template ...
        renderTemplate(templateString, [foo: "bar", stuff: listOfStuff])
    }
</pre>

<p>This should work pretty well.  Now for the caveats:</p>

<ul>
<li>I haven&#8217;t done any load testing yet, but there may be performance implications due to the way the GSP caching works.  This technique appears to have circumvented some parts of it and may have significant negative performance impact.</li>
<li>GSP code can never be made completely safe.  Never render GSP code that was created by untrusted people.  Although you are passing a model in, the GSP can run any Groovy code that it wants to run and could result in a serious security breech.</li>
</ul>

<p>Also, no I didn&#8217;t come up with this code on my own.  Credit goes to a bunch of grails mailing list threads that I&#8217;ve lost links to, help from people in #grails on irc.freenode.net, and this <a href="http://disgruntleddevs.wordpress.com/2009/06/13/grails-rendering-a-template-from-a-string/">other blog entry on the same topic</a> and yet <a href="http://www.sinjax.net/wordpress/?p=1714">another related blog</a> entry.</p>

<p><strong>Update</strong>: Here&#8217;s <a href="http://www.sinjax.net/wordpress/?p=1714">another example</a> that&#8217;s a bit more refined.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>IntelliJ 8.1 Unresponsive on Mac</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2009/11/intellij-81-unresponsive-on-mac.html" />
    <id>tag:little418.com,2009://4.399</id>

    <published>2009-11-08T02:01:38Z</published>
    <updated>2009-11-08T02:09:34Z</updated>

    <summary>Did you just notice that your IntelliJ editor is very slow all of a sudden? Is scrolling clumsy and do the animations crawl? Did you recently change your editor settings, by chance? When this happened to me the other day my first impulse was to jump into the animation settings and then configuration files to tune the JVM memory settings as described in most Google results for &#8216;IntelliJ performance&#8217;. This was a red herring, though. I was way off. It was my friggin font setting! As part of a configuration overhaul, I had changed the editor font from the default...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="IntelliJ" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="configuration" label="configuration" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="intellij813" label="intellij 8.1.3" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="performance" label="performance" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>Did you just notice that your IntelliJ editor is very slow all of a sudden?  Is scrolling clumsy and do the animations crawl?  Did you recently change your editor settings, by chance?</p>

<p>When this happened to me the other day my first impulse was to jump into the animation settings and then configuration files to tune the JVM memory settings as described in most Google results for &#8216;<a href="http://google.com/search?q=intellij+performance">IntelliJ performance</a>&#8217;.  This was a red herring, though.  I was way off.</p>

<p>It was my friggin font setting!</p>

<p>As part of a configuration overhaul, I had changed the editor font from the default to Lucida Sans Typewriter, one of my favorite fixed width fonts.  This was the culprit for some mysterious reason!
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="IntelliJ IDEA font config" src="http://little418.com/images/IntelliJ%20IDEA%20font%20config.jpg" width="441" height="392" class="mt-image-center" style="text-align: center; display: block; margin: 0 auto 20px;" /></span>
To fix this problem change your editor font.  I found that Courier, Monospaced, and OCR A Std all performed very well.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Java Collections List Map toString</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2009/11/java-collections-list-map-tostring.html" />
    <id>tag:little418.com,2009://4.396</id>

    <published>2009-11-03T21:50:31Z</published>
    <updated>2009-11-03T22:01:34Z</updated>

    <summary>Java collections, like List and Map, are great. In fact they&#8217;re probably the most used part of the Java core APIs. They do lack one feature, though: easy to use conversion into a string representation. This is a surprisingly common task for error messages and logging. In neither of these cases is the default toString() sufficient. Typical solutions include usage of a static utility class to convert them, iterating through them in your code, or creating a subclass of your own. None of these have ever made me happy, though. They&#8217;re either too verbose or clunky and the way I...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="Java" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="designpattern" label="design pattern" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="java" label="java" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>Java collections, like List and Map, are great.  In fact they&#8217;re probably the most used part of the Java core APIs.  They do lack one feature, though: easy to use conversion into a string representation.  This is a surprisingly common task for error messages and logging.  In neither of these cases is the default <code>toString()</code> sufficient.</p>

<p>Typical solutions include usage of a static utility class to convert them, iterating through them in your code, or creating a subclass of your own.  None of these have ever made me happy, though.  They&#8217;re either too verbose or clunky and the way I want to represent a collection as a string often varies considerably from one instantiation to another.</p>

<p>I had never thought about it before, but <a href="http://www.techartifact.com/blogs/2009/08/anonymous-classes-in-java.html">Java anonymous classes</a> provide a great solution.  You can simply specify a toString function when you create a collection by subclassing it anonymously.</p>

<p>Here&#8217;s a simple example.  I have a class which contains a map.  In logs and error messages I want to simply dump the keys.</p>

<pre class="brush: java">
public class MyClass {
  private Map map;

  public MyClass() {
      map = new HashMap&lt;String, Stuff&gt;() {
          public String toString() {
              String stringForm = new String();
              for(String key : this.keySet()) {
                  stringForm += key + &quot;, &quot;;
              }
              //remove the trailing &quot;, &quot;
              stringForm.substring(0, stringForm.length()-2);
              return stringForm;
          }
      };
  }
}
</pre>

<p>Later in my code I can simply run <code>map.toString()</code> to see a comma separated list of the keys in my map.</p>

<p>Of course, this pattern only helps when you need a flexible way to represent each collection as a String and when that collection is only created in one place.  If you&#8217;re creating the collection in many methods a non-anonymous inner class may be a better fit.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Solairs PS Truncates Commands</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2009/11/solairs-ps-truncates-commands.html" />
    <id>tag:little418.com,2009://4.394</id>

    <published>2009-11-02T21:28:33Z</published>
    <updated>2009-11-02T21:36:31Z</updated>

    <summary>If you&#8217;re new to Solaris, like me, you may have noticed an annoying limitation of the default ps program built into Solaris. It truncates the commands at 80 characters! To make matters worse, the man pages don&#8217;t mention anything about this issue. The reason the man pages offer no help is because this is a kernel issue. It was decided back in 1994 that 80 characters should be enough. Since the kernel does not store more than 80 characters, ps has no way of accessing this information. Ironicly, later that decade the same company invented their &#8220;language to end all...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="Solaris 10" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="opensolaris" label="open solaris" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="solaris" label="solaris" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="tools" label="tools" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>If you&#8217;re new to Solaris, like me, you may have noticed an annoying limitation of the default <code>ps</code> program built into Solaris.  It truncates the commands at 80 characters!  To make matters worse, the man pages don&#8217;t mention anything about this issue.</p>

<p>The reason the man pages offer no help is because this is a kernel issue.  It was decided back in 1994 that 80 characters should be enough.  Since the kernel does not store more than 80 characters, <code>ps</code> has no way of accessing this information.  Ironicly, later that decade the same company invented their &#8220;language to end all languages&#8221;, Java. Unfortunately Java&#8217;s design typically resulted in <code>CLASSPATH</code> values much longer than 80 characters prepended to many commands.  </p>

<p>There is an easy solution, though.  Rather than fixing the problem Sun left us the old <code>ps</code> tool.  While this does not use their new fancy API and is probably much less efficient, it somehow has access to the full command for all running processes.  It&#8217;s officially deprecated, so use at your own risk, but here&#8217;s the equivalent of <code>ps -ef</code>:</p>

<pre class="brush: bash">/usr/ucb/ps axww</pre>

<p>Note the different path to the command.  Time to set up an alias.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>PostgreSql Shared Memory Error</title>
    <link rel="alternate" type="text/html" href="http://little418.com/2009/10/postgresql-shared-memory-error.html" />
    <id>tag:little418.com,2009://4.393</id>

    <published>2009-10-22T18:22:55Z</published>
    <updated>2009-10-22T18:40:11Z</updated>

    <summary>The PostgreSQL install instructions for OS X 10.5 include a command to run to change the OS shared memory settings. Sometimes these settings seem to revert, though. If they&#8217;ve reverted or were otherwise changed you may see this big ugly error message: FATAL: could not create shared memory segment: Invalid argument DETAIL: Failed system call was shmget(key=5432001, size=29360128, 03600). HINT: This error usually means that PostgreSQL&apos;s request for a shared memory segment exceeded your kernel&apos;s SHMMAX parameter. You can either reduce the request size or reconfigure the kernel with larger SHMMAX. To reduce the request size (currently 29360128 bytes), reduce...</summary>
    <author>
        <name>Mike Nicholson</name>
        <uri>http://little418.com/cms/mt-cp.cgi?__mode=view&amp;blog_id=4&amp;id=1</uri>
    </author>
    
        <category term="PostgreSQL" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="error" label="error" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="leopard" label="leopard" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="postgresql" label="postgresql" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="postgresql83" label="postgresql 8.3" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://little418.com/">
        <![CDATA[<p>The PostgreSQL install instructions for OS X 10.5 include a command to run to change the OS shared memory settings.  Sometimes these settings seem to revert, though.  If they&#8217;ve reverted or were otherwise changed you may see this big ugly error message:</p>

<pre>
FATAL:  could not create shared memory segment: Invalid argument
DETAIL:  Failed system call was shmget(key=5432001, size=29360128, 03600).
HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter.  You can either reduce the request size or reconfigure the kernel with larger SHMMAX.  To reduce the request size (currently 29360128 bytes), reduce PostgreSQL's shared_buffers parameter (currently 3072) and/or its max_connections parameter (currently 103).
     If the request size is already small, it's possible that it is less than your kernel's SHMMIN parameter, in which case raising the request size or reconfiguring SHMMIN is called for.
     The PostgreSQL documentation contains more information about shared memory configuration.
</pre>

<p>You could dig through the docs to find the right answer, but if you want a quick fix, here&#8217;s the command sequence to run in order to get your Postgres working again.</p>

<pre class="brush: bash">
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=33554432
</pre>
]]>
        

    </content>
</entry>

</feed>
