Monday, December 12, 2011

Downloading Eve Online files overnight

  1. Disable sleep in Power Management preferences.

  2. Go to downloads directory.

    $ cd ~/Downloads
  3. Set commands to run at midnight. Files are taken Eve Online's offline installer download page.

    $ at midnight
    warning: commands will be executed using /bin/sh
    at> wget -c
    at> wget -c
    at> wget -c
    at> ^D<EOT>
    job 6 at Tue Dec 13 00:00:00 2011
  4. Go to bed!

  5. Re-enable sleep in Power Management preferences.

Note: Ideally would sleep when complete, but doing so probably requires some work with sudo.

Wednesday, December 7, 2011

Branching and unbranching in Git

I wanted to create a temporary branch for a piece of work.

# Make some changes...

# Oops, need a new branch!
git branch mybranch
git checkout mybranch
git commit

# Make and commit more changes...

# Send branch changes to remote repo.
git push origin mybranch

# All done, time to merge back.
git checkout master
git pull --rebase origin master
git merge mybranch
git commit -a
git push origin

# Remove branch locally and on remote repo.
git branch -d mybranch
git push origin :mybranch

Wednesday, November 16, 2011

Maven and Eclipse for Scala 2.9

These instructions were tested with the following versions.

  • Maven 3.0.3
  • Scala 2.9.1
  • Eclipse 3.6.2 (Helios SR2)
  • Sun's Java 1.6.0_26
  • Ubuntu 11.04 (Natty Narwhal)
  1. Download Maven and install in ~/opt/apache-maven-3.0.3.
  2. Create a Maven project with the Scala archetype.
    $ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn archetype:generate -Dfilter=org.scala-tools.archetypes:scala-archetype-simple
  3. Test compilation.
    $ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn install
  4. Update the POM to compile with Scala 2.9.1 rather than Scala 2.8.
    diff --git a/pom.xml b/pom.xml
    index 6522932..417619d 100644
    --- a/pom.xml
    +++ b/pom.xml
    @@ -18,7 +18,7 @@
    -    <scala.version>2.8.0</scala.version>
    +    <scala.version>2.9.1</scala.version>
    @@ -55,13 +55,13 @@
    -      <version>1.6.5</version>
    +      <version>1.6.9</version>
    -      <artifactId>scalatest</artifactId>
    -      <version>1.2</version>
    +      <artifactId>scalatest_${scala.version}</artifactId>
    +      <version>1.6.1</version>
  5. Test compilation with Scala 2.9.
    $ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn install
  6. Update the POM to include Scala configuration for Maven's Eclipse plugin.
    diff --git a/pom.xml b/pom.xml
    index 7b17d81..ea26d11 100644
    --- a/pom.xml
    +++ b/pom.xml
    @@ -110,6 +110,35 @@
    +      <plugin>
    +        <groupId>org.apache.maven.plugins</groupId>
    +        <artifactId>maven-eclipse-plugin</artifactId>
    +        <version>2.8</version>
    +        <!-- see for more information -->
    +        <configuration>
    +          <downloadSources>true</downloadSources>
    +          <downloadJavadocs>true</downloadJavadocs>
    +          <projectnatures>
    +            <projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
    +            <projectnature>org.eclipse.jdt.core.javanature</projectnature>
    +          </projectnatures>
    +          <buildcommands>
    +            <buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
    +          </buildcommands>
    +          <classpathContainers>
    +            <classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER"</classpathContainer>
    +            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
    +          </classpathContainers>
    +          <excludes>
    +            <exclude>org.scala-lang:scala-library</exclude>
    +            <exclude>org.scala-lang:scala-compiler</exclude>
    +          </excludes>
    +          <sourceIncludes>
    +            <sourceInclude>**/*.scala</sourceInclude>
    +            <sourceInclude>**/*.java</sourceInclude>
    +          </sourceIncludes>
    +        </configuration>
    +      </plugin>
  7. Create Eclipse metadata for the project.
    $ JAVA_HOME=/usr/lib/jvm/java-6-sun ~/opt/apache-maven-3.0.3/bin/mvn eclipse:eclipse
  8. Download Eclipse 3.6.2 (Helios SR2) and install in ~/opt/eclipse-helios-SR2.
  9. Start Eclipse.
    $ ~/opt/eclipse-helios-SR2/eclipse&
  10. Add the Scala 2.9 update site to Eclipse.
  11. Install Scala plugins from the update site:
    • Scala IDE for Eclipse
    • Scala IDE for Eclipse Source Feature
    • JDT Weaving
  12. Restart Eclipse to apply the new plugins.
  13. Add a classpath variable for M2_REPO and set to ~/.m2/repository.
  14. Import the project.
  15. Everything should compile and run correctly.

