Adding Groovy Support to Eclipse Mars 4.5

The short answer:

  1. Open Eclipse
  2. Select the menu: Help->Install new software…
  3. Click the Add… button
  4. Enter http://dist.springsource.org/snapshot/GRECLIPSE/e4.5/ for the name and URL
  5. Select groovy packages and install

The longer answer is that that since Pivotal Software has dropped funding for Groovy there is a bit of a transition period and things aren’t as easy to find as they used to be. I also no longer find using STS as beneficial since a quick install to get running was the goal and if I have to install Groovy support separately moving forward with STS too then why not use the standard Eclipse app?

Finding adb on OSX with Android Studio

I had a software update on my phone and referred to my earlier post on a
Tethering Fix for Xperia Z2 on Lollipop 5.0 when I realised I didn’t have adb in my path anymore. For those who have moved up to Android Studio and not updated your path, you’ll need to add something like this to your .bashrc or .bash_profile

PATH=~/Library/Android/sdk/platform-tools:$PATH

Tethering Fix for Xperia Z2 on Lollipop 5.0

After upgrading my phone to Android Lollipop, mobile tethering stopped working. I rang my operator and they said my account allowed it so it should work fine. They then ran me through a bunch of steps and it still didn’t work.

I found a long discussion on XDA developer that I was going to review eventually and then my colleague sent me through this fix to type into an adb shell:

settings put global tether_dun_required 0

And now it works. Hopefully it will help you too.

Thank you to silvrback and you can see his more in-depth explanation here: https://pmf.silvrback.com/fixing-tethering-on-android-kitkat

Hide PostgreSQL user in OSX Yosemite

If you install Postgres from enterprisedb.com then you’ll have a PostgreSQL user created that shows up in your login screen. It’s not the end of the world but is mildly irritating so here’s how to hide the account from the GUI:

sudo dscl . create /Users/postgres IsHidden 1

Note that /Users/postgres is not the home folder of the user but simply the path /Users/ followed by the user’s shortname. I tried pointing the tool to the users home folder with no luck.

Thanks to Apple Support for this answer. http://support.apple.com/en-us/HT203998

Groovy / Spring / Spring Security / Gmock : Last method called on mock already has a non-fixed count set

I banged my head against the wall for quite a while trying to figure this error out in my Groovy Junit tests:

Request processing failed; nested exception is java.lang.IllegalStateException: Last method called on mock already has a non-fixed count set.

I’m using Spring 4.0 with Spring Security 3.2.5 and thought maybe it was something to do with my test setup.  It turns out to be pretty straightforward.  I hadn’t wrapped my test in a play closure.  So going from this:

def r = mockMvc.perform(get("/...")).andExpect(status().isOk()).andReturn()

to this:

play {
  def r = mockMvc.perform(get("/...")).andExpect(status().isOk()).andReturn()
}

solved my problem.

Using CSS instead of XPath in Xopus config to set placeholder text in Xopus

We have URLs that are generated from the main topic’s title element and we wanted the authors to be aware of this when they created a page in Xopus. I thought it would be a simple update to the Xopus config.xml file but it turned out not to be. In the end, we added content using CSS instead of using the Xopus config like this:

/* This adds text to Xopus specifically on the first page title*/
#xopus-xsl-root div h1.topic-title:first-of-type .xopus-placeholder:after {
  content: ' (used for generating page URL)';
}

I believe this could do with a little more refinement but it’s worked in all the cases we’ve tested so we are happy.

If you are interested in what didn’t work, keep reading.

One of the limitations of the Xopus placeholder configuration option is that it is not really XPath so it only matches on the element name, attribute name or a class name.  This is documented on the Xopus Use of XPath in configuration FAQ page.

So we first tried:

<x:node match="class('topic/title')" preferElementsOnlyParent="true">
  <x:name xml:lang="en">Title (used to generate URL)</x:name>
  <x:placeholder xml:lang="en">{name}</x:placeholder>
</x:node>

But this added the message ‘ (used to generate URL)’ to the titles on figures, sections and other elements. My next thought was to do add the longer placeholder only to actual descendants of the topic element (and go back and add concept, etc. later) like this:

<x:node match="topic/title" preferElementsOnlyParent="true">
  <x:name xml:lang="en">Title (used to generate URL)</x:name>
  <x:placeholder xml:lang="en">{name}</x:placeholder>
</x:node>
<x:node match="class('topic/title')" preferElementsOnlyParent="true">
  <x:name xml:lang="en">Title</x:name>
  <x:placeholder xml:lang="en">{name}</x:placeholder>
</x:node>

This resulted in not showing the additional text message anywhere because the Xopus config doesn’t use full XPath, as I mentioned earlier so a match of topic/title matches all titles and since class(‘topic/title’) also matches the element and it comes later in the file, that is the version that was used.

