Thursday, December 6, 2012

TypeMatrix keyboard bindings for Mac OS

I want to reverse the usual mapping of Alt and Start; Alt should map to Option and Start to should map to Command. But I only want to do this for my external keyboard.

Go to System Preferences and look at the Keyboard settings. Click the Modifier Keys button. Then choose USB Keyboard and reverse the Command and Option mappings.

Via Stack Overflow.

Monday, December 3, 2012

Chrome check before quitting

It's surprisingly hard to find out how to stop Chrome on Mac from closing all its windows and tabs automatically if you accidentally press ⌘Q.

The answer is… there's a menu option in the Chrome menu called Warn Before Quitting. Select it and you'll need to hold down ⌘Q to quit.

Tuesday, November 27, 2012

Akka in Eclipse on Mac OS

These are my rough notes for getting Akka HEAD going in Eclipse with the Scala plugin. I used a nightly build of the plugin to get support for a recent version of Scala.

  1. Fork the Akka repository.
  2. Make a local clone of your fork.
    git clone akka
  3. Build it and run tests.
    $ sbt test
  4. Create an ~/.sbt/plugins/plugins.sbt file to teach SBT about the sbteclipse plugin.
    addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
  5. Generate Eclipse project metadata.
    $ sbt eclipse
  6. Download Eclipse Indigo SR2 and install it somewhere. Do not run it yet.
  7. Find the Eclipse application and view its contents by right-clicking and choosing Show package contents.
  8. Update Contents/MacOS/eclipse.ini according to these instructions. OK, I used a bit more memory. My changes were:
    $ diff -u Eclipse\ 
    --- 2012-11-26 13:48:13.000000000 +0100
    +++ Eclipse 2012-11-26 14:00:45.000000000 +0100
    @@ -16,9 +16,11 @@
  9. I have a high-res (Retina) screen on my Mac so I enabled high-resolution fonts for the Eclipse application according to these instructions. Update Contents/MacOS/eclipse.ini according to these instructions. If you've already started the application then your changes might not be picked up because of OS caching. Read the linked instructions for a workaround. My changes were:
    $ diff -u Eclipse\ 
    --- 2012-11-26 13:34:45.000000000 +0100
    +++ Eclipse 2012-11-27 11:40:36.000000000 +0100
    @@ -69,9 +69,6 @@
    - <key>NSHighResolutionCapable</key>
    - <true/>
  10. Open Eclipse.
  11. Tell Eclipse how to get the 2.10.x nightly build of the Scala plugin. Go to Help and choose Install New Software…. The update site is located at There are also milestone builds available.
  12. Go to General and Workspace and set the Text file encoding to UTF-8. Otherwise you'll get funny errors when Scala tries to compile the ⇒ characters in Akka source code.
  13. Use Import Existing Projects into Workspace… to pull in the Akka source code.
  14. Done!

Update: Explained how to add Scala plugin. Oops!

Saturday, November 10, 2012