Useful pages:

Monday, October 31, 2011

Killing hung SSH session

Press in sequence: enter, tilde (~) and period (.).

More information:

Wednesday, October 26, 2011

VPS providers

I've been in the market for a small VPS recently and unfortunately missed this post on Hacker News. The post and its discussion contain lots of interesting information that Google searching doesn't reveal. I guess VPS providers have done a lot of SEO, making searching difficult. The gem of the post is a link to lowendbox, a site that links to cheap VPS providers. The forums look active too.

Tuesday, October 18, 2011

PostgreSQL and Django in Ubuntu Natty

I wanted to create to test my Django 1.3 application using PostgreSQL. I'd previously being using SQLite.

I used a very simple, but not very secure setup—making my user account into a database superuser and then using ident authentication to control access. The goal is minimal hassle, not security.

I'm running Ubuntu Natty which comes with PostgreSQL 8.4.

  1. Install PostgreSQL and its Python adapter.
    sudo apt-get install postgresql python-psycopg2
  2. Make your development user into a PostgreSQL superuser. This will allow you (and Django) to create databases. Substitute your username for <user>.
    sudo -u postgres createuser --superuser <user>
  3. Create a database for your Django project. Substitute your Django database name for <database>.
    /usr/lib/postgresql/8.4/bin/createdb <database>
  4. Edit your Django file to use your new PostgreSQL database and to use ident authentication as your current user.
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': '<database>',
            'USER': '<user>'
  5. Test your connection. Substitute <projectname> for your Django project name.
    python <projectname>/ sql

Monday, October 17, 2011

Simple Shorewall config on Ubuntu server

