Page 3 of 36

Previous page

I Tri-ed It

Last Saturday I participated in my first triathlon at Santee State Park. It was an “off-road” triathlon which consisted of 3 miles of trail running, 3 miles of lake kayaking, and 7 miles of mountain biking. They had lots of participants for the short and long races, and the weather was excellent. It was good mix of people, so I didn’t feel intimidated just by being there. I was there more just to compete with myself anyway.

The race made for a good excuse to exercise during the winter. I did a little more activity right after Christmas, but I didn’t really get into it until the last month. Then I spent extra time at the gym and also did some “mini” triathlons here in the neighborhood.

For the race, the running was tough; I should have trained more for that and run more on trails instead of roads and treadmills. I felt great kayaking, and passed several people, but my wide poly kayak was a barge compared to the sea kayaks and racing kayaks that some other folks had. The biking was harder than expected; I was pretty tired by then and you can’t coast as much on a trail as you can on the road. But all in all, I was happy just to finish! And to not be last was a bit of a bonus. I came in 19th of 26.

Now you give it a “tri.” :)

MAMP and the Ruby MySQL Gem

Update 2011-09-18: See here for the most up-to-date instructions (MAMP 1.9). I got it working on 2.0, but experienced some of the same problems other commenters noted). See also these instructions for MAMP 1.8.

After much frustration, I found a way to get the Ruby mysql Gem installed and talking to my MySQL server on MAMP. Credit goes largely to “Hootbah” who followed a similar path to get MAMP talking to Perl’s MySQL library. Here’s the steps I followed for MAMP 1.7.2:

  1. Install the regular MAMP 1.7.2 dmg package.
  2. Download the MAMP 1.7.2 source code.
  3. Unzip the source code file.
  4. Open the terminal and go into the source code directory.
  5. Untar the mysql file and go into the untarred directory:
    $ tar -xzvf mysql-5.0.41.tar.gz
    $ cd mysql-5.0.41
  6. This is the Hootbah magic…we’re basically compiling libraries here for the Gem to link against.
    $ ./configure –with-unix-socket-path=/Applications/MAMP/tmp/mysql/mysql.sock –without-server –prefix=/Applications/MAMP/Library
    $ make -j2
  7. Copy the compiled libraries into MAMP:
    $ cp libmysql/.libs/*.dylib /Applications/MAMP/Library/lib/mysql
  8. Copy the MySQL headers into MAMP…Hootbah didn’t do this but I had been doing it earlier trying to get around some missing mysql.h problems, and figured I’d keep doing it:
    $ mkdir /Applications/MAMP/Library/include
    $ cp -R include /Applications/MAMP/Library/include/mysql
  9. Install the Ruby MySQL Gem:
    $ sudo env ARCHFLAGS=“-arch i386” gem install mysql – –with-mysql-config=/Applications/MAMP/Library/bin/mysql_config

    After being used to seeing errors spit out by this statement, finally a pleasant surprise:

    Building native extensions. This could take a while…
    Successfully installed mysql-2.7
    1 gem installed


Grepping from Ruby

I recently needed to run through one data file, pull a number, and look that number up in several other data files. So in Ruby, I first opened the initial file, pulled the number, and then opened the other files, iterating through every line until I found a match, then call break to move on. This worked, but it was sort of slow.

It occurred to me that I could use grep to see if the number was in the other files. So I had to figure out how to call it from Ruby. Here’s what I came up with:

The speed improvement depends on how many searches you’re doing and the size of the files you’re searching, but in a quick test the grep calls were 5x faster.

Vote for Me!

I hereby declare my candidacy for President of the United States. So please write my name in when you vote today. Why did I wait until today? My platform is procrastination. You can expect me to drag my feet on such projects as:

  • Expanding offshore drilling
  • Invading foreign countries with no reason, or made-up reasons
  • Renewing spying on American citizens

In the immortal words of Mark Twain, “Never put off until tomorrow what you can do the day after tomorrow.”

And whatever you do, please don’t vote for this guy!

'Shoulda' Tested My App

Shoulda is a handy plugin for Rails (now a Gem), which makes writing tests easier. It’s worth checking out. Shoulda has been very helpful with a big Rails project I’ve been working on all summer, and I submitted a couple small contributions and bug fixes. I was surprised to see my name mentioned in the newest release, but I appreciate it, and it was fun helping out!

Next page