Check If A Certificate & Private Key Match

Check if an SSL certificate and private key match in two simple commands. The OpenSSL commands below will require you to replace <file> with your file’s name.

For your SSL certificate:1

openssl x509 -noout -modulus -in <file> | md5sum

For your RSA private key:

openssl rsa -noout -modulus -in <file> | md5sum

The output of these commands should be identical. If it isn’t, your keys do not match.

  1. The pipe to md5sum is solely to make the output shorter and easier to visually compare

Improving mvim for MacVim

MacVim comes with a clever script called mvim which allows you to open files in MacVim via the command line (much like mate for TextMate). This is a wonderful tool, but does possess some idiosyncrasies. It creates a new window (rather than a new tab) when you invoke it and it also won’t take stdin as input unless you pass a dash1.

To fix this I modified the script to check for an existing macvim process, and if it exists attach tabs to it.2 Additionally, it checks for args and if none are present (or just -) the script invokes stdin. I am not much of a bash hacker though, so there are a few caveats…

  • –remote-tab-silent doesn’t seem to work with listening on stdin, so the script always pops it out into a new window.
  • You (apparently) can’t pass extra parameters when using –remote-tab-silent, so tricks like mvim /etc/hosts +5 to have it open with the cursor on line 5 will not work.

These are both irritating, but I feel the advantages outweigh the disadvantages. Hopefully someone can contribute fixes to these problems!

#!/bin/sh
#
# This shell script passes all its arguments to the binary inside the
# MacVim.app application bundle.  If you make links to this script as view,
# gvim, etc., then it will peek at the name used to call it and set options
# appropriately.
#
# Based on a script by Wout Mertens and suggestions from Laurent Bihanic.  This
# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
# Weber and Bjorn Winckler, Aug 13 2007.  Some mediocre hacking by Paul Kehrer Sep 30 2009).
# First, check "All the Usual Suspects" for the location of the Vim.app bundle.
# You can short-circuit this by setting the VIM_APP_DIR environment variable
# or by un-commenting and editing the following line:
# VIM_APP_DIR=/Applications
 
if [ -z "$VIM_APP_DIR" ]
then
	myDir="`dirname "$0"`"
	myAppDir="$myDir/../Applications"
	for i in ~/Applications ~/Applications/vim $myDir $myDir/vim $myAppDir $myAppDir/vim /Applications /Applications/vim /Applications/Utilities /Applications/Utilities/vim; do
		if [ -x "$i/MacVim.app" ]; then
			VIM_APP_DIR="$i"
			break
		fi
	done
fi
if [ -z "$VIM_APP_DIR" ]
then
	echo "Sorry, cannot find MacVim.app.  Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
	exit 1
fi
binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"
 
# Next, peek at the name used to invoke this script, and set options
# accordingly.
 
name="`basename "$0"`"
gui=
opts=
 
# GUI mode, implies forking
case "$name" in m*|g*|rg*) gui=true ;; esac
 
# Restricted mode
case "$name" in r*) opts="$opts -Z";; esac
 
# vimdiff and view
case "$name" in
	*vimdiff)
		opts="$opts -dO"
		;;
	*view)
		opts="$opts -R"
		;;
esac
 
tabs=true
stdinoption=false
 
#let's see if we need to read from stdin
#script currently assumes NO PARAMETERS
if [ -z "$1" ] || [[ $1 == \- ]]; then
	stdinoption=true
fi
 
# Last step:  fire up vim.
# The program should fork by default when started in GUI mode, but it does
# not; we work around this when this script is invoked as "gvim" or "rgview"
# etc., but not when it is invoked as "vim -g".
if [ "$gui" ]; then
	# Note: this isn't perfect, because any error output goes to the
	# terminal instead of the console log.
	# But if you use open instead, you will need to fully qualify the
	# path names for any filenames you specify, which is hard.
	if $stdinoption; then
		exec "$binary" -g - 
	else 
		if $tabs && [ `ps x|grep 'MacOS/MacVim'|grep -v grep|wc -l` = "1" ] && [[ `$binary --serverlist` = "VIM" ]]; then
			#when using remote tabs you can't pass things like +5.
			exec "$binary" -g $opts --remote-tab-silent ${1:+"$@"}
		else
			exec "$binary" -g $opts ${1:+"$@"} 
		fi
	fi
