<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><description></description><title>(¬; Alex's Stuff :¬)</title><generator>Tumblr (3.0; @alxndrsn)</generator><link>https://blog.alxndrsn.com/</link><item><title>mmmm ES6

pi = () =&amp;gt; { value: 3,141592654 };
</title><description>&lt;h1&gt;mmmm ES6&lt;/h1&gt;

&lt;pre&gt;&lt;code class="js"&gt;pi = () =&amp;gt; { value: 3,141592654 };
&lt;/code&gt;&lt;/pre&gt;</description><link>https://blog.alxndrsn.com/post/164134715795</link><guid>https://blog.alxndrsn.com/post/164134715795</guid><pubDate>Sun, 13 Aug 2017 14:31:26 +0100</pubDate></item><item><title>Javascript: how to delete</title><description>&lt;p&gt;Oh, what a lovely API:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;'x/y/z'.replace(/\//g, '')
'xyz'

'x/y/z'.replace(/\//g)
'xundefinedyundefinedz'\
&lt;/code&gt;&lt;/pre&gt;</description><link>https://blog.alxndrsn.com/post/162120117520</link><guid>https://blog.alxndrsn.com/post/162120117520</guid><pubDate>Thu, 22 Jun 2017 12:07:06 +0100</pubDate></item><item><title>Manipulating browser history - a simple example</title><description>&lt;h1&gt;Manipulating browser history&lt;/h1&gt;

&lt;p&gt;Here&amp;rsquo;s a simple example of manipulating the browser history using javascript:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   &amp;lt;html&amp;gt;
            &amp;lt;head&amp;gt;
            &amp;lt;/head&amp;gt;
            &amp;lt;body&amp;gt;

            &amp;lt;h1&amp;gt;
                    Counter: &amp;lt;span id="status"&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/h1&amp;gt;
            &amp;lt;div id="controls"&amp;gt;
                    &amp;lt;button id="next"&amp;gt;Next&amp;lt;/button&amp;gt;
            &amp;lt;/controls&amp;gt;

            &amp;lt;script&amp;gt;
                    // capture BACK events
                    window.addEventListener('popstate', function(event) {
                            window.updateCounter(event.state.count);
                    });

                    window.updateCounter = function(count) {
                            window.count = count;
                            document.getElementById('status').innerHTML = count;
                    };
                    document.getElementById('next')
                            .addEventListener('click', function() {
                                    // create a fake history item
                                    var newCount = window.count + 1;
                                    window.history.pushState({ count: newCount }, '');
                                    window.updateCounter(newCount);
                            });

                    // set up initial state and fake history item
                    window.history.replaceState({ count: 0 }, '');
                    window.updateCounter(0);
            &amp;lt;/script&amp;gt;

            &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</description><link>https://blog.alxndrsn.com/post/132205436830</link><guid>https://blog.alxndrsn.com/post/132205436830</guid><pubDate>Fri, 30 Oct 2015 11:36:14 +0000</pubDate></item><item><title># Immutable Objects in Java

Save some typing by declaring immutable object in Java like this:

   ...</title><description>&lt;p&gt;# Immutable Objects in Java&lt;/p&gt;

&lt;p&gt;Save some typing by declaring immutable object in Java like this:&lt;/p&gt;

&lt;p&gt;    public class SomeImmutableObject {&lt;br/&gt;
        public final SomeClass field1;&lt;br/&gt;
        public final SomeOtherClass field2;&lt;br/&gt;
        &lt;br/&gt;
        public SomeImmutableObject(SomeClass value1, SomeOtherClass value2) {&lt;br/&gt;
            field1 = value1;&lt;br/&gt;
            field2 = value2;&lt;br/&gt;
        }&lt;br/&gt;
    }&lt;br/&gt;
  &lt;br/&gt;
Apparently in [Effective Java](&lt;a href="http://uet.vnu.edu.vn/~chauttm/e-books/java/Effective.Java.2nd.Edition.May.2008.3000th.Release.pdf"&gt;http://uet.vnu.edu.vn/~chauttm/e-books/java/Effective.Java.2nd.Edition.May.2008.3000th.Release.pdf&lt;/a&gt;) [Joshua Bloch](&lt;a href="https://en.wikipedia.org/wiki/Joshua_Bloch"&gt;https://en.wikipedia.org/wiki/Joshua_Bloch&lt;/a&gt;) wrote:&lt;/p&gt;

&lt;p&gt;&amp;gt; While it’s never a good idea for a public class to expose fields directly, it is less harmful if the fields are immutable. You can’t change the representation of such a class without changing its API, and you can’t take auxiliary actions when a field is read, but you can enforce invariants.&lt;/p&gt;

&lt;p&gt;and further&lt;/p&gt;

&lt;p&gt;&amp;gt; In summary, public classes should never expose mutable fields. It is less harmful, though still questionable, for public classes to expose immutable fields.&lt;/p&gt;

&lt;p&gt;I think it&amp;rsquo;s great to know when a class is immutable.&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/124750918820</link><guid>https://blog.alxndrsn.com/post/124750918820</guid><pubDate>Wed, 22 Jul 2015 15:32:20 +0100</pubDate></item><item><title># Open NERDTree automatically

To open [NERDTree][1] automatically when in the root directory of a...</title><description>&lt;p&gt;# Open NERDTree automatically&lt;/p&gt;

&lt;p&gt;To open [NERDTree][1] automatically when in the root directory of a project, add the following to your `.vimrc`:&lt;/p&gt;

&lt;p&gt;    if !empty(glob(&amp;ldquo;./.git/&amp;rdquo;))&lt;br/&gt;
            autocmd VimEnter * NERDTree&lt;br/&gt;
            autocmd VimEnter * wincmd p &amp;ldquo; and move focus to the main window&lt;br/&gt;
    endif&lt;br/&gt;
    &lt;br/&gt;
This assumes that you&amp;rsquo;re using [git][2] for version control, and [vim][3] :¬)&lt;/p&gt;

&lt;p&gt;[1]: &lt;a href="https://github.com/scrooloose/nerdtree"&gt;https://github.com/scrooloose/nerdtree&lt;/a&gt;&lt;br/&gt;
[2]: &lt;a href="https://www.git-scm.com/"&gt;https://www.git-scm.com/&lt;/a&gt;&lt;br/&gt;
[3]: &lt;a href="http://www.vim.org/"&gt;http://www.vim.org/&lt;/a&gt;&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/119111456385</link><guid>https://blog.alxndrsn.com/post/119111456385</guid><pubDate>Sat, 16 May 2015 16:26:11 +0100</pubDate></item><item><title># StaleObjectException in grails domain custom validator

Just ran into this issue where the custom...</title><description>&lt;p&gt;# StaleObjectException in grails domain custom validator&lt;/p&gt;

&lt;p&gt;Just ran into this issue where the custom validator in a Grails GORM domain object was throwing a `StaleObjectException` for no obvious reason.  Turns out that referencing a transactional service in a custom validator will cause this exception to be thrown without fail.&lt;/p&gt;

&lt;p&gt;## Fix?&lt;/p&gt;

&lt;p&gt;Add the following to the top of your Service:&lt;/p&gt;

&lt;p&gt;	transactional = false&lt;/p&gt;

&lt;p&gt;Painful.&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/61752434307</link><guid>https://blog.alxndrsn.com/post/61752434307</guid><pubDate>Fri, 20 Sep 2013 13:11:00 +0100</pubDate><category>grails gorm StaleObjectException</category></item><item><title># StackOverflowError from Grails Routing Plugin

Was receiving the following rather confusing error...</title><description>&lt;p&gt;# StackOverflowError from Grails Routing Plugin&lt;/p&gt;

&lt;p&gt;Was receiving the following rather confusing error on startup of our grails app:&lt;/p&gt;

&lt;p&gt;	org.quartz.JobExecutionException: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.reflect.UndeclaredThrowableException] [See nested exception: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.reflect.UndeclaredThrowableException]]&lt;br/&gt;
		at org.quartz.core.JobRunShell.run(JobRunShell.java:229)&lt;br/&gt;
		at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)&lt;br/&gt;
	Caused by: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.reflect.UndeclaredThrowableException]&lt;br/&gt;
		at org.quartz.core.JobRunShell.run(JobRunShell.java:224)&lt;br/&gt;
		&amp;hellip; 1 more&lt;br/&gt;
	Caused by: java.lang.reflect.UndeclaredThrowableException&lt;br/&gt;
		at grails.plugin.hibernatehijacker.template.HibernateTemplates.withTransaction(HibernateTemplates.groovy:37)&lt;br/&gt;
		at grails.plugin.multitenant.core.MultiTenantService$_doWithTenantId_closure1.doCall(MultiTenantService.groovy:31)&lt;br/&gt;
		at grails.plugin.hibernatehijacker.template.HibernateTemplates$_withNewSession_closure2.doCall(HibernateTemplates.groovy:65)&lt;br/&gt;
		at grails.plugin.hibernatehijacker.template.HibernateTemplates.withNewSession(HibernateTemplates.groovy:57)&lt;br/&gt;
		at grails.plugin.multitenant.core.MultiTenantService.doWithTenantId(MultiTenantService.groovy:30)&lt;br/&gt;
		at grails.plugin.multitenantsingledbquartz2integration.TenantAwareJobFactory$1.execute(TenantAwareJobFactory.groovy:27)&lt;br/&gt;
		at org.quartz.core.JobRunShell.run(JobRunShell.java:213)&lt;br/&gt;
		&amp;hellip; 1 more&lt;br/&gt;
	Caused by: org.quartz.JobExecutionException: java.lang.StackOverflowError [See nested exception: java.lang.StackOverflowError]&lt;br/&gt;
		at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:66)&lt;br/&gt;
		at grails.plugin.multitenantsingledbquartz2integration.TenantAwareJobFactory$_1_execute_closure1.doCall(TenantAwareJobFactory.groovy:28)&lt;br/&gt;
		at grails.plugin.multitenant.core.MultiTenantService$_doWithTenantId_closure1_closure2.doCall(MultiTenantService.groovy:32)&lt;br/&gt;
		at grails.plugin.hibernatehijacker.template.HibernateTemplates$_withTransaction_closure1.doCall(HibernateTemplates.groovy:39)&lt;br/&gt;
		&amp;hellip; 8 more&lt;br/&gt;
	Caused by: java.lang.StackOverflowError&lt;br/&gt;
		at RoutingGrailsPlugin$_initializeRouteBuilderHelpers_closure6.doCall(RoutingGrailsPlugin.groovy:113)&lt;br/&gt;
		at RoutingGrailsPlugin$_initializeRouteBuilderHelpers_closure6.doCall(RoutingGrailsPlugin.groovy:113)&lt;br/&gt;
		at RoutingGrailsPlugin$_initializeRouteBuilderHelpers_closure6.doCall(RoutingGrailsPlugin.groovy:113)&lt;br/&gt;
		at RoutingGrailsPlugin$_initializeRouteBuilderHelpers_closure6.doCall(RoutingGrailsPlugin.groovy:113)&lt;br/&gt;
		at RoutingGrailsPlugin$_initializeRouteBuilderHelpers_closure6.doCall(RoutingGrailsPlugin.groovy:113)&lt;br/&gt;
		at RoutingGrailsPlugin$_initializeRouteBuilderHelpers_closure6.doCall(RoutingGrailsPlugin.groovy:113)&lt;/p&gt;

