17 February 2012

Yak Shaving to Install Git Via MacPorts on OS X Lion



Today I needed to set up a new MacBook Pro and as such one of the tasks was to install git on OS X Lion. Being that I am a fan of MacPorts, I decided to start there but I ran into some strange errors. Unfortunately I wound up doing a lot of yak shaving.

The last time I installed MacPorts fresh, it was on a previous MacBook Pro that had OS X Snow Leopard installed. I successfully installed MacPorts and then used the port utility to install git without issue. Later I then updated to OS X Lion and had no issues with git or Xcode.

So from previous experience, I knew that before I could install MacPorts I would need to install Xcode, so I downloaded and installed Xcode 4.3 from the App Store. Then I attempted to install MacPorts, but began seeing errors about not being able to find the make utility. Sure enough, it was not in /usr/bin. After some hunting, I ran across a document titled New Features in Xcode 4.3 which noted the following:
'The command-line tools are not bundled with Xcode 4.3 by default. Instead, they can be installed optionally using the Components tab of the Downloads preferences panel...'

So I installed the command-line tools from the Xcode preferences panel and then proceeded with the MacPorts installation. It completed successfully so I moved on to the actual installation of git using the following command:
$ sudo port install git-core +bash_completion +doc +svn
Unfortunately this wound up with an error stating:
Error: Failed to install zlib
Hunting around, I wound up finding a few things such as this MacPorts issue, only to discover that this issue was closed as invalid. So I hunted some more and found this question on Stack Overflow which had one hint but not everything to fix the situation. I also found some advice in a document about Migrating a MacPorts install to a new major OS version or CPU architecture.
  1. Install the Xcode command-line tools from the Xcode preferences panel
  2. Update the /opt/local/etc/macports/macports.conf file to change from 'developer_dir /Developer' to just 'developer_dir'
  3. Clean all ports using sudo port clean all (this took a while)
  4. Now run the following steps:


$ sudo ln -s / /Developer
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs /SDKs
$ sudo xcode-select -switch /Applications/Xcode.app
$ sudo port install git-core +bash_completion +doc +svn

After stumbling upon and utilizing these steps, I completed my yak shaving session and finally got git installed successfully. This cost me a total of about two hours. Here's a great Ren and Stimpy video about yak shaving. Now I'm on to another weird problem with this new laptop, a couple of System Preferences are dimmed and I can't figure out why. Anybody know what may be causing this?

11 February 2012

How To Avoid Another Knee Surgery

On 1 February, 2012, I was scheduled to have knee surgery, but at the last minute I decided to cancel the surgery in favor of a more advanced treatment that requires no surgery. Here's a brief story to describe why I chose this route.

All of my knee problems began when I was in high school. I was a pole vaulter on the track team and during an early spring season track meet while warming up I landed wrong and experienced a medial collateral ligament (MCL) tear as shown in the image to the right. Prior to this injury, I never had any knee problems so this injury was a very big surprise. There was no surgery required for the injury, just immobilization. So after eight weeks in a brace from my hip to my ankle that utilized progressive motion during the last four weeks, my doctor at the time took my crutches and told me good luck. I was just a kid and completely inexperienced with knee injuries to know any better. Little did I know that this lack of proper rehabilitation would affect me for the rest of my life.

The following fall, I made the high school soccer team again and played soccer wearing a big knee brace. Because of the brace, people would come after me on the field to take me out and so I experience a number of sprains and strains throughout the season. But the very last game we played that year I twisted my knee badly and heard a loud pop. When my knee ballooned up in a matter of minutes to the point that I could barely bend it, I knew I had a bad injury. The result was an anterior cruciate ligament (ACL) tear. The image to the right shows an ACL tear, note that mine was a total tear and not a partial tear. Although I did extensive physical therapy, I wound up needing reconstructive surgery a few months later. At the time, this involved a large incision down the center of the knee so that a chunk of the patellar tendon to form a new ACL that was grafted to the femur and tibia by drilling new tunnels and using a chunk of the patella. At the time, it was pretty extensive surgery and damn painful. Essentially stealing from one area of the knee to fix another area of the knee.

After nearly five months on crutches and one month with a cane, I was already into some rigorous physical therapy involving cycling, swimming and weight resistance/training. In that time, I also discovered that literally the week after I had surgery, the doctors began doing a new type of ACL reconstruction. This new type of surgery was/is known as anthroscopy and requires only very small incisions making it much less invasive than the style of surgery that I had and, as a result, required much less recovery and rehabilitative time.

