header

Torsten Curdt’s weblog

Proper sleep for the MacBook Pro

Ever wondered why suspending on your new shiny MacBook Pro is taking so much longer and seems a bit more flaky than on your old Powerbook? Have a look what hibernation mode you are running in:

pmset -g | grep hibernatemode

Obviously Apple changed the default hibernation mode from 0 to 3 which also writes the content of the memory to disk.

sudo pmset -a hibernatemode 0

If you change from 3 (or 7) back to 0 you are back in wonderland. You can then also free some disk space and remove the image. If you switch back it will be re-created.

sudo rm /var/vm/sleepimage

For more in-depth information see this article.

Restoring package selections

I have to say I just love apt-get way of package management. Especially that you can just save the list of packages you have installed

dpkg --get-selections > pakete.log

and with just a few commands bring your system (or another machine) to the same state again.

dpkg --set-selections < pakete.log
dselect update
dselect install

Also note that it might be useful to copy your /etc/apt/sources.list

Compiling aacgain on OSX

There is a nifty tool out there to adjust your mp3/aac collection to a similar volume …without any re-compression or data loss. Cool! But if you have ever tried to compile aacgain1.5 on OSX (Intel) yourself you will notice that the compilation of libfaad fails.

In file included from /usr/include/math.h:28,
                from common.h:341,
                from bits.c:28:
/usr/include/architecture/i386/math.h:378: error: conflicting types for 'lrintf'
common.h:308: error: previous definition of 'lrintf' was here

This could probably be fixed by some configure magic or checking for OSX in the header file. As a quick fix I’ve just commented it out.

--- aacgain-1.5/faad2/libfaad/common.h  2004-09-08 11:43:12.000000000 +0200
+++ aacgain-1.5.fixed/faad2/libfaad/common.h    2006-10-20 01:01:30.000000000 +0200
@@ -302,6 +302,7 @@
         return i;
     }
   #elif (defined(__i386__) && defined(__GNUC__))
+/*
     #define HAS_LRINTF
     // from http://www.stereopsis.com/FPU.html
     static INLINE int lrintf(float f)
@@ -314,6 +315,7 @@
             : "m" (f));
         return i;
     }
+*/
   #endif

Would be really nice to make this package available through fink.

Binding JMX on a dedicated address

Unfortunately in order to get JMX to bind to dedicated address (and not just 0.0.0.0) you have to jump through a few hoops. In order to save you some time – here is how you do it. Create your own RMISocketFactory that only creates server sockets on the specified address

public class RMIServerSocketFactoryImpl implements RMIServerSocketFactory {

    private final InetAddress localAddress;

    public RMIServerSocketFactoryImpl( final InetAddress pAddress ) {
        localAddress = pAddress;
    }

    public ServerSocket createServerSocket(final int pPort) throws IOException  {
        return ServerSocketFactory.getDefault()
            .createServerSocket(pPort, 0, localAddress);
    }

    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }

        return obj.getClass().equals(getClass());
    }

    public int hashCode() {
        return RMIServerSocketFactoryImpl.class.hashCode();
    }
}

Then create the naming service with that factory and create the RMI server using that naming service.

RMIServerSocketFactory serverFactory = new RMIServerSocketFactoryImpl(InetAddress.getByName(address));

LocateRegistry.createRegistry(namingPort, null, serverFactory);

StringBuffer url = new StringBuffer();
url.append("service:jmx:");
url.append("rmi://").append(address).append(':').append(protocolPort).append("/jndi/");
url.append("rmi://").append(address).append(':').append(namingPort).append("/connector");

Map env = new HashMap();
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverFactory);

rmiServer = new RMIConnectorServer(
   new JMXServiceURL(url.toString()),
   env,
   ManagementFactory.getPlatformMBeanServer()
   );

rmiServer.start();

Why do some so simple things need to be so overly complicated?

Umlaute in Terminal.app

Although I am using an english OS and now have an English keyboard I do want my German umlauts to be properly displayed …and I also want to be able to input them and not get some weird number sequences. Terminal by default uses UTF-8 for output. For having the proper input encoding you need to provide a few environment variables (e.g. in your .profile) and then you are set.

export LC_ALL=en_US.UTF-8
export LC_CTYPE=UTF-8
export LANG=en_US