Category Archives: Coding

Compiling / playing nethack 3.6.0 on Ubuntu or Debian

UPDATE: Instructions added for enabling the hilite_status feature to get nice coloured Hitpoint & Hunger highlighting

After a 10+ year hiatus, the NetHack DevTeam is happy to announce the release of NetHack 3.6, a combination of the old and the new.

- nethack 3.6.0 release notes

It took me a while to figure out how to actually get nethack v3.6.0 running on Ubuntu, so I’ve shared what I learned for others.

Thanks to Jochen, we can also get this compiling on Debian Jessie.

Get setup

  • Install the dependencies
    • sudo apt-get install flex bison build-essential libncurses5-dev checkinstall
  • Get the source
  • Extract the source
    • tar xpvzf nethack-360-src.tgz

Prepare the source

  • Edit include/unixconf.h
    • Change /* #define LINUX */ to #define LINUX
  • Edit sys/unix/hints/linux to be as here.
    • For Debian Jessie, change the HACKDIR=... line to be HACKDIR=$(PREFIX)/lib/games/$(GAME)dir
  • If you want to enable Status Hilite’s;
    • Edit include/config.h
    • Change /* #define STATUS_VIA_WINDOWPORT */ to #define STATUS_VIA_WINDOWPORT
    • Change /* #define STATUS_HILITES */ to #define STATUS_HILITES
  • sh ./sys/unix/setup.sh sys/unix/hints/linux (sets up the Makefiles correctly)

Build & install

  • make all
  • sudo checkinstall (will create a package and install it for you)
    • Hit y to create default docs
    • Enter nethack 3.6.0 then hit <Enter> twice when prompted
    • At the options screen, change option 12 to say nethack-common. This avoids accidentally installing any old version from your package manager.
    • Hit <Enter> to continue
    • If you see an error “Some of the files created by the installation are inside the home directory“;
    1. Hit n (it’s just a temporary file), then
    2. Hit y to continue (we do not want those files in our package).

Uninstallation

To uninstall, use your favourite package manager, or sudo dpkg -r nethack.

Play!

Now you can run the game via nethack.

Need some help getting starting with nethack? Read the v3.6.0 guidebook.

Tagged , , , ,

IE7’s CSS breaking “content: counter” bug

I came across a peculiar bug today while testing theiconic.com.au in IE7;

#foo:before {
    content: counter(item, ".") ": ";
}

Completely breaks IE7’s CSS parser for the current .css file.

The fix, as explained in pragmar’s answer on SO, is to add a space after ‘item’. This is not the most optimal fix, and has the potential to break when minifying.

The fix is to remove the space between the comma and the open quote. This is also safe for minification:

#foo:before {
    /* Note removing the space after ',' fixes IE7's CSS parser */
    content: counter(item,".") ": ";
}

This only occurs when using a quoted counter list-style-type. Using ‘open-quote’, ‘close-quote’, etc, does not exhibit the bug.

Check out the example below for a practical demonstration across browsers.

Example: IE7’s CSS breaking content counter bug.

ie7-content-bug

Happy Coding!

Tagged , , ,

The Visitor Pattern in PHP

Implementing the Visitor Pattern requires the ability to dynamically determine the type of the Visitor and the type of the “Element” (aka: object receiving the visitor).

In PHP (>= 5.0.0), this can easily be achieved with the get_class() function as we will see shortly.

Let’s start by looking at how the Visitor Pattern will look within user code;

$updateVisitor = new UpdateVisitor();
$deleteVisitor = new DeleteVisitor();
$element = new Foo();

$element->visit($updateVisitor);
$element->visit($deleteVisitor);

Looking at the UpdateVisitor class, we want the visitFoo() function to be called;

interface Visitor { }
class UpdateVisitor implements Visitor {
    public function visitFoo(Foo $theElement) {
        // ...
    }
}

You may already be (correctly) thinking “Why not just call $updateVisitor->visitFoo($element) directly?”.
Continue reading

Tagged , , ,

Inserting a function into all classes in a directory via Terminal

Or; Multi-line Search and Replace regular expression on the Command Line.

The situation

You have a single abstract class which is extended multiple times in 10 or 100 different classes throughout your codebase.

You’ve found a need for a new abstract method which all classes must now implement.

The problem

Who wants to manually insert that new code into all those classes!? (I don’t).

We need an automated way to do this
Continue reading

Tagged , , , , , , ,

Zend Framework Quickstart with MySQL

The Zend Framework Quickstart guide is a great place to start with the Framework, however it bases the example program on SQLite. As MySQL is the choice of the rest of the world (and even Zend’s own Stack installation), here is the Zend Framework Quickstart done with MySQL.

Continue reading

Tagged , , ,