&lt;p&gt;# The cause&lt;/p&gt;

&lt;p&gt;Defining a camel route with `.process(new MyFakeProcessor())` where MyFakeProcessor *doesn&amp;rsquo;t* implement `org.apache.camel.Processor`.&lt;/p&gt;

&lt;p&gt;# The fix&lt;/p&gt;

&lt;p&gt;Replace&lt;/p&gt;

&lt;p&gt;    .process(new MyFakeProcessor())&lt;/p&gt;

&lt;p&gt;With&lt;/p&gt;

&lt;p&gt;    .bean(new MyFakeProcessor(), &amp;lsquo;process&amp;rsquo;)&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/59391504870</link><guid>https://blog.alxndrsn.com/post/59391504870</guid><pubDate>Mon, 26 Aug 2013 13:56:22 +0100</pubDate></item><item><title># simple, sensible bash logging

This code will allow you to call e.g. `log &amp;lsquo;script...</title><description>&lt;p&gt;# simple, sensible bash logging&lt;/p&gt;

&lt;p&gt;This code will allow you to call e.g. `log &amp;lsquo;script starting&amp;hellip;&amp;rsquo;` in a bash script, and formatted log output provided:&lt;/p&gt;

&lt;p&gt;	# [script_name] script starting&amp;hellip;&lt;/p&gt;

&lt;p&gt;Further, if a script is sourced from another script, logging in the parent script and child script will both acknowledge the parent, but will clearly show which script they are from:&lt;/p&gt;

&lt;p&gt;	# [parent_script] sourcing child&amp;hellip;&lt;br/&gt;
	# [parent_script] [child_script] script starting&amp;hellip;&lt;/p&gt;

&lt;p&gt;The code is below.  It assumes the function will be included in a separate script file sourced from the main script.&lt;/p&gt;

&lt;p&gt;	function log {&lt;br/&gt;
		local logStart=&amp;ldquo;#&amp;rdquo;&lt;br/&gt;
		local sourceLen=${#BASH_SOURCE[@]}&lt;br/&gt;
		# if including this function directly in the top-level&lt;br/&gt;
		# script, terminating condition should be: `i&amp;gt;=0`&lt;br/&gt;
		for ((i=$sourceLen-1; i&amp;gt;0; &amp;ndash;i)); do&lt;br/&gt;
			logStart=&amp;ldquo;$logStart [$(basename ${BASH_SOURCE[$i]})]&amp;rdquo;&lt;br/&gt;
		done&lt;br/&gt;
		echo &amp;ldquo;$logStart $@&amp;rdquo;&lt;br/&gt;
	}&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/58995572042</link><guid>https://blog.alxndrsn.com/post/58995572042</guid><pubDate>Thu, 22 Aug 2013 09:32:00 +0100</pubDate></item><item><title># Grails build-test-data plugin and compilation

I had a strange experience recently where grails...</title><description>&lt;p&gt;# Grails build-test-data plugin and compilation&lt;/p&gt;

&lt;p&gt;I had a strange experience recently where grails unit and integration tests were happily passing on my machine (with `grails test-app unit:`), but failing on jenkins (with `grails clean; grails test-app unit:`).  The error:&lt;/p&gt;

&lt;p&gt;	Failure:  |&lt;br/&gt;
	test_name(frontlinesms2.MySpec)&lt;br/&gt;
	 |&lt;br/&gt;
	grails.buildtestdata.handler.ConstraintHandlerException: Validator constraint support not implemented in build-test-data, attempted value (0) does not pass validation: property amount of frontlinesms2.MyDomainClass&lt;br/&gt;
		at grails.buildtestdata.handler.ValidatorConstraintHandler.handle(ValidatorConstraintHandler.groovy:14)&lt;br/&gt;
		at grails.buildtestdata.DomainInstanceBuilder.createProperty_closure8(DomainInstanceBuilder.groovy:223)&lt;br/&gt;
		at grails.buildtestdata.DomainInstanceBuilder.createProperty(DomainInstanceBuilder.groovy:219)&lt;br/&gt;
		at grails.buildtestdata.DomainInstanceBuilder.createMissingProperty(DomainInstanceBuilder.groovy:210)&lt;br/&gt;
		at grails.buildtestdata.DomainInstanceBuilder.populateInstance(DomainInstanceBuilder.groovy:168)&lt;br/&gt;
		at grails.buildtestdata.DomainInstanceBuilder.build_closure5(DomainInstanceBuilder.groovy:145)&lt;br/&gt;
		at grails.buildtestdata.DomainInstanceBuilder.logToGraph(DomainInstanceBuilder.groovy:332)&lt;br/&gt;
		at grails.buildtestdata.DomainInstanceBuilder.build(DomainInstanceBuilder.groovy:144)&lt;br/&gt;
		at grails.buildtestdata.DomainInstanceBuilder.build(DomainInstanceBuilder.groovy:143)&lt;br/&gt;
		at grails.buildtestdata.BuildTestDataService.addBuildMethods_closure1(BuildTestDataService.groovy:22)&lt;br/&gt;
		at frontlinesms2.MySpec.setup(MySpec.groovy:13)&lt;/p&gt;

&lt;p&gt;What was weird about this was that I had explicitly set this value in `grails-app/conf/TestDataConfig.groovy` like so:&lt;/p&gt;

&lt;p&gt;	testDataConfig {&lt;br/&gt;
		sampleData {&lt;br/&gt;
			&amp;lsquo;frontlinesms2.MyDomainClass&amp;rsquo; {&lt;br/&gt;
				amount = 1&lt;br/&gt;
			}&lt;br/&gt;
		}&lt;br/&gt;
	}&lt;/p&gt;

&lt;p&gt;Apparently this was ignored if `test-app` was called directly after a clean.&lt;/p&gt;

&lt;p&gt;## How do you fix this?&lt;/p&gt;

&lt;p&gt;	grails clean&lt;br/&gt;
	grails compile&lt;br/&gt;
	grails test-app unit:&lt;/p&gt;

&lt;p&gt;I.e. **add an explicit compile step**.  I&amp;rsquo;m surprised this is necessary.  But it is.&lt;/p&gt;

&lt;p&gt;N.B. this occurred with grails 2.0.3 and java:&lt;/p&gt;

&lt;p&gt;	java version &amp;ldquo;1.6.0_27&amp;rdquo;&lt;br/&gt;
	OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.13.04.2)&lt;br/&gt;
	OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/58995505596</link><guid>https://blog.alxndrsn.com/post/58995505596</guid><pubDate>Thu, 22 Aug 2013 09:31:12 +0100</pubDate></item><item><title># WebDriver with a nice error message

Currently we&amp;rsquo;re suffering from the following exception...</title><description>&lt;p&gt;# WebDriver with a nice error message&lt;/p&gt;

&lt;p&gt;Currently we&amp;rsquo;re suffering from the following exception quite regularly on our Jenkins server:&lt;/p&gt;

&lt;p&gt;	Build info: version: &amp;lsquo;2.30.0&amp;rsquo;, revision: 'dc1ef9ceb805a672f56dc49198f9ffbd4ca345c7&amp;rsquo;, time: '2013-02-19 09:14:38&amp;rsquo;&lt;br/&gt;
	System info: os.name: 'Linux&amp;rsquo;, os.arch: 'amd64&amp;rsquo;, os.version: '3.2.0-37-generic&amp;rsquo;, java.version: '1.6.0_27&amp;rsquo;&lt;br/&gt;
	Driver info: driver.version: FirefoxDriver&lt;br/&gt;
		at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)&lt;br/&gt;
		at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)&lt;br/&gt;
		at org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:110)&lt;br/&gt;
		at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:188)&lt;br/&gt;
		at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:183)&lt;br/&gt;
		at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:179)&lt;br/&gt;
		at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:92)&lt;br/&gt;
		at script1361962190832380912643.run_closure2(script1361962190832380912643.groovy:23)&lt;br/&gt;
		at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)&lt;br/&gt;
		&amp;hellip; 13 more&lt;br/&gt;
	Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:&lt;br/&gt;
	Maximum number of clients reachedMaximum number of clients reachedError: cannot open display: :93&lt;br/&gt;
	Maximum number of clients reachedMaximum number of clients reachedError: cannot open display: :93&lt;/init&gt;&lt;/init&gt;&lt;/init&gt;&lt;/init&gt;&lt;/init&gt;&lt;/p&gt;

&lt;p&gt;I *suspect* this is caused by either:&lt;/p&gt;

&lt;p&gt;* new Firefox update not shutting down properly after Selenium tests are run; or&lt;br/&gt;
* manually terminated (killed) Jenkins builds not shutting down Firefox instances that were spawned as part of the job&lt;/p&gt;

&lt;p&gt;## Solution?&lt;/p&gt;

&lt;p&gt;log into server and `pkill firefox`.  Ugly.&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/44134338629</link><guid>https://blog.alxndrsn.com/post/44134338629</guid><pubDate>Wed, 27 Feb 2013 11:11:26 +0000</pubDate></item><item><title># Why are my Grails functional tests slow?

## Database flushes slow down over time

I&amp;rsquo;ve...</title><description>&lt;p&gt;# Why are my Grails functional tests slow?&lt;/p&gt;

&lt;p&gt;## Database flushes slow down over time&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ve posted this to the Grails mailing list - hopefully we&amp;rsquo;ll get some ideas from there: [&amp;ldquo;Flushes get slower in later tests (integration, functional)&amp;rdquo;](&lt;a href="http://grails.1312388.n4.nabble.com/Flushes-get-slower-in-later-tests-integration-functional-td4641847.html"&gt;http://grails.1312388.n4.nabble.com/Flushes-get-slower-in-later-tests-integration-functional-td4641847.html&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Combine this fact with Spock Specifications like this:&lt;/p&gt;

&lt;p&gt;	class MySpec extends spock.lang.Specification {&lt;br/&gt;
		setup() {&lt;br/&gt;
			100.times {&lt;br/&gt;
				new DomainObject().save(flush:true)&lt;br/&gt;
			}&lt;br/&gt;
		}&lt;br/&gt;
	}&lt;/p&gt;

&lt;p&gt;&amp;hellip;and you get a very slow test suite.  This should also slow down integration tests :¬)&lt;/p&gt;

&lt;p&gt;## Geb selecters are very slow for big content&lt;/p&gt;

&lt;p&gt;It may seem clever to write Geb selecters like&lt;/p&gt;

&lt;p&gt;	messages { moduleList MessageListRow, $(&amp;lsquo;tbody tr&amp;rsquo;) }&lt;/p&gt;

&lt;p&gt;and then call them like this:&lt;/p&gt;

&lt;p&gt;	messages[0].select.click()&lt;/p&gt;

&lt;p&gt;Actually it&amp;rsquo;s not very clever at all - it&amp;rsquo;s very very slow.  This is because, I think, Selenium individually loads each `MessageListRow` using a separate network request.  Even with 50 `MessageListRow`s, it becomes painfully slow to do a simple thing.  To get decent performance, refactor like so:&lt;/p&gt;

&lt;p&gt;	message { index -&amp;gt; ++index; $(&amp;ldquo;tbody tr:nth-child($index)&amp;rdquo;) }&lt;br/&gt;
	toggleSelect { index -&amp;gt; message(index).find('input[type=checkbox]&amp;rsquo;).click(); true }&lt;br/&gt;
	&amp;hellip;&lt;br/&gt;
	toggleSelect(0)&lt;/p&gt;

&lt;p&gt;## Anything else?&lt;/p&gt;

&lt;p&gt;Probably, but even just a couple of tweaks to work around the problems above cut our full test suite execution time from 65 to 45 minutes.&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/44129896935</link><guid>https://blog.alxndrsn.com/post/44129896935</guid><pubDate>Wed, 27 Feb 2013 08:02:00 +0000</pubDate></item><item><title># Jenkins jobs/ directory permissions problems

Sometimes our Jenkins user loses access to the...</title><description>&lt;p&gt;# Jenkins jobs/ directory permissions problems&lt;/p&gt;

&lt;p&gt;Sometimes our Jenkins user loses access to the `jobs` directory when our server is restarted.  We&amp;rsquo;ve not found the cause yet, but the simplest fix seems to be:&lt;/p&gt;

&lt;p&gt;    sudo chmod -R jenkins:jenkins /var/lib/jenkins; sudo su - jenkins; chmod +x jobs&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/43709512043</link><guid>https://blog.alxndrsn.com/post/43709512043</guid><pubDate>Fri, 22 Feb 2013 06:56:42 +0000</pubDate></item><item><title># Spock specs and grails integration tests

Earlier today I started getting the following strange...</title><description>&lt;p&gt;# Spock specs and grails integration tests&lt;/p&gt;

&lt;p&gt;Earlier today I started getting the following strange error in an integration test for a grails app:&lt;/p&gt;

&lt;p&gt;	|  java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.&lt;br/&gt;
		at frontlinesms2.controller.AppInfoControllerISpec.appInfoService should be called with request for relevant data(AppInfoControllerISpec.groovy:20)&lt;br/&gt;
	| Completed 1 spock test, 1 failed in 252ms&lt;/p&gt;

&lt;p&gt;The offending code:&lt;/p&gt;

&lt;p&gt;	given:&lt;br/&gt;
		controller.request.JSON = x&lt;/p&gt;

&lt;p&gt;The problem?  I had mistakenly extended `spock.lang.Specification` instead of `grails.plugin.spock.IntegrationSpec`.  Oops.&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/43000847044</link><guid>https://blog.alxndrsn.com/post/43000847044</guid><pubDate>Wed, 13 Feb 2013 14:06:58 +0000</pubDate></item><item><title># findAllByXNotInList throws NullPointerException with empty list

I guess this is a bug (grails...</title><description>&lt;p&gt;# findAllByXNotInList throws NullPointerException with empty list&lt;/p&gt;

&lt;p&gt;I guess this is a bug (grails 2.0.3, h2 database):&lt;/p&gt;

&lt;p&gt;DomainClass.findAllByIdInList([]) returns ok, but DomainClass.findAllByIdNotInList([]) throws a NullPointerException:&lt;/p&gt;

&lt;p&gt;	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdInList([])&lt;br/&gt;
	===&amp;gt; []&lt;br/&gt;
	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdNotInList([])&lt;br/&gt;
	ERROR java.lang.NullPointerException:&lt;br/&gt;
	null&lt;br/&gt;
	        at org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters (CriteriaQueryTranslator.java:316)&lt;br/&gt;
	        at org.hibernate.loader.criteria.CriteriaLoader.list (CriteriaLoader.java:119)&lt;br/&gt;
	        at org.hibernate.impl.SessionImpl.list (SessionImpl.java:1716)&lt;br/&gt;
	        at org.hibernate.impl.CriteriaImpl.list (CriteriaImpl.java:347)&lt;br/&gt;
	        at org.springframework.orm.hibernate3.HibernateTemplate.doExecute (HibernateTemplate.java:406)&lt;br/&gt;
	        at org.springframework.orm.hibernate3.HibernateTemplate.executeFind (HibernateTemplate.java:343)&lt;br/&gt;
	        at org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2.doCall (GormStaticApi.groovy:105)&lt;br/&gt;
	        at org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2.call (GormStaticApi.groovy)&lt;br/&gt;
	        at groovysh_evaluate.run (groovysh_evaluate:2)&lt;br/&gt;
	        &amp;hellip;&lt;br/&gt;
	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdNotInList([1L])&lt;br/&gt;
	===&amp;gt; []&lt;br/&gt;
	&lt;br/&gt;
or is this a feature?&lt;/p&gt;

&lt;p&gt;For added fun, passing an integer in the list throws a ClassCastException:&lt;/p&gt;

&lt;p&gt;	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdNotInList([1])&lt;br/&gt;
	ERROR java.lang.ClassCastException:&lt;br/&gt;
	java.lang.Integer cannot be cast to java.lang.Long&lt;br/&gt;
	        at org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap (LongTypeDescriptor.java:36)&lt;/p&gt;

&lt;p&gt;The domain class was:&lt;/p&gt;

&lt;p&gt;	package weirdfinder&lt;br/&gt;
	&lt;br/&gt;
	class Dom {&lt;br/&gt;
		String text&lt;br/&gt;
	}&lt;/p&gt;

&lt;p&gt;Also tested on: Grails 2.0.4.&lt;/p&gt;

&lt;p&gt;I guess this has been fixed as Grails 2.2.0 gives different inconsistent results - sometimes an empty list, and sometimes nothing at all:&lt;/p&gt;

&lt;p&gt;	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdInList([])&lt;br/&gt;
	===&amp;gt; []&lt;br/&gt;
	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdInList([1])&lt;br/&gt;
	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdInList([1L])&lt;br/&gt;
	===&amp;gt; []&lt;br/&gt;
	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdNotInList([])&lt;br/&gt;
	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdNotInList([1])&lt;br/&gt;
	groovy:000&amp;gt; weirdfinder.Dom.findAllByIdNotInList([1L])&lt;br/&gt;
	===&amp;gt; []&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/42425160603</link><guid>https://blog.alxndrsn.com/post/42425160603</guid><pubDate>Wed, 06 Feb 2013 12:45:00 +0000</pubDate><category>grails</category><category>gorm</category><category>dynamic-finders</category></item><item><title># Jenkins Violations with JSLint

From what I&amp;rsquo;ve seen, getting Jenkins Violations plugin to...</title><description>&lt;p&gt;# Jenkins Violations with JSLint&lt;/p&gt;

&lt;p&gt;From what I&amp;rsquo;ve seen, getting Jenkins Violations plugin to work with JSLint requires using [jslint4java][1] to generate the jslint report as XML.&lt;/p&gt;

&lt;p&gt;The closest I could find to a spec for the generated XML was looking at the [JSLintParser implementation][2] and [unit tests][3].  It looks like this:&lt;/p&gt;

&lt;p&gt;    &amp;lt;jslint&amp;gt;&lt;br/&gt;
        &amp;lt;file name=&amp;ldquo;path and name of file&amp;rdquo;&amp;gt;&lt;br/&gt;
            &amp;lt;issue reason=&amp;ldquo;&amp;hellip;&amp;rdquo;&lt;br/&gt;
                    evidence=&amp;ldquo;&amp;hellip;&amp;rdquo;&lt;br/&gt;
                    line=&amp;ldquo;&amp;hellip;&amp;rdquo;&lt;br/&gt;
                    char=&amp;ldquo;&amp;hellip;&amp;rdquo;/&amp;gt;&lt;br/&gt;
            &amp;hellip;&lt;br/&gt;
        &amp;lt;/file&amp;gt;&lt;br/&gt;
        &amp;hellip;&lt;br/&gt;
    &amp;lt;/jslint&amp;gt;&lt;/p&gt;

&lt;p&gt;From this, it&amp;rsquo;s fairly simple to make a script which converts JSLint&amp;rsquo;s JSON output (`jslint &amp;ndash;json`) into the XML format required by jenkins-violations-plugin.&lt;/p&gt;

&lt;p&gt;[1]: &lt;a href="https://code.google.com/p/jslint4java/"&gt;https://code.google.com/p/jslint4java/&lt;/a&gt;&lt;br/&gt;
[2]: &lt;a href="https://github.com/jenkinsci/violations-plugin/blob/master/src/main/java/hudson/plugins/violations/types/jslint/JsLintParser.java"&gt;https://github.com/jenkinsci/violations-plugin/blob/master/src/main/java/hudson/plugins/violations/types/jslint/JsLintParser.java&lt;/a&gt;&lt;br/&gt;
[3]: &lt;a href="https://github.com/jenkinsci/violations-plugin/blob/master/src/test/java/hudson/plugins/violations/types/jslint/JsLintParserTest.java"&gt;https://github.com/jenkinsci/violations-plugin/blob/master/src/test/java/hudson/plugins/violations/types/jslint/JsLintParserTest.java&lt;/a&gt;&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/33882822045</link><guid>https://blog.alxndrsn.com/post/33882822045</guid><pubDate>Fri, 19 Oct 2012 07:36:00 +0100</pubDate></item><item><title># Groovy&amp;rsquo;s `String.tokenize()` vs. Java&amp;rsquo;s `String.split()`

Re-discovered a little...</title><description>&lt;p&gt;# Groovy&amp;rsquo;s `String.tokenize()` vs. Java&amp;rsquo;s `String.split()`&lt;/p&gt;

&lt;p&gt;Re-discovered a little difference between Groovy&amp;rsquo;s `String.split()` and `String.tokenize()` methods today:&lt;/p&gt;

&lt;p&gt;    &amp;lsquo;abc.123.wtf&amp;rsquo;.split(&amp;rsquo;.&amp;rsquo;) == []&lt;br/&gt;
    'abc.123.wtf&amp;rsquo;.tokenize(&amp;rsquo;.&amp;rsquo;) == ['abc&amp;rsquo;, '123&amp;rsquo;, 'wtf&amp;rsquo;]&lt;/p&gt;

&lt;p&gt;because&amp;hellip;&lt;/p&gt;

&lt;p&gt;&amp;gt; [String.split()](&lt;a href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split%28java.lang.String%29"&gt;http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split%28java.lang.String%29&lt;/a&gt;)&lt;br/&gt;
&amp;gt; Splits this string around matches of the given regular expression.&lt;/p&gt;

&lt;p&gt;vs.&lt;/p&gt;

&lt;p&gt;&amp;gt; [String.tokenize()](&lt;a href="http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#tokenize%28java.lang.String%29"&gt;http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#tokenize%28java.lang.String%29&lt;/a&gt;)&lt;br/&gt;
&amp;gt; Tokenize a String based on the given string delimiter.&lt;/p&gt;

&lt;p&gt;Why anyone would ever want to call `String.split(&amp;rsquo;.&amp;rsquo;)` is anybody&amp;rsquo;s guess.&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/33768204588</link><guid>https://blog.alxndrsn.com/post/33768204588</guid><pubDate>Wed, 17 Oct 2012 12:38:00 +0100</pubDate></item><item><title># Fixing Git

    alias jit=`which git` &amp;amp;&amp;amp; alias git=&amp;ldquo;echo No command...</title><description>&lt;p&gt;# Fixing Git&lt;/p&gt;

&lt;p&gt;    alias jit=`which git` &amp;amp;&amp;amp; alias git=&amp;ldquo;echo No command &amp;lsquo;git&amp;rsquo; found, did you mean: jit&amp;rdquo;&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/33420174025</link><guid>https://blog.alxndrsn.com/post/33420174025</guid><pubDate>Fri, 12 Oct 2012 09:13:20 +0100</pubDate></item><item><title># Grails Heroku mystery issue

Currently seeing:

## Error 500: Internal Server Error

### URI
   ...</title><description>&lt;p&gt;# Grails Heroku mystery issue&lt;/p&gt;

&lt;p&gt;Currently seeing:&lt;/p&gt;

&lt;p&gt;## Error 500: Internal Server Error&lt;/p&gt;

&lt;p&gt;### URI&lt;br/&gt;
    /&lt;br/&gt;
### Class&lt;br/&gt;
    java.lang.IllegalStateException&lt;br/&gt;
### Message&lt;br/&gt;
    WRITER&lt;/p&gt;

&lt;p&gt;### Trace&lt;/p&gt;

&lt;p&gt;    Line | Method&lt;br/&gt;
	-&amp;gt;&amp;gt;  627 | getOutputStream  in org.eclipse.jetty.server.Response&lt;br/&gt;
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &lt;br/&gt;
	|   1330 | doFilter         in org.eclipse.jetty.servlet.ServletHandler$CachedChain&lt;br/&gt;
	|     51 | doFilterInternal in grails.plugin.databasesession.SessionProxyFilter&lt;br/&gt;
	|   1330 | doFilter         in org.eclipse.jetty.servlet.ServletHandler$CachedChain&lt;br/&gt;
	|    478 | doHandle &amp;hellip; . in org.eclipse.jetty.servlet.ServletHandler&lt;br/&gt;
	|    119 | handle           in org.eclipse.jetty.server.handler.ScopedHandler&lt;br/&gt;
	|    520 | handle &amp;hellip; . . in org.eclipse.jetty.security.SecurityHandler&lt;br/&gt;
	|    227 | doHandle         in org.eclipse.jetty.server.session.SessionHandler&lt;br/&gt;
	|    941 | doHandle &amp;hellip; . in org.eclipse.jetty.server.handler.ContextHandler&lt;br/&gt;
	|    409 | doScope          in org.eclipse.jetty.servlet.ServletHandler&lt;br/&gt;
	|    186 | doScope &amp;hellip; .  in org.eclipse.jetty.server.session.SessionHandler&lt;br/&gt;
	|    875 | doScope          in org.eclipse.jetty.server.handler.ContextHandler&lt;br/&gt;
	|    117 | handle &amp;hellip; . . in org.eclipse.jetty.server.handler.ScopedHandler&lt;br/&gt;
	|    250 | handle           in org.eclipse.jetty.server.handler.ContextHandlerCollection&lt;br/&gt;
	|    149 | handle &amp;hellip; . . in org.eclipse.jetty.server.handler.HandlerCollection&lt;br/&gt;
	|    110 | handle           in org.eclipse.jetty.server.handler.HandlerWrapper&lt;br/&gt;
	|    345 | handle &amp;hellip; . . in org.eclipse.jetty.server.Server&lt;br/&gt;
	|    441 | handleRequest    in org.eclipse.jetty.server.HttpConnection&lt;br/&gt;
	|    919 | headerComplete . in org.eclipse.jetty.server.HttpConnection$RequestHandler&lt;br/&gt;
	|    582 | parseNext        in org.eclipse.jetty.http.HttpParser&lt;br/&gt;
	|    218 | parseAvailable . in     &amp;ldquo;&lt;br/&gt;
	|     51 | handle           in org.eclipse.jetty.server.AsyncHttpConnection&lt;br/&gt;
	|    586 | handle &amp;hellip; . . in org.eclipse.jetty.io.nio.SelectChannelEndPoint&lt;br/&gt;
	|     44 | run              in org.eclipse.jetty.io.nio.SelectChannelEndPoint$1&lt;br/&gt;
	|    598 | runJob &amp;hellip; . . in org.eclipse.jetty.util.thread.QueuedThreadPool&lt;br/&gt;
	|    533 | run              in org.eclipse.jetty.util.thread.QueuedThreadPool$3&lt;br/&gt;
	^    636 | run &amp;hellip; &amp;hellip;  in java.lang.Thread&lt;/p&gt;

&lt;p&gt;Hopefully I&amp;rsquo;ll find out why tomorrow!&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/30472985541</link><guid>https://blog.alxndrsn.com/post/30472985541</guid><pubDate>Wed, 29 Aug 2012 22:03:03 +0100</pubDate></item><item><title># Git clone gets stuck when &amp;ldquo;Receiving objects&amp;rdquo;

Setting up our Jenkins machine...</title><description>&lt;p&gt;# Git clone gets stuck when &amp;ldquo;Receiving objects&amp;rdquo;&lt;/p&gt;

&lt;p&gt;Setting up our Jenkins machine recently, and with Zuku internet being very patchy, I found git constantly getting stuck while trying to clone.&lt;/p&gt;

&lt;p&gt;    Cloning into &amp;rsquo;/var/lib/jenkins/jobs/frontlinesms2-core-maintenance-service/workspace&amp;rsquo;&amp;hellip;&lt;br/&gt;
    remote: Counting objects: 51274, done.&lt;br/&gt;
    remote: Compressing objects: 100% (12986/12986), done.&lt;br/&gt;
    Receiving objects:   2% (1026/51274), 196.00 KiB    Kib/s&lt;/p&gt;

&lt;p&gt;It seems that [git doesn&amp;rsquo;t work very well with poor internet connections](&lt;a href="http://stackoverflow.com/questions/3954852/how-to-complete-a-git-clone-for-a-big-project-on-an-unstable-connection"&gt;http://stackoverflow.com/questions/3954852/how-to-complete-a-git-clone-for-a-big-project-on-an-unstable-connection&lt;/a&gt;).  This is a shame, and there are only two suggested solutions:&lt;/p&gt;

&lt;p&gt;## 1. download as a folder using e.g. wget&lt;br/&gt;
I&amp;rsquo;m not sure how practical this is in real life - e.g. if you&amp;rsquo;re downloading a folder from github or an Apache project, is it actually possible to wget a git repo?&lt;/p&gt;

&lt;p&gt;## 2. shallow clone&lt;br/&gt;
Add the argument `&amp;ndash;depth=1` to the arguments of `git clone`, e.g.&lt;/p&gt;

&lt;p&gt;    git clone &amp;ndash;depth=1 git://username@example.com&lt;/p&gt;

&lt;p&gt;This still suffers, though, from the standard issues of having a poor connection - it just has a higher chance of successfully completing before the connection is interrupted.&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/27978230781</link><guid>https://blog.alxndrsn.com/post/27978230781</guid><pubDate>Wed, 25 Jul 2012 13:36:00 +0100</pubDate></item><item><title># Adding display support for Jenkins on Ubuntu

Running Selenium tests on our new Jenkins server was...</title><description>&lt;p&gt;# Adding display support for Jenkins on Ubuntu&lt;/p&gt;

&lt;p&gt;Running Selenium tests on our new Jenkins server was failing with:&lt;/p&gt;

&lt;p&gt;    Error: no display specified&lt;/p&gt;

&lt;p&gt;Turns out we need to configure a display for the Jenkins user.  I couldn&amp;rsquo;t find any clear information on the best way to do this, but the following seems to work:&lt;/p&gt;

&lt;p&gt;## Start Xvfb&lt;/p&gt;

&lt;p&gt;Add the following to `/etc/init/jenkins.conf`:&lt;/p&gt;

&lt;p&gt;    pre-start script # this line was already here&lt;br/&gt;
        # Start X graphics so that Firefox can run from Jenkins functional tests&lt;br/&gt;
        Xvfb :93 -ac &amp;amp;&lt;br/&gt;
        # Completed X setup&lt;br/&gt;
        &amp;hellip;&lt;br/&gt;
    end script&lt;/p&gt;

&lt;p&gt;I chose the number _93_ because it&amp;rsquo;s quite big and doesn&amp;rsquo;t clash with other configured displays on my system.&lt;/p&gt;

&lt;p&gt;## Set DISPLAY environment variable&lt;/p&gt;

&lt;p&gt;In Jenkins configuration, set the environment variable `DISPLAY` to `:93`.&lt;/p&gt;</description><link>https://blog.alxndrsn.com/post/27977673063</link><guid>https://blog.alxndrsn.com/post/27977673063</guid><pubDate>Wed, 25 Jul 2012 13:15:00 +0100</pubDate></item></channel></rss>
