Parallels Share Ubuntu Filesystem with Mac Lion

I would like the ability to write the code on my host computer (Mac) and run them on my virtual machine (ubuntu 11).  Parallels does not come with a built in way to share ubuntu folders with your Mac like it does for Windows.  Using sshfs and openssh-server you can still accomplish it.

First make sure you can log into your virtual machine using ssh and your public/private keys.

1) Install openssh-server on the ubuntu VM

sudo apt-get install openssh-server

2) Make sure you can ssh into your vm

ssh user@address

3) Generate ssh key pair.  I assume you use the default rsa keys.  If you already have keys, you can skip this step.

ssh-keygen

3) Add your ~/.ssh/id_rsa.pub to your authorized_keys

scp ~/.ssh/id_rsa.pub jason@10.211.55.5:id_rsa.pub
ssh jason@10.211.55.5
mkdir ~/.ssh
chmod 700 ~/.ssh
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

4) You should now be able to login to your VM without supplying your password

ssh jason@10.211.55.5

5) Install sshfs on your mac.  I like to use Homebrew to install my open source software.  You need to install fuse and sshfs.  If you’ve previously installed MacFus, or OS Fuse, you need to uninstall it for this doc.  You can probably get it to work, but this guide won’t tell you how!

brew install fuse4x sshfs

6) Now you should be able to connect to the filesystem of ubuntu.  This creates “/Volume/ubuntu” folder that you can open from finder, or terminal, or textmate!

# mount
mkdir /Volumes/ubuntu
sshfs jason@10.211.55.5:/home/jason/ /Volumes/ubuntu -oauto_cache,reconnect,defer_permissions,negative_vncache,volname=somename

# unmount
umount /Volumes/linux

 

Sometimes your VM will change it’s ip address.  If it does, you may need to clear out your ~/.ssh/known_hosts file.  It’s ok to just wipe everything out because it’s simply a cache of the keys of the servers you’ve accessed.

Thanks to Philipp Klaus for the sshfs info

Thanks to ubuntu docs for the openssh-server info.

Native looking Mac apps using Python & wxPython

So, I went down the road of using wxRuby, but it seems that it is a dead or dying code base. Seems most Ruby-ists are interested in Rails, not in desktop applications. I also failed in my attempt at packaging up a ruby desktop app to make it appear native. I kept running into 64bit vs 32bit issues.

Anyway, after quite a few months break from my project, I decided it made more sense to develop my blenderfarmers render farm client application using Python. Blender itself uses Python to perform all it’s scripting tasks. This would guarantee that Python is installed on every computer that is running Blender.

Turns out, it doesn’t even matter if python is on the target machine because built into Python is the ability to bake the python application into an executable. Ruby has this ability too, but I just never could get it working. In one hour, I was able to create a shell wxPython window and “freeze” it to a native Mac package that behaves just like a native app. Beautiful!

I know this is Mac centric, I need to test on Windows too, but my experience is it is harder to get working on my Mac, than my Windows virtual machine.

Great page that helped:  Optimizing for Mac OS X

command line

One of the things that I love the most about my Mac is the command line.  I know the Mac is well known for it’s beautiful user interface, but that doesn’t stop at the graphical user interface.  It extends to the command line user interface as well.  One of the advantages of being based on unix is that all the command line power that is available on unix is also available on the Mac.  I know microsoft has recently upgraded their command line abilities but they can’t really compete with decades of knowledge on command line usage on unix.  There were many times that I felt a little helpless on my windows box when I wanted to do something cool.  I felt helpless because a lot of the stuff I was interested was for unix only.  I do not usually experience that on my Mac.  The unix environment is just more naturally geared for the free software world.

Compiling wxruby on Snow Leopard

I am trying to compile wxruby on Snow Leopard.  I am running into issues because wxwidgets 2.8 which wxruby 2.0.1 is based upon only compiles in 32bit mode.  I can compile wxwidgets 2.8.11 using 32 bit mode.  When I try to compile wxruby, I get errors.  I’m not quite sure what I need to do to resolve this yet.  Once (If) I do, I’ll update this post.