Minimal Akka Hello World with SBT

  1. Create a directory for our project files.
  2. Create helloworld.scala in the project directory.
    import akka.pattern.ask
    import akka.util.duration._
    import akka.util.Timeout
    case class Print(s: String)
    case object PrintAck
    class Printer extends Actor {
      def receive = {
        case Print(s) => {
          sender ! PrintAck
    object HelloWorld {
      def main(args: Array[String]) {
        val system = ActorSystem("HelloWorld")
        val printer = system.actorOf(Props[Printer])
        implicit val timeout = Timeout(5 seconds)
        (printer ? Print("Hello world")) onComplete {
          _ => system.shutdown()
  3. Create build.sbt in the project directory.
    name := "Akka Hello World"
    version := "1.0"
    scalaVersion := "2.9.2"
    resolvers += "Typesafe Repository" at ""
    libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.3"
  4. Download the latest SBT launch JAR and install it somewhere. This JAR bootstraps SBT and builds the project. I downloaded the 0.12.1 version. You can get the location of the latest version from the SBT Manual Installation instructions on the SBT website.
  5. Go to your project directory and run SBT. The following has the recommended VM options for running on Windows. Replace XXX with your SBT installation location.
    $ java -Xmx512M -jar XXX/sbt-launch-0.12.1.jar
    [info] Set current project to Akka Hello World (...)
  6. Run the program!
    > run
    [info] Running HelloWorld
    Hello world
    [success] Total time: 6 s, completed 11/11/2012 11:02:21 AM

See also:

Friday, August 17, 2012

Installing Rust 0.3 in Ubuntu 12.04 (Precise Pangolin)

I installed Rust with only a slight wrinkle; I decided to use GNU Stow so I could easily remove the installed files later. That should make it easier to upgrade to the next version of Rust when it's released.

sudo apt-get install g++ curl stow
cd ~/tmp
tar xzf rust-0.3.tar.gz
cd rust-0.3
./configure --prefix=/usr/local/stow/rust-0.3
make -j2
sudo make install
sudo stow -d /usr/local/stow rust-0.3

Extra info

Wednesday, August 15, 2012

Single-key shortcut for copy and paste in Windows

Too much copying (Control+C) and pasting (Control+V) hurts my fingers. Recently I downloaded a macro program to give me a single-key alternative for each. I used F3 and F4 for my new shortcuts. I made the shortcuts available in all applications except Eclipse. I disabled my shortcuts for Eclipse so that I could use its existing bindings.

  1. Install AutoHotkey.
  2. Create and edit a new script.
  3. Use the following code:
    #IfWinNotActive, ahk_class SWT_Window0
    F3::Send ^c
    F4::Send ^v
  4. Run the script.

Sunday, August 5, 2012

Review Board error with Subversion diff

Review Board 1.6.6 chokes on some diffs generated by Subversion 1.7.4. The error given is:

The file 'https://path-to-file-in-repo' could not be found in the repository

The problem seems to be with files that have been copied from elsewhere in the repository and then modified. Subversion generates a diff to show the changes to the file. Unfortunately Review Board doesn't realise the diff is taken against a file in a different location.

The diff is generated with the svn diff and produces a header like this:

Index: path/to/file
--- path/to/file (working copy)
+++ path/to/file (working copy)

The solution is to tell Subversion to pretend the file is newly added by using the --show-copies-as-adds option. With this option a different header is produced:

Index: path/to/file
--- path/to/file (revision 0)
+++ path/to/file (working copy)

Review Board accepts diffs created with this option without any problems. A downside is that some of the file history is missing for the reviewer.

Note: I didn't try using the post-review tool, which I think is the recommended way to generate diffs for Review Board.

Thursday, July 26, 2012

Showing whitespace in Eclipse

I use these settings to highlight undesirable whitespace in my code. By undesirable I mean tabs (when I use spaces for indentation) and any trailing whitespace.

  1. Open Preferences.
  2. Go to General > Editors > Text Editors.
  3. Check the Show whitespace characters checkbox.
  4. Click the whitespace characters link.
  5. Use the following settings.
  6. Click OK to save the whitespace settings.
  7. Click OK to save the preferences.

Wednesday, July 4, 2012

Stopping Windows' console beep

Since installing Gow I've been able to once again enjoy bash's tab completion. Unfortunately bash likes to beep whenever there's a completion choice to be made…

Console beeping can be disabled by turning off the Windows beep service with:

net beep stop

Via Stack Overflow.

Monday, July 2, 2012

Python setuptools bootstrap errors

I ran into some errors installing py-dom-path 0.1 into my Win32 Python 2.7 installation. Here are the errors and their resolution.

The installation command I used was:

C:\...\python.exe C:\...\py-dom-xpath-0.1\ install


First, running in a corporate environment, the bootstrap script failed to access the network to download setuptools.

I needed to set an environment variable with the HTTP proxy details.

set HTTP_PROXY=user:pass@host:port

Old version of bootstrap script

The bootstrap script included in py-dom-path 0.1 is out of date. It referenced an old version of setuptools that was no longer available:

urllib2.HTTPError: HTTP Error 404: Not Found

I downloaded the latest version of the bootstrap script, placed it in the source directory and ran the installation again, this time with no problems.

Tuesday, June 26, 2012

Using TortoiseMerge for command line Subversion merging

  1. Create a batch file called svn_tortoisemerge.bat with the following content.
    "c:\Program Files\TortoiseSVN\bin\TortoiseMerge.exe" /base:"%1" /theirs:"%2" /mine:"%3" /merged:"%4"
  2. Set the SVN_MERGE environment variable to point to the file.
    set SVN_MERGE=c:\...\svn_tortoisemerge.bat
  3. When merging conflicts use l to launch the editor and r to mark a conflict as resolved.
    Conflict discovered in 'C:/.../somefile'.
    Select: (p) postpone, (df) diff-full, (e) edit,
            (mc) mine-conflict, (tc) theirs-conflict,
            (s) show all options:

Via Stack Overflow.

Saturday, June 16, 2012

Cleaning up Word's HTML

I still need to find an HTML editor that produces clean HTML in the style I like. In the meantime I write blog posts directly in HTML or, for longer posts, I compose in another program and then convert to HTML.

Word produces horrible HTML but here's a trick to tidy it up. Turns out CKEditor has a Paste from Word button especially for this purpose! Just go to the demo page and paste your work, then extract the HTML by clicking Source. The HTML still needs a little cleaning to reach my exacting standards but it's pretty close!

Via Stack Overflow.

Monday, June 4, 2012

Selecting Maven modules to build

On a multimodule Maven project you can speed up builds by only building the modules that have changed. Use the --projects option to list the modules you want to build.

mvn --projects aaa,bbb,ccc install

And if you're in a real hurry you can tack on -Dmaven.test.skip to avoid running any tests.

mvn --projects aaa,bbb,ccc install -Dmaven.test.skip

Sunday, May 27, 2012

Backing up Gmail

  1. Generate an application-specific password for your Google account. (You are using 2-step verification, right?)
  2. Use BaGoMa to run a backup.
    python -e <email address> -d ~/Backup/Gmail/<email address>
  3. Set SpiderOak* to back up the ~/Backup directory.
  4. Relax.

TODO: Run BaGoMa on a schedule.

* Referral link - you get 1GB free, I get 1GB free.

Friday, May 25, 2012

Quick Python web server on localhost

Python's SimpleHTTPServer is great for serving files from a directory without the hassle of setting us a proper web server.

$ python -m SimpleHTTPServer

But by default it listens on all network interfaces. If you only want to listen on localhost then you'll need to write a short script.

import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

SimpleHTTPRequestHandler.protocol_version = "HTTP/1.0"
httpd = BaseHTTPServer.HTTPServer(('', 8000), SimpleHTTPRequestHandler)

Adapted from an article at Linux Journal.

Wednesday, May 23, 2012

Using Notepad++ to edit Subversion commit messages

You can set the Subversion editor with the SVN_EDITOR environment variable. Unfortunately, if you have other documents open, Notepad++ will edit your commit message in the existing process. The new process launched by Subversion will exit immediately, leading Subversion to complain:

Log message unchanged or not specified
(a)bort, (c)ontinue, (e)dit:

The trick is to open Notepad++ in a new process with the -multiInst option.

set SVN_EDITOR="c:\Progra~1\NotePad++\notepad++ -multiInst"

Once that option is provided everything works correctly.

Via SVNForum.

Wednesday, May 9, 2012

Where to buy PC components in NZ

After searching around I found this helpful thread at GP Forums. The thread gives ratings for the reliability and service of each retailer. The ratings are updated regularly. Top retailers at the time of posting are Computer Lounge, Ascent, Mighty Ape and Paradigm PCs.

A couple of comments from me:

  • I'll have to check out Mighty Ape for online purchases in NZ. They sell a lot of other stuff too: books, board games. I noticed they also list other sellers' prices on there site, a very Amazon move.
  • I have a long history with Ascent. Most of it is great, although their reputation has recently been somewhat tarnished for me. Their policy seems to be to dispute any return made after the manufacturer's warranty is over. This goes against the rights granted by NZ's Consumer Guarantees Act. Under the Act consumers can expect their purchases to last for a reasonable time, no matter what the warranty says! However I suspect CGA disputes are not unusual among computer retailers—Dell sounds particularly bad! On balance I think Ascent are probably still one of the better ones out there. I was just disappointed after 10 years of great experiences. In the end they did give me a refund.

Thursday, May 3, 2012

Accidental Git commit

I've realised my last post helps when you commit the wrong files or the wrong message, but still want to commit. Sometimes (or quite often for me) you accidentally commit when you're not ready. In that case what you really want is…

git reset --soft HEAD~1

Via Stack Overflow.

Wednesday, April 25, 2012

Saturday, April 14, 2012

Drools Planner for open source employee rostering

While investigating automated employee scheduling for a friend I found it hard to locate a framework to use. There is a lot of information in the academic literature about rostering algorithms and also there are quite a few commercial solutions, but it was hard to find something I could use right away.

Eventually I came across Drools Planner and I was quickly able to come up with a working prototype. Drools Planner comes with some solid search algorithms, currently tabu search and simulated annealing.

The Drools rules engine is used for calculating the "score" of a particular solution. Drools has an advantage over a hand-coded scoring algorithm; it is able to calculate a score delta based on only the parts of the solution that have changed.

There are a lot of great examples to get you started. Check out the video of nurse rostering for a quick overview.

Scala Maven repositories

I noticed that latest Scala releases have moved away from scala-tools and now live in the main Maven repo. This message confirms the current Scala artifact locations.

Thursday, April 5, 2012

Exception breakpoints in Chrome

Chrome does not seem to have traditional exception breakpoints, however it is possible to break on all uncaught exceptions by clicking the Pause on exceptions button in the bottom left until it turns purple: .

More information can be found on the Chrome website.

Via Stack Overflow.

Tuesday, April 3, 2012

Luadns for personal DNS hosting

I've found another candidate for my personal DNS hosting: Luadns. I like the use of a programming language (Lua) for configuration. Configuration is pulled from a Git repository; private repositories are supported too.

Via Hacker News.

Thursday, March 29, 2012

Headphones for Toshiba Satellite L640 in Ubuntu Natty

By default in Ubuntu Natty the built-in speakers keep playing even when headphones are plugged in. Adding the following to /etc/modprobe.d/alsa-base.conf fixes the problem for me.

options snd-hda-intel model=thinkpad

Via Ubuntu Forums.

Wednesday, March 28, 2012

ATI Radeon GPU power management in Ubuntu Natty

Update: Some YouTube videos don't work on the mid setting for me, high seems to be needed. More investigation required!

OK, CPU scaling wasn't the reason for my laptop's excess heat and fan noise after all. The problem was with the GPU.

A forum post outlines how to scale down the GPU to reduce power, heat and fan noise (found via a comment in a Launchpad bug report). Worked for me with the mid power setting.

$ sudo -i
# echo dynpm > /sys/class/drm/card0/device/power_method
# echo profile > /sys/class/drm/card0/device/power_method
# echo mid > /sys/class/drm/card0/device/power_profile 

After applying this change there was a marked decrease in fan noise. The GPU temperature has clearly come down.


$ sensors
Adapter: PCI adapter
temp1:       +66.5°C


$ sensors
Adapter: PCI adapter
temp1:       +56.5°C 

Scaling CPU in Ubuntu Natty

When I use my laptop in Ubuntu Natty I notice extra heat from the CPU. It seems like Windows is being more agressive at slowing the CPU down to save power. Unfortunately, the Power Management control in Natty doesn't mention CPU speed at all.

There is (or was?) an option for controlling the CPU in the Power Management control. But I wasn't able to get it to work.

Instead I installed the cpufreq indicator:

$ sudo add-apt-repository ppa:artfwo/ppa
$ sudo apt-get update
$ sudo apt-get install indicator-cpufreq
$ indicator-cpufreq&

Sunday, March 25, 2012

Scala in gedit

The standard distribution of gedit doesn't understand Scala source. Here's how to add it.

  1. Create ~/.local/share/mime/packages/scala-mime.xml with the following content:
    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns=''>
    <mime-type type="text/x-scala">
    <comment>Scala programming language</comment>
    <glob pattern="*.scala"/>
  2. Register the new MIME information and check that the registration has been successful.
    $ update-mime-database ~/.local/share/mime
    $ gnomevfs-info myfile.scala | grep MIME
    MIME type         : text/x-scala
  3. Add the Scala syntax highlighting information.
    mkdir -p ~/.gnome2/gtksourceview-1.0/language-specs/
    wget -P ~/.gnome2/gtksourceview-1.0/language-specs/
  4. Enjoy your highlighted source!
    $ gedit myfile.scala

This post is based on information from Shashank Tiwari and from the GNOME Desktop System Administration Guide.

Saturday, March 17, 2012

Personal DNS hosting

As part of my slow migration away from GoDaddy I have a few personal domains that I want to arrange hosting for. After a bit of investigation I finally found what looks like a nice DNS hosting provider: Zonomi. As a bonus they also seem to be affiliated with Rimuhosting, who I've had good experiences with in the past!

I looked at some of the free DNS providers out there and after having a few difficulties with each of them decided I'd prefer to pay a bit of money for something nicer—but not too much!

Free DNS hosts I looked at:

Paid DNS hosts:

And, finally, an old but relevant Hacker News thread!

Monday, March 12, 2012

Toshiba Satellite L640 battery in Ubuntu Linux

A vanilla installation of Ubuntu Natty (11.04) doesn't show a battery indicator for my Toshiba Satellite L640 PSK0LA-05X00T. No battery is detected.

The problem seems to be in the process of being fixed, but in the meantime there is a workaround. The instructions below are a blend of those taken from posts by Faheem and Michael Kuron. Thanks!

  1. Extract the current DSDT.

    $ sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat
  2. Decompile it.

    $ sudo apt-get install iasl
    $ iasl -d dsdt.dat
  3. Patch the source, as described here.

    $ sed -i 's/OperationRegion (EMEM, SystemMemory, 0xFF808001, 0xFF)/OperationRegion (EMEM, EmbeddedControl, 0x00, 0xFF)/g' dsdt.dsl
  4. Recompile the modified source.

    $ iasl -tc dsdt.dsl
  5. Configure GRUB to use the modified DSDT.

    $ sudo cp dsdt.aml /boot/
    $ sudo nano /etc/grub.d/01_acpi
    #! /bin/sh -e
    # Uncomment to load custom ACPI table
    . ${libdir}/grub/grub-mkconfig_lib
    # Load custom ACPI table
    if [ x${GRUB_CUSTOM_ACPI} != x ] && [ -f ${GRUB_CUSTOM_ACPI} ] \
            && is_path_readable_by_grub ${GRUB_CUSTOM_ACPI}; then
        echo "Found custom ACPI table: ${GRUB_CUSTOM_ACPI}" >&2
        prepare_grub_to_access_device `${grub_probe} --target=device ${GRUB_CUSTOM_ACPI}` | sed -e "s/^/  /"
        cat << EOF
    acpi (\$root)`make_system_path_relative_to_its_root ${GRUB_CUSTOM_ACPI}`
    $ sudo chmod +x /etc/grub.d/01_acpi
    $ sudo update-grub2
    Found custom ACPI table: /boot/dsdt.aml
  6. Reboot and enjoy proper battery support.

Monday, January 16, 2012

LaserJet 1022n driver in Windows 7 64-bit

Some good tips can be found here. Using a LaserJet 6L driver seemed to work for printing a test page.