Through all the reading and research around knees that I have done since my first injury, I have also discovered that the immobility was the real downside to the old style of knee surgery. It left patients (including me) with a significant amount of atrophy or muscle deterioration. To this day, I have visible atrophy of the muscles in my right leg where all of my knee problems have occurred and it all comes back to the immobilization techniques used in my recovery.

Over the last 24 years since the ACL reconstruction, I have experienced zero knee problems. But in December of 2011, while playing indoor soccer, I experienced a knee injury and I new right away that something tore. A month later, I found out that I experienced two meniscal tears (one medial, one lateral) as well as a possible partial tear of the ACL -- what?! Yes, the one that I had reconstructed so many years before. Through my own research, the lack of swelling and the type and location of pain, I had already guessed that I had torn my meniscus, so that was not a surprise. But I was very surprised by the news that there is a partial tear in the ACL. But the doctors did tell me that they couldn't tell for sure if this tear occurred at the same time. The image to the right shows the meniscus and my tears are located near the rear of each meniscus.

So I decided to have surgery for the meniscal tears and during the surgery the doctor would determine if the ACL needed to be replaced. There were two options for the ACL reconstruction -- use part of my hamstring or use donated tissue from a cadaver. After researching both options, I decided I didn't want to steal from another part of my leg to mend my knee again, so opted for the donated tissue. My surgery would have been an anthroscopy which is good because it requires less recovery and physical therapy resulting in much less down time than I had when I was a teenager. As I researched and read about folks who had had meniscal tears fixed via the same surgery, I found many folks who had success with the surgery but I also found a surprising number of stories from people who said that their knees were worse off after such surgery. And they attributed these to a variety of issues including shaving the meniscus, stitching the meniscus and, in some cases, removal of part of the meniscus. For those who are not aware, the meniscus is a spongy, low blood flow tissue that pads the area in the knee where the femur meets the tibia. Injuries to this area can often cause arthritis over time and removal of any of the meniscus means less padding there. This is why you see folks who have had a bad experience with meniscal repair who walk so gingerly, especially up and down stairs. Given all of this, I didn't think that I had any alternatives, so I scheduled the surgery with the goal of being able to cycle this summer.