Installing a SuperNexus ROM on Galaxy S3

I finally did it. I finally rooted my Galaxy S3 and installed a custom ROM. This usually happens when my phone becomes slow and I think “this phone was fast last year so what is wrong?”

I also despise hearing about new Android features but not being able to use them. My Google Now was horrendously slow on my Samsung TouchWiz ROM.  I just got a galaxy tab 10 too and I found that things were just different enough between the two to annoy me when switching back and forth.

So was it hard? Not at all. I’d explain but the instructions on the SuperNexus ROM announcement page are adequate. If you have problems, let me know and I’ll help. I’ve flashed a lot of ROMs on other devices but this is the first one on my S3.

http://forum.xda-developers.com/showthread.php?t=2219885

Now for what didn’t work very well.

Barclays mobile app wouldn’t run on my rooted Galaxy S3. It would start and take me through all the steps then bomb out saying that you cannot run the app on rooted devices. This is annoying because I’ve come to rely on this application’s mobile pinsentry functionality.  After a little research, I found that I could get the Barclays Mobile application to run on my rooted phone using the steps below. I basically followed the instructions I found here: http://forum.xda-developers.com/showthread.php?t=1710613

  1. Buy TriangleAway
  2. Tell it to reset your custom ROM counter
  3. Open the SuperSU application
  4. Click the button that says prepare for reinstallation via google play (or something similar…my app is gone now so I can’t go back and look!)
  5. Reboot
  6. Your phone now is not flagged as having a custom ROM and superSU is not installed
  7. Run the Barclays app and set it up
  8. Unverified yet: reinstall SuperSU from the play store. I’ve read that this will work but I’ll download it and use it when I need it next. For now things are in good shape on my phone.

I’ve heard that this will help you use SkyGo on a rooted Galaxy S3 too but I haven’t tried that either. Bonus: my Netflix application works now too!

I’ve been running the ROM for a day and am incredibly pleased with my phone again. I’d recommend flashing to anybody who is a little frustrated with lags and the overall performance of their Galaxy S3 at the moment. It’s not a hardware problem, it’s a software one!

Looking for XML elements in Javascript with e4x

If you are manipulating XML in Javascript then E4X is one of the options available to you. The problem is that the documentation is a little thin and the examples only show you how to find things that definitely exist. So here’s some help in trying to see if elements exist or not.

In this example, I’m processing DITA and trying to find the “title” of the document. This can be in a variety of locations in DITA and can be a <title> in a topic, concept, etc. or a <mainbooktitle> element in a bookmap. So how do you see if you have a mainbooktitle in e4x?

var concept = new XML("...my dita concept xml...");
var mainbooktitle = concept..mainbooktitle;
if (mainbooktitle.length() > 0) {
    // we have a mainbooktitle
}

The concept..mainbooktitle construct finds all children elements in the document named mainbooktitle and returns them in an XMLList. Crucially the documentation does not tell you that an XMLList is always returned and can either be:

  1. A list of length zero meaning no elements named mainbooktitle were found
  2. A list of length one meaning only one element was found. When this happens, you can refer to the item as if it were not in a list. For example, to get the id attribute you could just say mainbooktitle.@id instead of mainbooktitle[0].@id.
  3. A list of length greater than one. You should then use a for each loop or access items by index like this mainbooktitle[1].@id

I hope this saves somebody some time because I had to figure it out by trial and error!

“Flash the screen when an alert sound occurs” disabled but my screen still flashes!

I’m not sure when it started but I recently noticed that my screen was flashing all of the time when I was using the terminal instead of sounding a tone like it should. I dug around in Terminal’s preferences and in Universal Access but everything seemed to be in order.

A couple of Google searches later and I came across a post from Erik Phansen that solved my problem. It boils down to running one command in the terminal:

sudo killall coreaudiod

http://blog.erikphansen.com/weird-os-10-7-lion-audiovideo-problems/

Note that I had some strange feedback echoes after killing coreaudiod that I fixed by alternating between starting iTunes and playing some music and killing coreaudiod. Unfortunately I can’t say what combination stopped the echoes.

How long are my URLs?

We are trying to reduce the allowed URL length in one of our applications for security reasons. The first question that you need to answer when doing an optimisation like this is “how many characters do I need to keep my application running?” You can look through your apache log files to find out. Here is a command-line script to help you find out how long your URLs are:

cat access.log* | cut -d" " -f7 | awk '{ print length($0),$0 }' | sort -nu

One thing I noticed is that apache logs URL-encoded strings so the line lengths are too high if you have multibyte or special characters in your URLs. I was able to read the results  and do the maths manually this time but I will probably need to sort that out for the next round.