Emacs on Mac OS X

carbon-emacs-iconAt work I use a Linux work station a lot, and one of the things I really enjoy is that when I use Emacs from the command line, it opens up the graphical user interface. This, of course, is not the behavior on OS X. Additionally, the version that ships with Mac OS X is woefully out of date (version 22.1.1 at the time of writing).

I decided to do something about it, and grabbed an up-to-date build of Emacs from emacsformacosx.com. By default, it gets installed in /Applications, which will work just fine. It provides a graphical version of Emacs with support for normal Mac OS X short cuts, like command-c, etc.

But, Michael, how does this solve the problem of the Emacs from the command line being out of date? Well, Inside the application bundle is the Emacs executable that can be run from the command line, sans GUI. All you have to do is create an alias with this code (in my case, I made a bash script that resides in my ~/.bin named ’emacs’) with the following code:

    [ -z "$SSH_CONNECTION" ]
    /Applications/Emacs.app/Contents/MacOS/Emacs "$@"
    /Applications/Emacs.app/Contents/MacOS/Emacs -nw "$@"

This makes it so that if the terminal detects that you are running over an SSH (non-graphical) connection, it will run the non-windowed version of Emacs, otherwise it will launch the graphical version. It works just like it does in most Linux distros, and is a real pleasure to use!

Shipping Containers


The other day I was stuck in some traffic while out on a trip with my brother and dad. The freeway was moving at about 5 MPH due to an accident, and we were behind a semi-truck towing a shipping container. Naturally, with nothing better to do, we looked up shipping container information online to find out how much they cost, size, weight, etc. and ran across the ISO 6346 specification for the serial numbers found on shipping containers.

The serial number found on shipping containers follow a strict format. The first 3 characters are the owner code, and are only letters. The 4th digit is the category identifier, which at this moment the only category is “U” for freight container. The remaining 6 characters are the serial number which will only be comprised of digits. After the 10 character serial number, there is a check digit, usually shown as a number in a box to the right.


The check digit is calculated by taking each character of the serial number, and assigning a value to the character and multiplying that value by 2 to the power of its location. Digits retain their face value, 0-9, while letters are given an incrementing value starting at 10, with the exception of multiples of 11 which are skipped (a=10, b=12, c=13, d=14… z=38). All of these values are then added together, divided by 11, truncated to an integer, multiplied by 11, and then subtracted from the original total. This is basically a fancy way of saying take the modulus 11 of the total.

We passed the remainder of our time in the traffic by verifying by hand that all the shipping container check numbers were calculated correctly. When I got home, I wrote this Python program to calculate it for me the next time I may ever need to generate or check a shipping container check digit. It asks for input, then uses a regular expression to validate the format. It then calculates and returns the check digit.

import re
ShippingNumber = raw_input("Enter Container Code (eg. PSSU210948): ")
if not re.compile('\D{4}\d{6}').match(ShippingNumber):
    print "Invalid, please ensure code follows ISO 6346 specifications."
for i in range(len(ShippingNumber)):
    if not Value.isdigit():
print "Check Digit:", str(Total%11%10)

Mountain Lion, Upgrading, and Fusion Drive

This week, I finally embarked on the upgrade to Mountain Lion from the venerable Snow Leopard that has been serving me faithfully for many years. The feature that pushed me over the edge of upgrading was Fusion Drive.

I have had both an SSD and HDD on my machine for a while, and love the benefits of the faster SSD. However, managing the symlinks to different bits of data back and forth between the two disks was annoying, and not as finely tuned as as I would prefer. The nice thing about Apple’s Fusion Drive method is that the OS automatically moves things where it makes most sense for them to be. System files, and more often accessed files migrate themselves to the faster SSD.

Troubles Installing on a MacPro(3,1)

Mac Pro

There have been many people who have made instructions for how to enable Fusion Drive on older machines. Mine is a 2008 MacPro (3,1). There happened to be a problem that many owners of this MacPro encountered when trying to install Mountain Lion. Each time I tried, I found my USB bus was dead upon booting to the installer. No, the machine wasn’t frozen, but without the Mouse and Keyboard, it was impossible to proceed with the installation. Fortunately, after some searching, I found this thread that culminated in the revelation that the people who were affected were those using an 802.11G wireless card which apparently is NOT compatible with Mountain Lion. After removing the card, I was able to use my keyboard and mouse, and proceed with the installation!

Enabling FusionDrive via CoreStorage/diskutil

To enable Fusion Drive, it takes a couple simple command in the terminal. I followed the example of Patrick Stein found here.

First, I listed the disks on my system in order to see their identifiers (disk0, disk1…). This is done with the following command:

diskutil list

Next, I created the “CoreStorage” logical volume. This is done with the following command:

diskutil cs create <NameOfNewDisk> disk0 disk1

Here, you would replace <NameOfNewDisk> with whatever name you wish to give the volume, and then identify the proper disks by index.

This process will result in a unique identifier for the new volume such as, “C3EF49E5-C10F-4379-B74E-EFD8810C1272.” Next, I used this number to create a partition on the drive. The command looks like the following:

diskutil coreStorage createVolume C3EF49E5-C10F-4379-B74E-EFD8810C1272 jhfs+ <NameOfNewVolume> <SizeOfNewVolume>

Of course, you will replace the large number with the identifier of your CoreStorage volume, and the <NameOfNewVolume> with the name you wish it to have, and <SizeOfNewVolume> with the size of the total drive. For me, this was 1123g.

After using that last command, the drive showed up on the desktop and was ready to use. I then proceeded with the Mountain Lion install. Everything worked like a charm!

© 2007-2015 Michael Caldwell