<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Marcin's Musings]]></title>
  <link href="http://junkheap.net/atom.xml" rel="self"/>
  <link href="http://junkheap.net/"/>
  <updated>2015-04-27T16:31:21+10:00</updated>
  <id>http://junkheap.net/</id>
  <author>
    <name><![CDATA[Marcin Szczepanski]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Mac OS X Java and /Library/Java/Extensions based woes]]></title>
    <link href="http://junkheap.net/blog/2014/04/06/mac-os-x-java-and-slash-library-slash-java-slash-extensions-woes/"/>
    <updated>2014-04-06T10:28:00+10:00</updated>
    <id>http://junkheap.net/blog/2014/04/06/mac-os-x-java-and-slash-library-slash-java-slash-extensions-woes</id>
    <content type="html"><![CDATA[<p>The kid was asleep, the wife had gone to bed early, so I did what any other sane person would do on a Saturday night &ndash; cracked open a beer and decided to brush up on my Java skills.</p>

<p>I&rsquo;ve never done Java full-time, and while I know the basics of the language &ndash; I even got a &ldquo;Sun Certified Java Programmer 1.4&rdquo; certification back in the day, just for kicks &ndash; I hadn&rsquo;t explored the newer features like Generics, Annotations and whatever else.  So with that in mind I fired up IDEA and started playing around.</p>

<p>I soon ran into some troubles though!</p>

<!-- More -->


<p>When I switched my project to point at the 1.7 JDK, IDEA was telling me:</p>

<p><code>java: System Java Compiler was not found in classpath</code></p>

<p>A Stackoverflow post suggested using the &ldquo;Eclipse&rdquo; compiler instead of &ldquo;Javac&rdquo;, and this seemed to do the trick, but I didn&rsquo;t know why so that wasn&rsquo;t ideal.  I checked my JAVA_HOME variable and all was good:</p>

<p><code>/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home</code></p>

<p>Running <code>javac -version</code> from the command line gave me the right version too:</p>

<p><code>javac 1.7.0_51</code></p>

<p>So no idea why Javac mode wasn&rsquo;t working, but I went back to playing around.</p>

<p>Soon after I wanted to check out Junit, so followed the instructions to add that to my project using Maven (now I have two problems!).  I&rsquo;m new to Maven as well, so I was relatively blindly just adding the JUnit dependency and using IDEA to sort the rest out for me and hoping for the best.</p>

<p>The problem now I was that I couldn&rsquo;t compile using maven. It was giving me an unsual error:</p>

<p><code>class file has wrong version 51.0, should be 49.0</code></p>

<p>&hellip; and this error was in reference to <code>java.util.List</code>!</p>

<p>I tried compiling from the command line using <code>javac</code> and got an error <code>illegal start of type</code> where I was using the Java 1.7 &ldquo;diamond&rdquo; notation:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">List</span><span class="o">&lt;</span><span class="n">String</span><span class="o">&gt;</span> <span class="n">strings</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ArrayList</span><span class="o">&lt;&gt;();</span>
</span></code></pre></td></tr></table></div></figure>


<p><code>javac -version</code> and my <code>JAVA_HOME</code> were definitely pointing to the 1.7 JDK so I was very confused.  After some additional research, I tried doing:</p>

<p><code>javac -source 1.7 -target 1.7 Foo.java</code></p>

<p>but kept getting errors like: <code>invalid source release: 1.7</code> &ndash; which were very perplexing!  <code>-target 1.6</code> didn&rsquo;t work either, but <code>-target 1.5</code> did, which was very strange.</p>

<p>A bunch of Google searches for these various errors I&rsquo;d been having yielded no useful answers for my situation &ndash; basically most of them boiled down to invalid <code>JAVA_HOME</code> settings, but mine were fine!</p>

<p>So to cut a long story short, and it&rsquo;s already been spoiled if you&rsquo;ve read the title, there&rsquo;s a <code>/Library/Java/Extensions</code> directory on Mac OS X that contains additional JAR files that are on the default classpath. These JARs can be installed by other applications, and can cause conflicts with other JARs you&rsquo;re expecting.  I removed all the JARs from this folder and suddenly everything worked fine!  IDEA could compile in Javac mode! Maven compiled! <code>javac</code> from the command line compiled!</p>

<p>I suspect the culprit was the <code>tools.jar</code> that had been placed there by something. This <code>tools.jar</code> was, I assume, from the Java 1.5 JDK. <code>tools.jar</code> appears to contain the classes for the Java Compiler, amongst other things. So despite the command line compiler being from 1.7, the actual classes that it was loading to do the compilation were from Java 1.5!</p>

<p>It took me two hours or so of futile searching, experimentation, reinstalling of JDKs, etc, before I finally remembered that I&rsquo;d been bitten by <code>/Library/Java/Extensions</code> before. Should&rsquo;ve thought of it sooner!</p>

<p>Anyway, this post probably won&rsquo;t be useful unless you&rsquo;re in this particular situation, but my hope is that by adding all those error messages in the post and the solution, somebody else who runs into the same issue will find my post instead of wasting time trying to work it out!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[SydJS Presentation: Koa]]></title>
    <link href="http://junkheap.net/blog/2014/03/30/sydjs-presentation-koa/"/>
    <updated>2014-03-30T13:10:00+11:00</updated>
    <id>http://junkheap.net/blog/2014/03/30/sydjs-presentation-koa</id>
    <content type="html"><![CDATA[<p>I tweeted about these slides but didn&rsquo;t actually post them to the blog. I presented at <a href="http://sydjs.com">SydJS</a> for the first time this month, about <a href="http://koajs.com">Koa</a> &ndash; a generator based web server framework for <a href="http://nodejs.org">Node.js</a>.</p>

<p>The slides by themselves probably aren&rsquo;t the most useful, and if you want to learn about Koa you might just be better off reading the docs!</p>

<p><a href="http://junkheap.net/presentations/koa/">Koa presentation slides</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[CFML CI Updates: multi-platform and TestBox support]]></title>
    <link href="http://junkheap.net/blog/2014/01/01/cfml-ci-updates-multi-platform-and-testbox-support/"/>
    <updated>2014-01-01T12:01:00+11:00</updated>
    <id>http://junkheap.net/blog/2014/01/01/cfml-ci-updates-multi-platform-and-testbox-support</id>
    <content type="html"><![CDATA[<p>Happy New Year!</p>

<p>I&rsquo;ve been putting in a bit of time during the holiday break, in between baby wrangling and Christmas duties, and have managed to add a bunch of useful features to the <a href="https://github.com/marcins/cfml-ci">CFML CI</a> template.</p>

<!-- More -->


<h2>Multi-platform support</h2>

<p>The biggest change is that the scripts now support running <a href="http://www.adobe.com/au/products/coldfusion-family.html">Adobe Coldfusion</a> 9.0.2 and 10. In addition, with the changes made to support multiple platforms, Railo 4.0 and the new 4.2 beta have been added to the default list of platforms &ndash; although for Railo this was trivial, just point at different archives.</p>

<p>ACF support was a bit trickier, as ACF requires an &ldquo;installation&rdquo; before it&rsquo;ll run. I have done this install step, gone through the initial setup screens, applied patches, and packaged up the result. I am hosting these pre-installed re-packaged version on an S3 bucket, and downloads from Travis CI are pretty darn fast (they might be on AWS infrastructure as well). The other part of the puzzle was doing a find and replace from the original installed path to wherever it had been installed by the CI scripts.  Oh yeah, and just for good measure the startup script was tweaked to remove the requirement to run as root!</p>

<p>The good thing was the work to get ACF10 working translated pretty easily to ACF9 &ndash; with minor differences for paths and startup procedure for the server. Future versions of ACF should also be able to be supported, although supporting the future versions may be easier from what I&rsquo;ve seen in the pre-release program.</p>

<p>Adobe ColdFusion and multi-platform support is on the master branch of the CFML CI project:</p>

<p><a href="https://github.com/marcins/cfml-ci">https://github.com/marcins/cfml-ci</a></p>

<p>These changes have also been backported and merged into FW/1 &ndash; it&rsquo;s test suite is now running against the main supported versions:</p>

<p><a href="https://travis-ci.org/framework-one/fw1">https://travis-ci.org/framework-one/fw1</a></p>

<h2>TestBox</h2>

<p>Initial experimental support for <a href="http://wiki.coldbox.org/wiki/TestBox.cfm">TestBox</a> has also now been added, however I am waiting for the 1.0.1 release before it ends up on master as currently the build doesn&rsquo;t fail if there are test errors, there is a <a href="https://ortussolutions.atlassian.net/browse/TESTBOX-57">fix coming that allows for writing out a properties file that can be used to determine whether the tests failed</a>. You can see the test matrix for this branch on Travis CI:</p>

<p><a href="https://travis-ci.org/marcins/cfml-ci">https://travis-ci.org/marcins/cfml-ci</a></p>

<p>(Although technically those TestBox tests should be failing as there&rsquo;s an intentional failure in there)</p>

<h2>TODO</h2>

<p>The only thing remaining for this iteration is to update the documentation to cover multiple test frameworks, and update the Jenkins documentation to describe how to set up a multi-config / &ldquo;matrix&rdquo; project to allow for testing the various platforms from a single project.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Continous Integration for CFML projects]]></title>
    <link href="http://junkheap.net/blog/2013/12/10/continous-integration-for-cfml-projects/"/>
    <updated>2013-12-10T09:00:00+11:00</updated>
    <id>http://junkheap.net/blog/2013/12/10/continous-integration-for-cfml-projects</id>
    <content type="html"><![CDATA[<p>I recently took on the task of trying to make the <a href="https://github.com/framework-one/fw1">FW/1</a> test suite run on <a href="http://travis-ci.org/">Travis CI</a>. With a bit of experimentation and hacking it <a href="https://travis-ci.org/framework-one/fw1">now works</a>! This might be the first open source CFML project with Continous Integration tests, and as a resource for the community I thought it would be good to release the relevant parts as a template of sorts.  Presenting the CFML CI project:</p>

<p><a href="https://github.com/marcins/cfml-ci">https://github.com/marcins/cfml-ci</a></p>

<p>The README contains instructions for integrating with your CFML project.</p>

<!-- More -->


<h2>What&rsquo;s Continous Integration?</h2>

<p>Stepping back a bit, you may be wondering what Continous Integration (CI) actually is. Roughly speaking, it&rsquo;s the idea that your tests / build process is run continously, automatically, whenever a change is made to the repository &ndash; giving you immediate feedback if the changes are going to break the build.</p>

<h3>Travis CI</h3>

<p>Travis CI is a CI Software as a Service (SaaS) platform, originally started for the open source community. It provides a number of different language environments for running tests in &ndash; including Java. Travis CI is free to use for open source projects (but your builds are public), and integrates closely with Github. What this means is that when a FW/1 Pull Request is opened now, it will automatically have the tests run by Travis, and the results will be shown in Github &ndash; giving you plenty of warning before you merge a &ldquo;broken build&rdquo;.</p>

<p>It also provides you a nice image you can stick in your Github README (or anywhere else) with the current status of the build, for example this is the live status of the CFML CI project:</p>

<p><a href="https://travis-ci.org/marcins/cfml-ci"><img src="https://travis-ci.org/marcins/cfml-ci.png?branch=master" alt="Build Status" /></a></p>

<h2>The process</h2>

<p>There were a few modifications required to a few components in order to get everything working smoothly:</p>

<ul>
<li>A patch was required to MXUnit as on a default Railo install it tries to output some null properties in the XML output
which was causing a failure.</li>
<li>Modifications were required to the Ant Runner CFC as some of the FW/1 tests set the status code to 500 (error) which flowed through to the test output causing a failure</li>
<li>A custom output Ant task was written that takes the output from the test runner and displays it on the Ant console, otherwise on Travis CI if the tests failed you would not get any feedback as to which test had failed in the console.</li>
</ul>


<p>The scripts currently only work with Railo, because Adobe does not provide an equivalent to Railo Express which makes a simple download / extract / run process impossible on ACF. Need to experiment with the idea of installing and configuring ACF locally and creating a &ldquo;ready to run&rdquo; package.</p>

<h2>The future</h2>

<p>There&rsquo;s still a bit of work I&rsquo;d like to put into this, some of it a bit simpler than others:</p>

<ul>
<li>support for multiple versions of Railo, and Adobe ColdFusion</li>
<li>create a new version of the MXUnit Ant task that integrates the console output as well as fixing some other minor issues</li>
<li>there&rsquo;s already brief guides for running on Travis and Jenkins, but provide documentation for integrating with other CI servers (Bamboo, ??)</li>
<li>make it work on Windows (it&rsquo;s very unix dependent right now &ndash; would probably involve rewriting the helper script in something more portable) &ndash; although this isn&rsquo;t a high priority for me</li>
</ul>


<p>As always with open source, feel free to contribute your code or comments via <a href="https://github.com/marcins/cfml-ci">the Github repo</a>!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Building REST APIs with FW/1 2.2]]></title>
    <link href="http://junkheap.net/blog/2013/11/15/building-rest-apis-with-fw-slash-1-2-dot-2/"/>
    <updated>2013-11-15T11:11:00+11:00</updated>
    <id>http://junkheap.net/blog/2013/11/15/building-rest-apis-with-fw-slash-1-2-dot-2</id>
    <content type="html"><![CDATA[<p><a href="github.com/framework-one/fw1">FW/1</a>, the awesome and lightweight CFML application framework, has <a href="http://corfield.org/blog/post.cfm/fw-1-releases-and-roadmap">version 2.2 just around the corner</a> (in RC as I write this, may be out by the time you read it). Version 2.2 is mostly a bugfix release, however there are two new features that were of particular interest to me: resource routes, and renderData.</p>

<!-- More -->


<h2>Resource Routes</h2>

<p>Resource Routes were contributed by <a href="https://github.com/jcberquist">John Berquist</a> for FW/1 2.2. This is actually something I had also proposed a long time ago, I mentioned it in <a href="https://github.com/marcins/cfobjective2012">my CF.Objective(ANZ) presentation</a> this time last year, but never got around to implementing. So thanks, John!</p>

<p>Resource Routes allow you to simplify adding REST style routes to your route table. In my presentation I showed a set of routes required to implement a RESTful API for a resource, basically Resource Routes allows you to replace those with a single entry using the magic $RESOURCES route.</p>

<h2>renderData</h2>

<p>The other cool feature is a renderData function that simplifies the process of returning non-HTML content from a FW/1 controller. Currently returning data in JSON, XML and text is supported. There have been a couple of ways of doing this in the past, using an <code>onMissingView</code> function in Application.cfc or using a special view that would set the content type. <code>renderData</code> makes this a one-liner without any additonal requirements.</p>

<h2>Building a REST API</h2>

<p>By combining renderData and Resource Routes it makes it easier than ever to build a REST style API with FW/1. I&rsquo;ve created a simple example project that implements, of course, a TODO list application.  It&rsquo;s not necessarily best practice, but I think it shows how easy it is to provide an API and cosume it. For a &ldquo;real&rdquo; app for the front-end code I&rsquo;d probably use something like Backbone or AngularJS instead, but in the interests of keeping the barrier to understanding the code low I&rsquo;ve kept it as plain JS (with jQuery).</p>

<p><a href="https://github.com/marcins/fw1-rest-example">https://github.com/marcins/fw1-rest-example</a></p>

<h3>RESTful routes</h3>

<p>This is grossly simplifying the topic, but essentially the idea of REST is that URLs point to particular resources in your data model, and the HTTP method determines what to do with that resoruce (eg. GET to get data, POST to create a new object, PUT to update, DELETE to delete).  There is also the concept of child objects, so for example in the TODO app a list item is referenced through it&rsquo;s list:</p>

<p><code>/lists/LISTID/items/ITEMID</code></p>

<p>The routes in Application.cfc to support this are quite simple:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='cfs'><span class='line'><span class="nv">routes</span> <span class="o">=</span> <span class="p">[{</span>
</span><span class='line'>  <span class="s2">&quot;$RESOURCES&quot;</span> <span class="o">=</span> <span class="p">{</span> <span class="nv">resources</span> <span class="o">=</span> <span class="s2">&quot;lists&quot;</span><span class="p">,</span> <span class="nv">nested</span> <span class="o">=</span> <span class="s2">&quot;items&quot;</span> <span class="p">}</span>
</span><span class='line'><span class="p">}]</span>
</span></code></pre></td></tr></table></div></figure>


<p>This requires two controllers, lists and items, and with the default settings will create routes for the following actions in the controller:</p>

<ul>
<li><code>default</code> (GET without id)</li>
<li><code>show</code> (GET with id)</li>
<li><code>create</code> (POST)</li>
<li><code>update</code> (PUT)</li>
<li><code>destroy</code> (DELETE)</li>
</ul>


<p>For these methods rc will have available, where relevant, <code>lists_id</code> and <code>items_id</code> (in the items controller).</p>

<p>You can configure which methods are available, and a whole bunch of other stuff, in the route as well. The FW/1 manual goes into detail as to what configuration options are available.</p>

<h4>Error handling</h4>

<p>The easiest way to &ldquo;throw&rdquo; an error back to the Javascript is to use a HTTP response code. <code>renderData</code> allows this with an optional status code parameter, for example:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='cfs'><span class='line'><span class="k">var</span> <span class="nv">list</span> <span class="o">=</span> <span class="nf">getObjectStore</span><span class="p">().</span><span class="nf">getObjectById</span><span class="p">(</span><span class="nv">rc.lists_id</span><span class="p">);</span>
</span><span class='line'><span class="k">if</span> <span class="p">(</span><span class="nf">isNull</span><span class="p">(</span><span class="nv">list</span><span class="p">))</span> <span class="p">{</span>
</span><span class='line'>  <span class="nv">return</span> <span class="nf">fw.renderData</span><span class="p">(</span><span class="s2">&quot;json&quot;</span><span class="p">,</span> <span class="p">{</span><span class="nv">error</span> <span class="o">=</span> <span class="s2">&quot;List not found&quot;</span><span class="p">},</span> <span class="m">404</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Note that the example JS code doesn&rsquo;t really handle these errors, mainly because I was lacking spare time and wanted to get this post out.</p>

<h3>Accessing through Javascript</h3>

<p>If you&rsquo;re using jQuery there&rsquo;s not really anything special you have to do here, if your actions are returning JSON using <code>renderData("json", ...)</code> then jQuery&rsquo;s &ldquo;intelligent Guess&rdquo; for datatype will know it&rsquo;s JSON and de-serialize it.  The only trickiness is that there are only AJAX helper methods (eg. <code>$.get</code>) for GET and POST, not PUT and DELETE, so if you want to use those you&rsquo;ll need to use the slightly more verbose <code>$.ajax</code> instead:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">(</span><span class="nx">Example</span><span class="p">.</span><span class="nx">baseUrl</span> <span class="o">+</span> <span class="s1">&#39;/lists/&#39;</span> <span class="o">+</span> <span class="nx">selectedList</span><span class="p">.</span><span class="nx">id</span> <span class="o">+</span> <span class="s1">&#39;/items/&#39;</span> <span class="o">+</span> <span class="nx">itemId</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">type</span><span class="o">:</span> <span class="s2">&quot;PUT&quot;</span><span class="p">,</span>
</span><span class='line'>  <span class="nx">data</span><span class="o">:</span> <span class="p">{</span><span class="nx">complete</span><span class="o">:</span> <span class="o">!</span><span class="nx">selectedList</span><span class="p">.</span><span class="nx">items</span><span class="p">[</span><span class="nx">itemId</span><span class="p">].</span><span class="nx">complete</span><span class="p">}</span>
</span><span class='line'><span class="p">}).</span><span class="nx">done</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">selectedList</span><span class="p">.</span><span class="nx">items</span><span class="p">[</span><span class="nx">itemId</span><span class="p">]</span> <span class="o">=</span> <span class="nx">data</span><span class="p">;</span>
</span><span class='line'>  <span class="nx">renderList</span><span class="p">();</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>I think it&rsquo;s only IE6 and lower that doesn&rsquo;t support anything but GET/POST from an XMLHttpRequest, so you should be OK in most cases.</p>

<h3>Other points of interest</h3>

<ul>
<li><p>the Javascript isn&rsquo;t super efficient and will re-render the list of lists and list items when anything changes to keep the data in sync.</p></li>
<li><p>there is no security or authentication &ndash; again, keeping it simple, but don&rsquo;t do this in production :)</p></li>
<li><p>the sample project includes a basic persistent object store to avoid the need for a database. This is definitely NOT for production use, but seemed like a useful thing to have for demos and works like a mini-Couch or MongoDB sort of thing.</p></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[CFCamp 2013 Presentation: Introduction to CoffeeScript]]></title>
    <link href="http://junkheap.net/blog/2013/10/22/cfcamp-2013-presentation-introduction-to-coffeescript/"/>
    <updated>2013-10-22T07:49:00+11:00</updated>
    <id>http://junkheap.net/blog/2013/10/22/cfcamp-2013-presentation-introduction-to-coffeescript</id>
    <content type="html"><![CDATA[<p>Last week I had the opportunity to speak at the <a href="http://cfcamp.org/">CFCamp 2013</a> conference in Munich. Rather than a CFML topic I proposed a talk on <a href="http://coffeescript.org/">CoffeeScript</a>, as I had been doing a few CoffeeScript projects at work and found the language interesting. Although funnily enough in between proposing the talk and actually giving it I have actually gone off the idea of using CoffeeScript heavily in production.</p>

<p>After attending <a href="http://2013.jsconf.eu/">JSConf EU</a> in September I just feel that there&rsquo;s too much new stuff coming in JavaScript that clashes with what&rsquo;s already in CoffeeScript that it might be better to stick to pure JS.  Of course CoffeeScript generated JS won&rsquo;t stop working, but it just sometimes feels like the little bit of nicer syntax isn&rsquo;t worth the overheads to the process.</p>

<p>So my presentation was very wary in trying to advocate / evangelise CoffeeScript, it was more a case of &ldquo;Hey, this is what CoffeeScript is and what it looks like. You might want to give it a go, but really be aware of the downsides&rdquo;!</p>

<p>I&rsquo;ve put the <a href="http://junkheap.net/presentations/coffeescript-intro/">Introduction to CoffeeScript presentation online</a> &ndash; there&rsquo;s a live CoffeeScript code editor and compiler built into the slides, which was a bit of fun to write.</p>

<p>As for the conference itself, it was a lot of fun! Michael Hnat and the rest of the organising team did a great job, and the venue was excellent. Also loved the drinks on every table in the presentation rooms, and the copious amounts of pretzels for snacks.  I met some interesting people, and saw some interesting presentations. It was only good timing with my family holiday that I could make it there this year, which is a shame as I&rsquo;d happily come back next year if it wasn&rsquo;t half way around the world.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Implementing Google Authenticator support in ColdFusion]]></title>
    <link href="http://junkheap.net/blog/2013/05/30/implementing-google-authenticator-support-in-coldfusion/"/>
    <updated>2013-05-30T19:48:00+10:00</updated>
    <id>http://junkheap.net/blog/2013/05/30/implementing-google-authenticator-support-in-coldfusion</id>
    <content type="html"><![CDATA[<p>I use the <a href="https://support.google.com/accounts/answer/1066447?hl=en">Google Authenticator</a> app as an additional security measure for my Google account. When Dropbox added support I realised it wasn&rsquo;t just a Google thing. I finally thought I&rsquo;d look at what it takes to implement a Google Authenticator &ldquo;compliant&rdquo; service.  Turns out it&rsquo;s not too hard, and it&rsquo;s all standards based.</p>

<p>For the impatient, here&rsquo;s the <a href="https://github.com/marcins/cf-google-authenticator">CF Google Authenticator</a> Github repo.</p>

<p>So for the details: These 2 standards are involved in the Google Authenticator implementation:</p>

<ul>
<li><a href="http://tools.ietf.org/html/rfc6238">RFC-6238</a> <em>TOTP: Time-Based One-Time Password Algorithm</em></li>
<li><a href="http://tools.ietf.org/html/rfc4226">RFC-4226</a> <em>HOTP: An HMAC-Based One-Time Password Algorithm</em></li>
</ul>


<p>The first is actually a specific implementation of the second, and what Google Authenticator tokens are based on.</p>

<p>HOTP is conceptually simple &ndash; you take the HMAC-SHA-1 of a shared secret key, and a counter. You then do some bit twiddling with the resulting 160-bit (20 byte) hash to get it down to a 4-byte number, from which you then extract a 6-digit number which is your token.</p>

<p>TOTP is a particular implementation of HOTP, where the counter is based on the number of seconds since the UNIX Epoch. Specifically it&rsquo;s how many X second periods have there been since the epoch, where X is 30 seconds in Google&rsquo;s case. This is why the number changes every 30 seconds.</p>

<p>So anyway, the actual derivation of the current token value from the secret is only a few lines of code, but there was some additional complexity to implementing this in ColdFusion.</p>

<!-- More -->


<h2>Base32</h2>

<p>The Secret Key that is required for the Google Authenticator app is encoded in Base32. This is a less common relation of Base64, but it&rsquo;s a lot easier to type in manually as it only includes uppercase letters and numbers. Base32 is defined in <a href="http://tools.ietf.org/html/rfc4648">RFC-4648</a> <em>The Base16, Base32, and Base64 Data Encodings</em>.</p>

<p>There is a Java based Base32 implementation in <a href="http://commons.apache.org/proper/commons-codec/">Apache Commons Codec</a>, however it was only added in v1.5.  Adobe ColdFusion 10 bundles Apache Commons Codec, but unforutnately it&rsquo;s only v1.3.  So if I wanted to use the library I&rsquo;d have to include it and use a JavaLoader. In fact my first implementation did this, but I deicded to go for the extra challenge of implementing Base32 myself.</p>

<h2>Java Crypto</h2>

<p>This code also makes heavy use of <a href="http://docs.oracle.com/javase/6/docs/api/javax/crypto/package-summary.html">Java Crypto</a>, and so needs to put stuff into byte arrays and other native Java types.  In retrospect the whole project might&rsquo;ve been better implemented as a Java library that could just be loaded, in fact there probably already is one. However I treated this as more of a learning exercise, and challenged myself to do it entirely in native CF. It&rsquo;s definitely easier to implement being a single CFC without any dependencies on external JARs.</p>

<h2>QR Codes</h2>

<p>The Google Authenticator app allows you to add your account by scanning a QR Code. I wanted to do this for my Proof of Concept / Demo, and it turns out there&rsquo;s a neat little Javascript library for doing it called (funnily enough) <a href="http://davidshimjs.github.io/qrcodejs/">qrcode.js</a>. It&rsquo;s got wide browser support by using canvas where available, and HTML tables where it&rsquo;s not.</p>

<h2>ColdFusion quirks</h2>

<p>ColdFusion isn&rsquo;t really designed for bit twiddling &ndash; even in cfscript there aren&rsquo;t the usual bitwise operators and shifts, you have to use functions. There&rsquo;s also no hex constants, so you need to convert stuff to decimal. Still, I guess CF isn&rsquo;t really a general purpose language but web specific, so the demand for these types of operations is probably fairly low.</p>

<p>An example, it means you tend to be a bit more verbose:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='cfs'><span class='line'><span class="nv">byte</span> <span class="o">=</span> <span class="nf">bitSHLN</span><span class="p">(</span><span class="nf">bitAnd</span><span class="p">(</span><span class="nv">this.DECODE_TABLE</span><span class="p">[</span><span class="nv">encodedBytes</span><span class="p">[</span><span class="nv">i</span> <span class="o">+</span> <span class="m">4</span><span class="p">]],</span> <span class="m">1</span><span class="p">),</span> <span class="m">7</span><span class="p">);</span>
</span><span class='line'><span class="nv">byte2</span> <span class="o">=</span> <span class="nf">bitSHLN</span><span class="p">(</span><span class="nv">this.DECODE_TABLE</span><span class="p">[</span><span class="nv">encodedBytes</span><span class="p">[</span><span class="nv">i</span> <span class="o">+</span> <span class="m">5</span><span class="p">]],</span> <span class="m">2</span><span class="p">);</span>
</span><span class='line'><span class="nv">byte3</span> <span class="o">=</span> <span class="nf">bitSHRN</span><span class="p">(</span><span class="nv">this.DECODE_TABLE</span><span class="p">[</span><span class="nv">encodedBytes</span><span class="p">[</span><span class="nv">i</span> <span class="o">+</span> <span class="m">6</span><span class="p">]],</span> <span class="m">3</span><span class="p">);</span>
</span><span class='line'><span class="nf">decodedBytes.write</span><span class="p">(</span><span class="nf">bitOr</span><span class="p">(</span><span class="nf">bitOr</span><span class="p">(</span><span class="nv">byte</span><span class="p">,</span> <span class="nv">byte2</span><span class="p">),</span> <span class="nv">byte3</span><span class="p">));</span>
</span></code></pre></td></tr></table></div></figure>


<p>instead of being able to do the more typical:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">decodedBytes</span><span class="o">.</span><span class="na">write</span><span class="o">(</span>
</span><span class='line'>    <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">DECODE_TABLE</span><span class="o">[</span><span class="n">encodedBytes</span><span class="o">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">4</span><span class="o">]]</span> <span class="o">&amp;</span> <span class="mh">0x1</span><span class="o">)</span> <span class="o">&lt;&lt;</span> <span class="mi">7</span> <span class="o">|</span>
</span><span class='line'>    <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">DECODE_TABLE</span><span class="o">[</span><span class="n">encodedBytes</span><span class="o">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">5</span><span class="o">]]</span> <span class="o">&lt;&lt;</span> <span class="mi">2</span><span class="o">)</span> <span class="o">|</span>
</span><span class='line'>    <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">DECODE_TABLE</span><span class="o">[</span><span class="n">encodedBytes</span><span class="o">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">6</span><span class="o">]]</span> <span class="o">&gt;&gt;</span> <span class="mi">3</span><span class="o">));</span>
</span></code></pre></td></tr></table></div></figure>