compile wxMac

# Download, compile, install the 2.8.11 version of wxMac
mkdir osx-build
cd osx-build
arch_flags="-arch i386"
../configure  CFLAGS="$arch_flags" CXXFLAGS="$arch_flags" CPPFLAGS="$arch_flags" LDFLAGS="$arch_flags" OBJCFLAGS="$arch_flags" OBJCXXFLAGS="$arch_flags" --enable-universal_binary --with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk --with-macosx-version-min=10.4 --disable-shared --enable-unicode --enable-static --disable-debug --enable-catch_segvs --enable-graphics_ctx --enable-mediactrl --with-opengl --with-libjpeg=builtin --with-libpng=builtin --with-libtiff=builtin --with-expat=builtin --enable-gui --enable-xrc --enable-mdi --enable-gif --enable-pcx --enable-iff --enable-pnm --enable-xpm --with-macosx-sdk=/Developer/SDKs/MacOSX10.6.sdk --with-macosx-version-min=10.6
make
sudo make install

compile SWIG

# Download, compile, install SWIG 1.3.38
cd /usr/local/swig-1.3.38
sudo ./configure --disable-ccache #--disable-ccache is because I do not have yodl2man installed
sudo make
sudo make install

compile wxruby

# Downloaded the trunk versin of wxRuby
svn checkout svn://rubyforge.org/var/svn/wxruby
cd wxruby/trunk
rake

Error!

# ---------------- ERROR
I get the following error:
lipo: can't figure out the architecture type of: /var/folders/pI/pIyyNf1MGiaa6DODFaul2U+++TI/-Tmp-//ccmdge2D.out
lipo: can't open input file: /var/folders/pI/pIyyNf1MGiaa6DODFaul2U+++TI/-Tmp-//ccsraXTA.out (No such file or directory)
rake aborted!
Command failed with status (1): [g++ -c  -I/usr/local/lib/wx/include/mac-un...]

Mac Application Bundle

So, I packaged up my native looking Mac application in my own Application Bundle.  It was super simple to do.

An application bundle is nothing more than a folder that has been renamed with the extension “.app” and conforms to a certain directory structure.  The directory structure looks like this:

/Contents/
/Contents/Info.plist
/Contents/MacOS/
/Contents/Resources/
/Contents/youricon.icns

The important piece is Info.plist.  It tells the system what to call your bundle and where the executable is located.

<plist version="1.0">
<dict>
  <key>CFBundleExecutable</key>
  <string>test.rb</string>
  <key>CFBundleGetInfoString</key>
  <string>Test</string>
  <key>CFBundleIconFile</key>
  <string>test.icns</string>
  <key>CFBundleIdentifier</key>
  <string>test</string>
  <key>CFBundleName</key>
  <string>Test Name</string>
</dict>
</plist>

Your application should go in MacOS.  I put my ruby script in the MacOS directory and it could not longer load my resources that were right next to it in that directory.  If I hard code the path to be an absolute path based on where the app is bundled (/Users/jasonxrowland/myapp.app/Contents/MacOS) it works.  I have a feeling, I need to call a Mac specific API to get the resource bundle path.  I’ll figure that out later…

I created the icon using the Icon Composer application included with the Mac.

Native Looking Mac App with Ruby

Ruby is really popular to make websites because of Rails, but I want to write a native looking application using Ruby.  I’ve discovered wxruby which is a really cool cross platform GUI library for use with Ruby.  It is built on wxWidgets which is a C++ library for making cross platform GUIs that appear native because they are built on the underlying native libraries of each platform (linux, OSX, and Windows).  Right now, I’m interested in Mac, but I plan on testing this on Windows and Linux too.

Installation

wxWidgets