Only days before the surgery, my friend and neighbor informed me about an alternative to knee surgery called Regennex. Last year my neighbor had a persistent hamstring injury treated with a similar procedure known as Platelet Rich Plasma (PRP). PRP is a similar injection therapy for acute injuries that only uses the platelets from your own blood to promote healing. She experienced a full recovery to an injury that had been recurring for years. Needless to say, she is a fan. Regarding the Regennex treatment, she knows a woman who had the procedure last year and now is doing wonderful now. In fact, her case was even televised recently (see the video here: http://www.youtube.com/embed/DQ_H0yGLQh0?autoplay=0&). Being that the clinic where this procedure is being conducted is only a few miles from where I live, I decided to see if I could schedule an evaluation ASAP with the goal of avoiding surgery. A couple days later I was evaluated and found out that I was a candidate for this new procedure. Being that my first ACL reconstruction was essentially using the tail end of surgical techniques at the time, I didn't want to be in the same boat this time. I wanted to be on the cutting edge and to avoid surgery if possible. Also, knowing that I can have this new procedure more than once if necessary and that I can always opt for surgery at a later time if it truly becomes necessary, I decided not to have the surgery at this time in lieu of this new procedure.



I am currently undergoing the Regennex Stem Cell Plasma procedure. This procedure involves a series of treatments where they draw blood from my arm to get the platelets out of it and they take bone marrow aspirate from my hip to get the stem cells out out it. Then they combine these two compounds and inject it into the damaged areas of my knee to encourage it to grow new tissue and essentially heal itself. My hope is to experience minimal down time (I will only need to avoid cycling for a few days) and continue being active. For more information about the procedure, check out Orthopedics 2.0 - How Regenerative Medicine will Create the Next Generation of Less Invasive Orthopedics.

The one activity that I have begrudgingly decided to sit out on is soccer. I have always loved soccer and I still love soccer, but two of my three major knee injuries occurred playing soccer. As difficult as it will be to watch my wife and friends and kids still play soccer, I have decided it would be best not to play competitively anymore. I will continue to cycle, hike, run, swim and do nearly everything I love to do, just not competitive soccer.

Stay tuned and I will let you know how things turn out as I complete the rest of the Regennex procedure.

04 January 2012

How To Add An Existing Git Project to Eclipse



Here's another quick set of notes for myself for posterity. I always clone and build a project on the command line before I import it into the IDE to begin hacking code. Right now I have to handle a hairy merge so I need a visual tool to make things a bit easier. For this purpose, I want to make Eclipse git aware so that I can use the visual diff in the IDE. Hopefully these notes will help out someone else, too.

For this situation I'm dealing with a Java project that uses git. First some quick items to set the stage:

  • IDE:For Java development, my IDE of choice is the SpringSource Tool Suite (STS). If you develop Spring-based Java apps and you like Eclipse, you should really be using STS.
  • SCM: The majority of projects I have worked with over the last few years use git for SCM. It is vastly superior to any other SCM tools I've used and documentation abounds for it, but it is a bit like a razor blade.
  • IDE+SCM: The standard git tool for Eclipse is EGit


To make the Eclipse project git aware, follow these steps:

  1. Go to Window->Show View->Other
  2. In the filter field, enter the word git
  3. Select Git Repositories and click OK
  4. Click on the icon whose tooltip reads 'Add an existing local Git Repository to this view'
  5. Click on the browse button and navigate to the directory that contains the project source code
  6. Click the Search button
  7. Click OK
  8. Right-click on the project in the Package Explorer
  9. Go to Team->Share Project
  10. Select Git and click Next
  11. Check the box for 'Use or create Repository in parent folder of project - this should automatically find the .git directories
  12. Click Finish and let EGit complete the integration


After following these steps, the projects should be connected to their git repository. This allows you to handle the vast majority of git commands right from inside the IDE.

For more info about EGit, check out the EGit User Guide.

02 January 2012

Developing Apps for Mac OS X With Objective-C and Cocoa



Even though I've used Macs for over 20 years now, I have never developed a native app for the Mac OS. So over the holiday break, I finally spent some time getting ramped up on Objective-C to develop apps for Mac OS X and IOS. This meant reading a lot about Objective-C, XCode and Cocoa.

I'm primarily a Java developer these days but I'm familiar with writing C code (though I haven't written it in many years) so this knowledge helped me quite a bit. The syntax for Objective-C was a bit strange at first but I got the hang of it after a bit and I'm continuing to learn. I managed to develop a command line app and a GUI app using XCode. Building the command line app was much more understandable for me because you are writing all the code by hand. Constructing the GUI app was a rather nebulous task mainly because you rely upon the IDE to handle many things for you. XCode is the IDE for building Objective-C apps for Mac OS X and IOS. When developing a GUI app, XCode provides a visual tool called Interface Builder that is amazing. It provides a standard set of widgets for your apps and allows you to do visually design the UI. Interface Builder simplifies the creation of connections from the code to the GUI widgets via dialogs and selections in those dialogs. Because the actual code to handle these things is hidden behind the IDE, the experience was rather cloudy in my mind. At some point, I plan to dig down into what is actually happening behind the curtain here to solidify it in my mind. I also used the XCode debugger and profiler which were both very nice tools and were both included in the IDE.

I forgot to mention that I am using Objective-C 2.0 and XCode 4.2. This is not only a new release of Objective-C but it's also a new release of XCode with a dramatically improved set of functionality. My prior experience was with XCode 3.x, it was minimal and I was not writing Objective-C, so I didn't really get to experience the power of XCode. Now that I've been through a couple of tutorials with XCode 4.2 and Objective-C, I must say that I'm duly impressed. In fact, Eclipse could stand to learn a few things from XCode. Objective-C 2.0 is a big improvement over the previous version. There's now automatic reference counting to help you with memory management (the big thing I hated about C/C++) and much more.

The apps I created run on Mac OS X. They are both very minimal and not very useful overall, but it is invigorating to delve into new territory for a platform that I have known and loved for over 20 years already. I plan to keep at it as time allows and build some useful apps. Perhaps I will even develop some IOS apps.

For those who are interested, here are the two tutorials that I followed:

I've also been reading many blogs from Objective-C and Cocoa developers. I also found some items for Java developers who want to learn Objective-C:

I will try to keep adding info about resources here as I think about them. Not only is this a record for myself, but hopefully it will help other folks as well.

19 September 2011

Installing PostgreSQL 9.0 on Mac OS X 10.6.8 via MacPorts



While installing PostgreSQL 9.0 on Mac OS X again, I had to figure out all these steps yet again. So I'm documenting this process for my own sake because I have been through this now twice on two computers recently, having to hunt down all of these commands each time. I'm hopeful that this will help others as well.

Use the MacPorts command port to install PostgreSQL 9.0, then create and own a data directory and a logs directory:

$ sudo port install postgresql90-server
$ sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
$ sudo chown -R postgres:postgres /opt/local/var/db/postgresql90
$ sudo mkdir -p /opt/local/var/log/postgresql90
$ sudo chown -R postgres:postgres /opt/local/var/log/postgresql90

Now you need to initialize the database using the data directory that was created above:

$ sudo -u postgres /opt/local/lib/postgresql90/bin/initdb -D /opt/local/var/db/postgresql90/defaultdb

I prefer to change the postgres user's shell to bash:

$ sudo dscl . -create /Users/postgres UserShell /bin/bash

View the postgres user account just to make sure it all looks OK:

$ dscl . -read /Users/postgres
AppleMetaNodeLocation: /Local/Default
GeneratedUID: 5B38F583-CBBF-4082-A32D-C17947394A27
NFSHomeDirectory: /opt/local/var/db/postgresql90
Password: *
PrimaryGroupID: 501
RealName:
PostgreSQL-90 Server
RecordName: postgres
RecordType: dsRecTypeStandard:Users
UniqueID: 502
UserShell: /bin/bash

Also check the postgres group:

$ dscl . -read /Groups/postgres
AppleMetaNodeLocation: /Local/Default
GeneratedUID: 715FEB22-D0F1-443F-BC93-55896210DB44
Password: *
PrimaryGroupID: 501
RealName: postgres
RecordName: postgres
RecordType: dsRecTypeStandard:Groups

Now edit the /opt/local/var/db/postgresql92/defaultdb/pg_hba.conf file to add the appropriate permissions:

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust

This should allow you to connect easily using the psql utility.

I prefer to use the pg_ctl command to start and stop PostgreSQL. This is simply because I learned PostgreSQL on Linux and that's all there was. To prevent having to retype the full command every time I want to start or stop the database, create a start script and a stop script in the postgres user's home directory named pg_start and pg_stop. Below are the contents of the pg_start file. Make sure to create these files as the postgres user in the home directory:

$ sudo su - postgres
$ vim ./pg_start
#!/bin/sh
/opt/local/lib/postgresql90/bin/pg_ctl -D /opt/local/var/db/postgresql90/defaultdb -l /opt/local/var/log/postgresql90/postgres.log start &

Below are the contents of the pg_stop file:

$ vim ./pg_stop
#!/bin/sh
/opt/local/lib/postgresql90/bin/pg_ctl -D /opt/local/var/db/postgresql90/defaultdb -l /opt/local/var/log/postgresql90/postgres.log stop

Don't forget to make them executable:

$ chmod +x ./pg_start
$ chmod +x ./pg_stop

(There is a Mac OS X way of starting PostgreSQL using launchctl but I don't tend to use that because I'm used to the standard pg_ctl command.)

Now use the pg_start script to start up PostgreSQL. Execute it as the postgres user (sudo su - postgres) I tend to cat the log file just to make sure it's running correctly:

$ ./pg_start
$ server starting

$ cat ../../log/postgresql90/postgres.log
LOG: database system is ready to accept connections
LOG: autovacuum launcher started

Looks good so we'll create my user:

$ /opt/local/lib/postgresql90/bin/createuser bsnyder
Shall the new role be a superuser? (y/n) y

Because I made my user a superuser, I can create my own db schema, so log out of the postgres user account and back to my own account first:

$ exit
$ /opt/local/lib/postgresql90/bin/createdb
CREATE DATABASE

The createdb command automatically uses my username as the schema name.

The only thing left to do before starting up the database is edit your ~/.profile or ~/.bash_profile to put the path to the PosgreSQL bin directory into the PATH:

export PATH=/opt/local/lib/postgresql90/bin:$PATH

Now just log into the PostgreSQL server using psql to make sure we're ready to roll:

bsnyder@skunk [~] $ . ~/.bash_profile
bsnyder@skunk [~] $ /opt/local/lib/postgresql90/bin/psql
psql (9.0.4)
Type "help" for help.

bsnyder=# select version();
version
------------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 9.0.4 on x86_64-apple-darwin10.8.0, compiled by GCC i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664), 64-bit
(1 row)

bsnyder=#

And we're good to go!

UPDATE: For those who want a nice seamless experience stopping/starting Postgres via a Mac OS X preference pane, check out Preference Pane for administering PostgreSQL on Mac OS X . It is configurable so there is no restriction on where PosgreSQL is installed.

03 August 2011

Courage Classic Charity Ride 2011, Even Better Than 2007



Every year I ride in a three-day cycling event in the Colorado Rocky Mountains named the Courage Classic. I participate in this ride every summer because it benefits the Children's Hospital Foundation, a wonderful cause that directly benefits many kids with life-saving care. To find out more, check out the website.

In 2007, I wrote about riding the Courage Classic with my oldest daughter. That was a wonderfully proud moment for me as a parent. But this year was even better.

For months now, my youngest daughter has been talking about riding the Courage Classic family day this year. We were never sure if she would actually do it or not, but we worked up to it by practicing and kept encouraging her. Not only did she ride the same little single-geared bike that her older sister rode over the 33 mile course from Copper Mountain to Breckenridge and back, she did it a year earlier -- and she's only eight years old!!! What really drove her, I found, is that she is one year younger than her older sister when she rode it for the first time. Ah, sibling rivalry has its positive moments. All along the entire course, people cheered her on and she got the biggest thrill from it.

Not only did my eight-year-old ride for the first time, so did my wife and she did great. She's typically a runner and only likes casual bike riding, so I wasn't sure how it would go. A few days beforehand, I took her around Turquoise Lake near Leadville, CO (which is about 10,000 feet of elevation) as a training ride. She was not too excited by this choice as the last training ride for her, but she did admit that it helped her prepare and she really surprised me.

So I got to ride with both my daughters and my wife on the second day of the ride this year. A memorable day indeed!

02 August 2011

The iPhone is Not a Submarine But Apple Made My Day



This morning I got up at 5am to ride up Flagstaff Mountain with a friend. Soon after I got up I dropped my iPhone in water, totally submerging it. Great. What a wonderful start to my day. Obviously this rendered the phone completely dead. Excellent. So I rode this morning with my old iPod Shuffle, so that wasn't a big deal. But I didn't have a clock so I took my wristwatch and put it in my jersey pocket.

In my second hour of riding I pulled the watch out of my jersey pocket (pockets are on the back of a bike jersey) and I dropped it on the rode. When I circled back and picked it up, I realized that one of the pins had bent and needed to be replaced. Not a big deal really as I've had this happen many times over the years. And there's a jewelry place right near the Apple Store I typically use. Still, that's strike number two for the day. I rode the third hour just waiting for the third bad thing to happen, but it never did.

I just returned from the Apple Store and I'm glad to say that I was quite happily surprised. This phone was covered under AppleCare but it doesn't cover dropping your phone in water. Matteo at the Flatirons Crossing Apple Store informed me that Apple has a policy of leniency when it comes to your first major accident with your iPhone so he was able to basically give me a get out of jail free card and save me $200 (the cost of replacing an iPhone 3GS). What a surprise!!! I was prepared to pay the cost of replacement and be on my way. So I was very pleasantly surprised.

As Matteo was filling out the necessary forms for the replacement, we chatted a bit. He asked me if I upgraded to Mac OS X Lion yet. I explained that I had not because I was speaking a conference in Portland last week and I didn't want to chance any issues with my laptop until that was done. This led him to asking me more about speaking at conferences and what I do for a living. After explaining that I'm a software engineer at VMware, his response was, 'We all love VMware Fusion!" I agreed and explained that I use it often for testing and running other operating systems on Mac OS X. He said that folks inside Apple really prefer VMware because it's so reliable, which was nice to hear.

Before leaving, I asked Matteo to help me find the AC adapter that plugs into the end of a USB cable. I left one in my hotel room in Portland last week so I needed to replace it. Unfortunately you cannot buy just the AC adapter, you must buy a new USB cable as well. But Matteo said, 'Hold on a minute, I'll be right back.' A minute later he returned with the very AC adapter I needed and said, 'Here you go, free of charge. Because you work for a cool company that we love. And I can see that you need a change of luck today." Wow! Yet another pleasant surprise!!! I think this might be a good day after all. Thanks, Matteo!