Here are the steps I used to configure a simple Shorewall firewall on Ubuntu Lucid (10.04). The firewall provides SSH and webserver access only; all other ports are blocked.

  1. Install the Shorewall firewall. Version 4.4.x was available on Lucid at the time of writing.
    sudo apt-get install shorewall
  2. Backup the original configuration, just in case.
    sudo cp -p /etc/shorewall/shorewall.conf /etc/shorewall/shorewall.conf.orig
  3. Copy the provided configuration for a single-interface machine.
    sudo cp -p /usr/share/doc/shorewall/examples/one-interface/* /etc/shorewall/
  4. Add rules to allow SSH and web access.
    sudo nano /etc/shorewall/rules
    SSH(ACCEPT)     net             $FW
    Web(ACCEPT)     net             $FW
  5. Edit Shorewall config to allow the firewall to start.
    sudo nano /etc/shorewall/shorewall.conf
  6. Edit Ubuntu's Shorewall config to allow the firewall to start.
    sudo nano /etc/default/shorewall
    startup = 1
  7. Start the firewall.
    sudo /etc/init.d/shorewall start
  8. Observe the new rules.
    sudo /sbin/iptables -L

More information:

Printing sorted contact lists in ThunderBird

ThunderBird doesn't provide many options for printing contact lists. To get more flexibility you need to export data into a CSV file and then print from within a spreadsheet program.

There's a handy program called... MoreFunctionsForAddressBook that lets you do this.

The plugin isn't part of ThunderBird's add-on site so you will need to download the XPI file and manually install it. The file is at the very bottom of the main add-on page. To install the add-on into ThunderBird you will first need to go to the add-ons window. Then, if you can find the little cog icon next to the search box, you can choose an option to install an add-on from a file.

Friday, October 14, 2011

Scheduling a late night distro download

Be nice to the internet and download off-peak!

$ at midnight
warning: commands will be executed using /bin/sh
at> wget -c
at> ^D
job 1 at Sat Oct 15 00:00:00 2011

Tuesday, October 11, 2011

Internet Explorer 7 in Ubuntu Natty

I installed IE7 in Natty so I could do some cross-browser testing. I use PlayOnLinux to automate the installation under Wine. PlayOnLinux supports several Windows browsers. Alternatively I could have run Windows in a virtual machine.

  1. Download and install PlayOnLinux.
    $ wget -q "" -O- | sudo apt-key add -
    $ sudo wget -O /etc/apt/sources.list.d/playonlinux.list
    $ sudo apt-get update
    $ sudo apt-get install playonlinux
  2. Run PlayOnLinux.
    $ playonlinux&
  3. Click the Install button.
  4. Choose Internet Explorer 7 from the Internet section.
  5. Click the Apply button.
  6. Follow the installation instructions.
    • If asked, do not download updates for the malicious software removal tool.
    • I chose to "restart later".
  7. Internet Explorer 7 is now available as an application that can be clicked on and run within PlayOnLinux.

Saturday, October 8, 2011

Syncing with a remote repo in Git

My latest workflow...

  1. Check for local changes.
    $ git status
  2. Commit or stash them. Rebase won't work with local changes.
    $ git stash save 'local env settings'
  3. Pull down remote changes and rebase my changes off them.
    $ git pull --rebase
  4. Get my local changes back.
    $ git stash pop
  5. Test that everything still works!
  6. Push changes back to the remote repo.
    $ git push origin

Update: Changed stash apply to stash pop, to avoid creating an infinite number of stashes.

Wednesday, September 28, 2011

Undo last commit in Git

From Josh's answer on StackOverflow:

git commit --amend

The git commit manual says that --amend, unlike some of the other StackOverflow answers, can be used to amend merge commits.

Fixing merge conflicts in Git

From CoolAJ86's answer on StackOverflow:
git checkout --ours filename.c
git checkout --theirs filename.c
git add filename.c
git commit -m "using theirs"

Tuesday, September 27, 2011

Minecraft server and IPv6

I was having trouble starting a Minecraft server in Ubuntu Natty. I could connect locally, but my friend couldn't connect over the internet.

I used the standard command to start the server.

$ java -Xmx1024M -Xms1024M \
-jar minecraft_server.jar nogui

I noticed that the server was listening on an IPv6 address. My local network and internet connection is IPv4-only, so my friend would obviously be unable to connect.

$ netstat -an | grep 25565
tcp6  0  0  :::25565  :::*  LISTEN

The solution was to pass a property to Java telling it to bind to an IPv4 address.

$ java -Xmx1024M -Xms1024M \
-jar minecraft_server.jar nogui

With that option the server will listen on an IPv4 address.

$ netstat -an | grep 25565
tcp  0  0*  LISTEN

Friday, September 23, 2011

Fixing commit authors in Git

I accidentally committed changes with incorrect author information. Brenda Wallace has posted instructions for how rewrite Git's history with new author names.

$ git filter-branch --commit-filter '
        if [ "$GIT_COMMITTER_NAME" = "oldname" ];
                GIT_COMMITTER_NAME="Firstname Lastname";
                GIT_AUTHOR_NAME="Firstname Lastname";
                git commit-tree "$@";
                git commit-tree "$@";
        fi' HEAD

I also fixed my future commits with the following commands, taken from GitHub's instructions.

$ git config --global "Firstname Lastname"
$ git config --global ""

Getting git diff of about-to-be-committed changes

I always like to go over the changes I'm committing before I actually commit them. In other version control systems (CVS, Subversion, Mercurial), running cmd diff will show you what you're about to commit. Not so with Git! You need an extra option.

$ git diff --cached

Tuesday, June 28, 2011

Binary diff in Mercurial

To do this you can use the extdiff extension with the vbindiff program (available in Ubuntu).

Edit your Mercurial config (~/.hgrc) to include the following lines:

extdiff =

cmd.bdiff = vbindiff

Now you can get a diff of a binary file with the following command:

$ hg bdiff <filename>

Thursday, June 23, 2011

Installing Windows 7 from a USB stick

I needed to install Windows 7 on an old laptop that struggled with booting from a DVD.

I found a nice tool to do this automatically: WUDT. It has a longer name, but I like the abbreviation better. :)

It formatted the USB drive so I used a fresh one for the purpose. It might be possible to disable the formatting in some cases with a registry setting.

Booting worked fine. I haven't tested the actual installation yet as I want to preserve the hard drive until I'm sure all data has been recovered.