You have to download the source and compile it yourself for Snow Leopard.  This means, you need to install the developer toolset that comes with your Snow Leopard DVD.  Just install everything, hard drives are cheap.  I don’t know if you have to actually run “./configure”, “make” or not.  My guess is you don’t, but I did.  Snow Leopard has some special challenges and you have to do the following:

$ set arch_flags="-arch x86_64"
$ ./configure CFLAGS="$arch_flags" CXXFLAGS="$arch_flags" CPPFLAGS="$arch_flags" LDFLAGS="$arch_flags" OBJCFLAGS="$arch_flags" OBJCXXFLAGS="$arch_flags"
$ make

DialogBlocks

After you download, Open the DMG image and copy the contents to wherever you want.  I copied mine to /Developer/Applications.  When you run this for the first time, it asks you to select the location of wxWidgets.

wxruby

The latest stable version is 2.0.1.  If you try to install wxruby through gems, it will install 1.9.3.  I don’t know what’s different between the two, but 2.0.1 is a year old so I want to use it.

wx_sugar

$ gem install wx_sugar

Ruby

You should already have a version of Ruby installed.  I list it here because the latest version as I write this is 1.9.2.  Unfortunately, one of the tools we will use to generate ruby classes does not support 1.9.2.  If you really want to use 1.9.2, you can follow the directions here.  I haven’t tried it so I don’t know if it will work or not.  I just switched to mine to the system version “rvm  –default system”

Making a simple app

There is a great tutorial on the wxruby website.  It shows you how all these tools work together to create an application. I created my frame using DialogBlocks.  I created my ruby file using xrcise.  I completed the tutorial.  Now if you forget that wxruby is 32bit only and you just try to run the app, you may see an error like this:

/Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wxruby2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wxruby2.bundle, 9): no suitable image found.  Did find: (LoadError)
/Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wxruby2.bundle: no matching architecture in universal wrapper - /Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wxruby2.bundle
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wx.rb:12
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `require'
from main.rb:3

To run the app, you need to run ruby in 32 bit mode like this:

env arch -i386 ruby -rubygems main.rb

Here is the screen shot of my app running on a mac.

Taking screen shots with Mac OSX

I seem to always forget these short cuts even though i use them frequently. With windows, it is simply “print screen” button to capture the desktop and alt-”print screen” to capture the active window.  This puts the image in the clip board.

The apple commands for capturing the screen aren’t as intuitive as the Windows version.

To capture the desktop, Command-Shift-3

To capture a portion of the screen, Command-Shift-4.

To capture a specific windows, Command-Shift-4 followed by space bar.

The Mac version will create PNG files on the desktop with these commands.  If you hold down the control key while pressing these combinations, it will put the image in the clipboard.

Simulating a slow network on a Mac

I ran across these very handy commands to simulate a connection of only 4kbps.  This is helpful when developing mobile applications in particular because some cell connections are horrible.

sudo ipfw pipe 1 config bw 4KByte/s
sudo ipfw add 100 pipe 1 tcp from any to me 3000

There are several interesting parts to these commands.

The 4KByte/s which can be whatever speed you want.  This is the bandwidth, measured in [K|M]{bit/s|Byte/s}.

The other interesting part is 3000.  This is the port that will be slowed.  Port 3000 is the default port on which Ruby on Rails listens.  If you are doing Java, you would probably want to use 8080.

The 100 is the rule number.  Useful when it comes time to delete this rule.

To clear out this pipe, simply type the following when finished:

sudo ipfw delete 100

To clear all custom rules, you could type:

sudo ipfw flush

Change your Terminal prompt on Mac

I hate the default prompt for the Terminal in Mac.  It usually takes up most of my terminal screen real estate.  It shows me my computer name, my current directory, and who the logged in user is.  I never need to know my computer name.  I rarely need to know who the username is.  If I did “whoami” will tell me.  I do like to see my current directory though.

create/edit the .profile file.  Add the following:

export PS1="W$"

Source it by typing

. .profile

This will create a prompt with the current directory followed by the $.  Yay.