<p>There was also a fair bit of casting, and using Java classes in order to get things into (mainly) native <code>byte[]</code> arrays.</p>

<p>As I said though, as a learning exercise it was definitely interesting to explore some of the lesser used parts of CF, and refresh my bitwise operator math. There was even a piece of paper and pen involved in working some of it out!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Setting up monit on Elastic Beanstalk]]></title>
    <link href="http://junkheap.net/blog/2013/05/21/setting-up-monit-on-elastic-beanstalk/"/>
    <updated>2013-05-21T20:40:00+10:00</updated>
    <id>http://junkheap.net/blog/2013/05/21/setting-up-monit-on-elastic-beanstalk</id>
    <content type="html"><![CDATA[<p>Continuing on with <a href="http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/">yesterday&rsquo;s theme</a> of posts about <a href="http://aws.amazon.com/elasticbeanstalk/">Amazon Elastic Beanstalk</a> bits and pieces I&rsquo;ve discovered I&rsquo;m going to talk about how to setup the simple monitoring tool <a href="http://mmonit.com/monit/">Monit</a> on your EC2 instance(s). In my case I&rsquo;m using Monit to monitor the delayed_job service I mentioned in my last post, and restart it if it dies.</p>

<!-- More -->


<p>Monit isn&rsquo;t installed on the instance by default so we&rsquo;ll need to install the package.  After that we just need to configure it to monitor delayed_job and make sure it&rsquo;s running.  This is actually pretty simple with just the standard <code>.config</code> files.</p>

<p>Here is my <code>.ebextensions/90monit.config</code>:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
</pre></td><td class='code'><pre><code class='yaml'><span class='line'><span class="l-Scalar-Plain">packages</span><span class="p-Indicator">:</span>
</span><span class='line'>  <span class="l-Scalar-Plain">yum</span><span class="p-Indicator">:</span>
</span><span class='line'>    <span class="l-Scalar-Plain">monit</span><span class="p-Indicator">:</span> <span class="p-Indicator">[]</span>
</span><span class='line'><span class="l-Scalar-Plain">files</span><span class="p-Indicator">:</span>
</span><span class='line'>  <span class="s">&quot;/etc/monit.d/delayed_job&quot;</span><span class="p-Indicator">:</span>
</span><span class='line'>    <span class="l-Scalar-Plain">mode</span><span class="p-Indicator">:</span> <span class="s">&quot;000644&quot;</span>
</span><span class='line'>    <span class="l-Scalar-Plain">owner</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">root</span>
</span><span class='line'>    <span class="l-Scalar-Plain">group</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">root</span>
</span><span class='line'>    <span class="l-Scalar-Plain">content</span><span class="p-Indicator">:</span> <span class="p-Indicator">|</span>
</span><span class='line'>      <span class="no">set mailserver smtp.gmail.com port 587</span>
</span><span class='line'>      <span class="no">username &quot;system@XXXXXX&quot; password &quot;XXXXXX&quot; using tlsv1</span>
</span><span class='line'>      <span class="no">with timeout 30 seconds</span>
</span><span class='line'>
</span><span class='line'>      <span class="no">set httpd port 2812 and</span>
</span><span class='line'>        <span class="no">use address localhost  # only accept connection from localhost</span>
</span><span class='line'>        <span class="no">allow localhost        # allow localhost to connect to the server and</span>
</span><span class='line'>
</span><span class='line'>      <span class="no">check process delayed_job</span>
</span><span class='line'>        <span class="no">with pidfile /var/app/support/pids/delayed_job.pid every 2 cycles</span>
</span><span class='line'>        <span class="no">start program = &quot;/usr/bin/env BUNDLE_WITHOUT=test:development RAILS_ENV=production /var/app/current/script/delayed_job --pid-dir=/var/app/support/pids start&quot; as uid webapp and gid webapp</span>
</span><span class='line'>        <span class="no">stop program = &quot;/usr/bin/env BUNDLE_WITHOUT=test:development RAILS_ENV=production /var/app/current/script/delayed_job --pid-dir=/var/app/support/pids stop&quot; as uid webapp and gid webapp</span>
</span><span class='line'>
</span><span class='line'>      <span class="no">alert alerts@XXXXX with mail-format {</span>
</span><span class='line'>        <span class="no">from: system@XXXXXX</span>
</span><span class='line'>        <span class="no">reply-to: alerts@XXXXXX</span>
</span><span class='line'>        <span class="no">subject: XXXXXX $SERVICE $EVENT at $DATE</span>
</span><span class='line'>      <span class="no">}</span>
</span><span class='line'><span class="l-Scalar-Plain">commands</span><span class="p-Indicator">:</span>
</span><span class='line'>  <span class="l-Scalar-Plain">remove_bak</span><span class="p-Indicator">:</span>
</span><span class='line'>    <span class="l-Scalar-Plain">command</span><span class="p-Indicator">:</span> <span class="s">&quot;rm</span><span class="nv"> </span><span class="s">/etc/monit.d/delayed_job.bak&quot;</span>
</span><span class='line'>    <span class="l-Scalar-Plain">ignoreErrors</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
</span><span class='line'><span class="l-Scalar-Plain">service</span><span class="p-Indicator">:</span>
</span><span class='line'>  <span class="l-Scalar-Plain">sysvinit</span><span class="p-Indicator">:</span>
</span><span class='line'>    <span class="l-Scalar-Plain">monit</span><span class="p-Indicator">:</span>
</span><span class='line'>      <span class="l-Scalar-Plain">ensureRunning</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
</span><span class='line'>      <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
</span></code></pre></td></tr></table></div></figure>


<p>Basically what we&rsquo;re doing is:</p>

<ul>
<li>Using yum to install the monit package</li>
<li>deploying a config file for monitoring delayed_job into <code>/etc/monit.d</code> (more on this later)</li>
<li>When you deploy the config script, if it already exists Elastic Beanstalk will create a backup. We need to delete this file if it exists because monit will load all files in <code>/etc/monit.d</code> regardless of extension</li>
<li>ensure the monit service is enabled and running</li>
</ul>


<p>So the config file for monit is where the interesting stuff is. We&rsquo;re configuring stuff in here that we&rsquo;d probably normally put in core monit config, but in the interests of keeping the deployment script simple we do it all from one script.</p>

<p>What we&rsquo;re doing with this config is:</p>

<ul>
<li>Setup our mailserver to use GMail SMTP to send the emails &ndash; I&rsquo;m using a specific service account.</li>
<li>Setup the monit httpd service so we can run <code>monit status</code> on the instance when debugging</li>
<li>Setup the config for monitoring <code>delayed_job</code> &ndash; more on this below.</li>
<li>Last of all we setup an alert to be sent to our alerts email when there&rsquo;s a status change for delayed_job</li>
</ul>


<p>So the hardest part was getting the commands right. There were a few pages I found that gave me most of the answer, however not fully &ndash; for me it was failing for ages because I didn&rsquo;t have the <code>BUNDLE_WITHOUT</code> variable set when trying to run the script and I have some test specific dependencies.</p>

<p>The part that makes this more difficult is because monit runs your commands with an extremely cut down shell &ndash; all you get is basically the path, with no other environment variables.  So what we&rsquo;re doing is running our command through <code>/usr/bin/env</code> to setup the environment (although I&rsquo;m not sure that&rsquo;s actually doing anything), and explicitly passing the RAILS_ENV. We also need to specify the user to run the commands as, otherwise the delayed_job service will start up as root &ndash; which is not good.</p>

<p>I could probably improve this script by refactoring the commands to use the Elastic Beanstalk environment like <code>$EB_CONFIG_APP_CURRENT</code> rather than hardcoding <code>/var/app/current</code>, but it&rsquo;s working for now so I&rsquo;ve left it alone &ndash; and as I said above, monit runs commands in a very cut down environment so getting those variables in might not be easy.</p>

<p>Anyway, that&rsquo;s another piece of my Elastic Beanstalk puzzle.  Pretty simple in hindsight, but probably took a good hour or two of fiddling around on the instance, trying various approaches, reading documentation and so on to finally get it all working reliably and repeatably.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Elastic Beanstalk post-deployment scripts]]></title>
    <link href="http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/"/>
    <updated>2013-05-20T21:44:00+10:00</updated>
    <id>http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts</id>
    <content type="html"><![CDATA[<p>Some of this is extracted from an <a href="http://stackoverflow.com/questions/14401204/how-to-automatically-restart-delayed-job-when-deploying-a-rails-project-on-amazo/16275837#16275837">answer I posted to a Stack Overflow question</a>.</p>

<p>Recently I&rsquo;ve been helping out a friend with a website and we are deploying it to AWS via their Elastic Beanstalk service. I&rsquo;ve learned a few quirks of the platform in my, albeit brief, time working with it.  One of these is that there&rsquo;s no official way to run a &ldquo;post deploy&rdquo; script.  You can run <a href="(http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands">&ldquo;Container Commands&rdquo;</a>), which are executed in your application directory BEFORE it is deployed (ie. made live), but no way to run a script AFTER your application is deployed (ie. when your application is in <code>/var/app/current</code> and the web server has been restarted).</p>

<p>Why would you need to do this?</p>

<!-- more -->


<p>Well, in my case I am using <a href="https://github.com/collectiveidea/delayed_job">delayed_job</a> as a worker for this Ruby on Rails app, and need to restart delayed_job when the application is deployed.  I can&rsquo;t do this before the app is live, because at that point the app is still in <code>/var/app/ondeck</code> and this seemed to cause problems. Also at this point the deploy could still technically fail, and you&rsquo;d be left with the &ldquo;old&rdquo; version of the application running, but with the &ldquo;new&rdquo; delayed_job instance. Not good.</p>

<p>So when I was looking at the <code>eb-tools.log</code> on the EC2 instance I found it was searching for scripts to run in a <code>/opt/elasticbeanstalk/hooks/appdeploy/post</code> directory after restarting the web server. Turns out if you drop shell scripts into this directory they will be executed post deployment, just like you want! However this directory does not exist by default, as Amazon does not use any post-deploy scripts, so we also need to make sure this directory is created.</p>

<p>You can use the regular config YAML files that go in your <code>.ebextensions</code> folder in order to deploy a shell script that will be run after the deployment is complete.</p>

<p>This is my <code>99delayed_job.config</code>:</p>

<figure class='code'><figcaption><span>99delayed_job.config</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class='yaml'><span class='line'><span class="l-Scalar-Plain">commands</span><span class="p-Indicator">:</span>
</span><span class='line'>  <span class="l-Scalar-Plain">create_post_dir</span><span class="p-Indicator">:</span>
</span><span class='line'>    <span class="l-Scalar-Plain">command</span><span class="p-Indicator">:</span> <span class="s">&quot;mkdir</span><span class="nv"> </span><span class="s">/opt/elasticbeanstalk/hooks/appdeploy/post&quot;</span>
</span><span class='line'>    <span class="l-Scalar-Plain">ignoreErrors</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
</span><span class='line'><span class="l-Scalar-Plain">files</span><span class="p-Indicator">:</span>
</span><span class='line'>  <span class="s">&quot;/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh&quot;</span><span class="p-Indicator">:</span>
</span><span class='line'>    <span class="l-Scalar-Plain">mode</span><span class="p-Indicator">:</span> <span class="s">&quot;000755&quot;</span>
</span><span class='line'>    <span class="l-Scalar-Plain">owner</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">root</span>
</span><span class='line'>    <span class="l-Scalar-Plain">group</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">root</span>
</span><span class='line'>    <span class="l-Scalar-Plain">content</span><span class="p-Indicator">:</span> <span class="p-Indicator">|</span>
</span><span class='line'>      <span class="no">#!/usr/bin/env bash</span>
</span><span class='line'>      <span class="no">. /opt/elasticbeanstalk/support/envvars</span>
</span><span class='line'>      <span class="no">cd $EB_CONFIG_APP_CURRENT</span>
</span><span class='line'>      <span class="no">su -c &quot;RAILS_ENV=production script/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart&quot; $EB_CONFIG_APP_USER</span>
</span></code></pre></td></tr></table></div></figure>


<p>What this config does is:</p>

<ul>
<li>create the &ldquo;post&rdquo; directory if it doesn&rsquo;t already exist (it won&rsquo;t by default) &ndash; ignore any errors (such as if the directory already existed)</li>
<li>deploy the shell script with the appropriate permissions into the right directory</li>
</ul>


<p>What the shell script does is:</p>

<ul>
<li>setup the environment variables (I borrowed this line from the other shell scripts in <code>/opt/elasticbeanstalk</code>)</li>
<li>change to the &ldquo;current&rdquo; directory &ndash; this will probably be <code>/var/app/current</code> but we don&rsquo;t make any assumptions</li>
<li>restart delayed_job as the app user (usually <code>webapp</code>), using a shared pids directory to make sure it kills the old version first</li>
</ul>


<p>So after commiting the config file and doing a <code>git aws.push</code> you should see something like this in your <code>/var/log/eb-tools.log</code>:</p>

<pre><code>2013-05-16 01:20:53,759 [INFO] (6467 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing directory: /opt/elasticbeanstalk/hooks/appdeploy/post/
2013-05-16 01:20:53,760 [INFO] (6467 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh
2013-05-16 01:21:02,619 [INFO] (6467 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: delayed_job: trying to stop process with pid 6139...
delayed_job: process with pid 6139 successfully stopped.
2013-05-16 01:21:02,620 [INFO] (6467 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script succeeded.
</code></pre>

<p>As I said, putting stuff in this &ldquo;post&rdquo; directory is undocumented &ndash; but hopefully at some point Amazon add actual support to the <code>.config</code> scripts to run commands post-deploy, in that case you could just move the restart comamnd itself to the officially supported approach.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Hello World!]]></title>
    <link href="http://junkheap.net/blog/2013/05/20/hello-world/"/>
    <updated>2013-05-20T20:32:00+10:00</updated>
    <id>http://junkheap.net/blog/2013/05/20/hello-world</id>
    <content type="html"><![CDATA[<p>Hello! Let&rsquo;s try this blogging thing again. Decided to give <a href="http://octopress.org/">Octopress</a> a whirl. Gone are the days of writing your own blogging engine every time you want to start writing a blog again (well, maybe).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using CIDetector with video from an AVCaptureSession]]></title>
    <link href="http://junkheap.net/blog/2011/11/22/using-cidetector-with-video-from-an-avcapturesession/"/>
    <updated>2011-11-22T08:57:00+11:00</updated>
    <id>http://junkheap.net/blog/2011/11/22/using-cidetector-with-video-from-an-avcapturesession</id>
    <content type="html"><![CDATA[<p>I was checking out the <a href="http://developer.apple.com/library/IOs/#documentation/CoreImage/Reference/CIDetector_Ref/Reference/Reference.html">CIDetector API in iOS5</a>, specifically using it with an <a href="http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVCaptureSession_Class/Reference/Reference.html">AVCaptureSession</a> to detect faces in video.  I&#8217;d never played with the AV Foundation framework before, but it was pretty straight forward to hook up the front camera on the phone as an <code>AVCaptureDevice</code> and get the frames through an <code>AVCaptureVideoDataOutput</code>.</p>


<p>&#13;</p>

<p>However I ran into issues when trying to get <code>CIDetector</code> to find faces in the <code>CIImage</code> from the video.  Eventually I came across the Apple <a href="http://developer.apple.com/library/ios/#samplecode/SquareCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011190">SquareCam sample</a> which contained the solution!</p>


<!-- more -->


<p>The reference for <code>CIDetector</code> only mentions the <code>- featuresInImage:(CIImage *)</code> selector, however there is also an <code>- featuresInImage:(CIImage *) options:(NSDicitonary *)</code> selector which can be used to provide a <code>CIDetectorImageOrientation</code> key.  This is documented in the CIDetector.h (and appears to only be available on iOS and not Mac).  The iPhone camera actually captures video &#8220;natively&#8221; in landscape mode, so if you&#8217;re holding the camera in portrait you need to tell the detector this (I&#8217;m sure if I was more familiar with the AV Foundation framework this would have been obvious).</p>


<p>The SquareCam sample has a good chunk of code for converting a <code>UIDeviceOrientation</code> to the <code>CIDetectorImageOrientation</code> required by <code>CIDetector</code> (essentially an EXIF orientation) - this includes an enum for the various EXIF orientations and working correctly for the front and rear facing cameras, but as a basic hack for working in portrait mode with the front facing camera all you need to do is:</p>


<p>&#13;</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='objc'><span class='line'><span class="n">imageOptions</span> <span class="o">=</span> <span class="p">[</span><span class="n">NSDictionary</span> <span class="nl">dictionaryWithObject:</span><span class="p">[</span><span class="n">NSNumber</span> <span class="nl">numberWithInt:</span><span class="mi">6</span><span class="p">]</span>
</span><span class='line'><span class="nl">forKey:</span><span class="n">CIDetectorImageOrientation</span><span class="p">];</span>
</span><span class='line'><span class="n">NSArray</span> <span class="o">*</span><span class="n">features</span> <span class="o">=</span> <span class="p">[</span><span class="n">detector</span> <span class="nl">featuresInImage:</span><span class="n">image</span> <span class="nl">options:</span><span class="n">imageOptions</span><span class="p">];</span>
</span></code></pre></td></tr></table></div></figure>




<p>(this is the 0 row on the right and 0 col on top orientation - ie. image needs to be rotated 90º CCW to get it to the right orientation)</p>


<p>&#13;</p>

<p>Anyway, probably something obvious for more experienced folk, but having never played with the AV stuff I didn&#8217;t realise what the issue could be, so was happy to find the solution, so I&#8217;ll leave this here in case anyone else is running into the same issue.</p>


<p></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Solving a "login loop" in Mac OS X Lion due to corrupt LaunchServices cache]]></title>
    <link href="http://junkheap.net/blog/2011/09/22/solving-a-login-loop-in-mac-os-x-lion-due-to-corrupt/"/>
    <updated>2011-09-22T11:46:00+10:00</updated>
    <id>http://junkheap.net/blog/2011/09/22/solving-a-login-loop-in-mac-os-x-lion-due-to-corrupt</id>
    <content type="html"><![CDATA[<p>Because it might help someone else Googling and it took me forever to find. I could no longer login to my account after a few system crashes due to bad RAM during the login process.</p>


<p>&#13;</p>

<p>If you are suffering from a so-called &#8220;login loop&#8221; in Mac OS X 10.7 Lion - ie. you login to your account and then suddenly you&#8217;re back at the login prompt again - your LaunchServices cache might be corrupt.</p>


<!-- more -->


<p>If you check your Console from another user account and the Stack Trace for a bunch of login related processes (loginwindow etc) shows a crash in:</p>


<p>&#13;</p>

<p><code>0   com.apple.LaunchServices      <span> </span>0x00007fff8fa7dd24 CSStoreGetUnit + 40</code></p>


<p>&#13;</p>

<p>Then this may be the case.  Older articles around the internets refer to deleting the LaunchServices cache in /Library/Caches or ~/Library/Caches however on my Lion machine I couldn&#8217;t find this file.</p>


<p>&#13;</p>

<p>Where you&#8217;ll actually find it is in:</p>


<p>&#13;</p>

<p><code>/private/var/folders/XX/YY/C/com.apple.LaunchServices-034ZZZ.csstore</code></p>


<p>&#13;</p>

<p>Where XX and YY are random names - your user account will only have access to your own, you&#8217;ll need to look into each of the folders under &#8220;folders&#8221; and find which one is yours (ls -al will show ownership).</p>


<p>&#13;</p>

<p>The ZZZ is your userid (a number - the first user on the machine is 501 and so on).</p>


<p>&#13;</p>

<p>Delete this file and you should be able to login! </p>


<p>&#13;</p>

<p>Note that this cache stores all of your customised file associations and things like default browser - so you&#8217;ll lose those settings. It might even lose your &#8220;Login Items&#8221; you&#8217;ve configured, but I can&#8217;t be sure that wasn&#8217;t one of the other files I&#8217;d previously deleted that stored that :)</p>


<p>&#13;</p>

<p>Took me about 3 hours of mucking around and searching for clues on the Internet to find that bugger!</p>


<p></p>
]]></content>
  </entry>
  
</feed>