else
	exec "$binary" $opts ${1:+"$@"}
fi
  1. This is the standard vim way, but feels irritatingly inelegant to me.
  2. The script does a ps x to check for the existence of a macvim process. This is done before the serverlist check because the script will output ugly errors to stdout if there is no macvim process.

NTFS-3G 64-bit PrefPane For Snow Leopard

Update: A version of NTFS-3G with native 64-bit PrefPane support has been released. The instructions below have been left for archival purposes, but are no longer required.

I use NTFS-3G + MacFUSE to write to NTFS disks on occasion, but I hate restarting System Preferences just to run a 32-bit PrefPane when I want to view/change some settings. Behold the power of open source!

To compile a 64-bit System Preferences compatible version of this item simply

  1. Grab the source for the NTFS-3G PrefPane
  2. Right click and get info on the build target to add x86_64, turn on Objective-C garbage collection to “supported”1
  3. Build the target.

…and you’re all set. You can download my copy, but I don’t recommend using it in 10.5 or 10.4. Of course, you don’t need a 64-bit PrefPane prior to 10.6 so why would you download it anyway?

  1. If you set it to supported it should work in OS X 10.5 still

CDN Tools Status Update

I apologize to everyone who has been inquiring about when CDN Tools will be updated to add WP 2.8 compatibility. I have been very busy lately and haven’t found the time to get the issues resolved. However, I am still planning to update it so don’t lose hope. In the meantime here are instructions to get CDN Tools working with 2.8 with only one issue that I’m aware of:

  1. Click remove files. This will delete all JS and attachments from your CDN.
  2. Turn on advanced mode and click “load attachments”1

Once you’ve completed these two steps the admin pages should be working properly and your attachments should be loading from the CDN again. Side loading is also functional, although please be aware that deleting items does not work. If you remove an attachment you will need to go to your CDN and manually remove it.

  1. If you click the normal “load files” CDN Tools will attempt to load both attachments and javascript. The javascript load causes numerous issues in WP 2.8 with the admin pages.

Photos on Prairie Home Companion

prairie_homeI have been informed that one of my photos was featured on the Prairie Home Companion website and mailing list today. Pretty cool! It’s an HDR I took in Pullman, WA with my XTi a few years ago. If you’re interested, take a look at the original and poke around at some of my more recent photos. I’ve also got a set of my favorites.

Update: A permanent link to the Prairie Home episode.

Changing OS X Short Name

When my work laptop was originally set up the short name was set to “paul kehrer”. This space tends to cause issues with poorly written applications, especially on the command line, so I set out to change it. Prior to Leopard this was a difficult task best accomplished with ChangeShortName, but with Leopard you can now do it without any third party utilities.

advancedoptionsFirst you’ll need to create a secondary admin account and log into that. While you can directly change the short name of an account you are logged into, I wouldn’t recommend it. Next, open system preferences, go to accounts, and right click the user you want to change. You’ll see a single menu item called “advanced options…”.

useroptionsChoosing that will bring up a sheet that lets you change your user ID, group ID, short name, logins hell, home directory path, UUID, and add/remove aliases (other login names) for your account. While these are all very powerful tools we’re only going to use short name and home directory this time. In general it is safest to keep your short name and home directory path synchronized to avoid any issues that might arise from poorly written apps, but it is not required to change both. If you do change the home dir, then be aware that you’ll also need to run this command from the terminal to complete your account switch.

sudo mv /Users/oldshortname /Users/newshortname

Once you’ve done this you can log back in to the other account and you’re all set. Be aware that some apps do use hard coded paths for preferences, so you’ll probably have a few small issues to correct as you get up to speed.