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.