Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

How to debug Play applications setup with the Typesafe stack from IntelliJ May 23, 2012

Filed under: IntelliJ,playframework,Web — Rupert Bates @ 8:18 pm
Tags: , ,

Windows:
Set your sbt.bat to the following:

set SCRIPT_DIR=%~dp0
set SBT_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999
java %SBT_OPTS% -Xmx512M -XX:MaxPermSize=256m -jar “%SCRIPT_DIR%sbt-launch.jar” %*

Run SBT in your project folder and then the ‘run’ command

In IntelliJ set up a run configuration (Run/Edit Configurations) as follows:

Add a new ‘Remote’ configuration
Give it a name
Set transport to ‘Socket’
Set debugger to ‘Attach’
Set host to localhost set port to 9999 (so it matches the port you set in SBT_OPTS in the sbt.bat file)

Put in some breakpoints and hit debug.

 

I’ll add in Linux/MacOs instructions next time I’m at a Linux box…

 

Setting child divider on an ExpandableListView causes weird flashing overlay on some Samsung phones November 29, 2011

Filed under: Android,Error — Rupert Bates @ 2:22 pm

This is a weird niche bug which I’m documenting here in case I need it in future.

Affected devices:
I have only seen it occur on a Samsung Galaxy S2 but I’m guessing it probably happens on any 2.x Samsung device running TouchWiz (it doesn’t happen on the Nexus S)

Steps to reproduce:
Create an activity with an ExpandableListView and set the childDivider property of the ExpandableListView to any colour, say red for ease of viewing


<ExpandableListView android:id="@+id/pageBundles"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:childDivider="@color/red"
                        android:cacheColorHint="@color/white"/>

Now if you scroll the list for a while, particularly if you sort of wiggle it up and down quickly and then let it go the list will be completely covered by a solid block of the colour specified in the childDivider property. This will remain for a few seconds and then disappear.

To fix this issue just remove the childDivider property setting

 

Phone number code puzzle November 4, 2011

Filed under: Coding,Scala — Rupert Bates @ 1:53 pm

Once upon a time I was presented with the following test in an interview:

Given a mapping of digits to an array of characters, ie.
"1"={},
"2"={"A","B","C"},
"3"={"D","E","F"},

etc.

Print out all the string permutations a given input of digits maps to.
So for instance the string “23” should return:
AD
AE
AF
BD
BE
BF
CD
CE
CF

Another way to think of this is a function that returns all the possible combinations of letters the digits could represent if they were keypresses on a standard phone keypad.

I did a pretty bad job at this when I was asked it, partly because it was quite late at night, and partly because it’s not the sort of thing you find yourself doing that often, but today I found myself with a little bit of spare time on my hands and thought I’d give it another go.

I chose to do it in Scala rather than in Java which I had used last time and of course this led to the solution being much more elegant and succinct. If fact this is exactly the sort of problem that demonstrates the value of functional programming.

import collection.immutable.{List, Map}
import java.lang.String

object PhoneNumbers extends App {
  val input = "1234"
  val data = Map(
    0 -> List("0"),
    1 -> List("1"),
    2 -> List("a", "b", "c"),
    3 -> List("d", "e", "f"),
    4 -> List("g", "h", "i"),
    5 -> List("j", "k", "l"),
    6 -> List("m", "n", "o"),
    7 -> List("p", "q", "r", "s"),
    8 -> List("t", "u", "v"),
    9 -> List("w", "x", "y", "z")
  )
  getCombinations(input.substring(0, 1), input.substring(1))
    .foreach(f => Console.println(f))

  def getCombinations(current: String, remaining: String): List[String] = {
    val vals = data(Integer.parseInt(current));
    if (remaining.length() == 0)
      return vals

    val restOfString = getCombinations(remaining.substring(0, 1), remaining.substring(1))

    vals
      .map(f => restOfString.map(f2 => f + f2))
      .flatten
  }
}

 

Speaking at JAX London 2011 October 1, 2011

Filed under: Android,guardian.co.uk,Java — Rupert Bates @ 5:15 pm

I am going to be giving a talk about the development of the recently released Guardian app for Android at the Jax 2011 conference.
The session is on the 2nd of November, more details here

 

Guardian App On Android V 1.0 September 7, 2011

Filed under: Android,guardian.co.uk — Rupert Bates @ 2:58 pm

Finally! The project I’ve been working on for the last 5 months goes live…
https://market.android.com/details?id=com.guardian
And:
http://www.guardian.co.uk/help/insideguardian/2011/sep/07/guardian-android-app

 

Generate a changelog for the current branch in Git September 2, 2011

Filed under: Git — Rupert Bates @ 3:04 pm

I find it useful to be able to quickly generate a list of all changes in the current branch which have not yet been merged into master. It’s a good way to come up with a change list when doing a release for instance. To do this in git you can use the following:

git log master.. --pretty="%s"

This assumes that you are on a branch which is off master (if you are on master you could use the path ..my-branch) and that the changes have not yet been merged into master, and it will give you a list showing only the commit messages, ready for copying and pasting into that release note.

 

Speed up Google apps account login with Empathy chat client in Ubuntu August 3, 2011

Filed under: Linux — Rupert Bates @ 10:25 am
Tags:

When I first set up the Empathy chat client to connect to my Google apps account it took a ridiculous amount of time to load the contacts, usually over 10 minutes, and this was every time I logged in.

By changing the settings on the account though I got it to work pretty much instantaneously.

Settings:

Login ID: your email address
Password: your password

Under advanced settings:

Check ‘Encryption Required’ checkbox
Resource: Home
Server: talk.google.com
Port: 5223
Check ‘Use old SSL’ checkbox

 

 
Follow

Get every new post delivered to your Inbox.