Tuesday, November 30, 2010

Building MySQL multiarch (32/64 bit) client libraries on OS X

Getting the mysql gem to build can be a pain. Especially if you have installed the 64-bit version of mysql and are using a 32-bit version of ruby

You can check the build arch of an executable/library via the file command, such as:

$ file `which ruby`
/Users/timcharper/Developer/.rvm/rubies/ruby-1.8.6-p383/bin/ruby: Mach-O executable i386
$ file /usr/local/mysql/lib/libmysqlclient.dylib 
/usr/local/mysql/lib/libmysqlclient.dylib: Mach-O 64-bit dynamically linked shared library x86_64

See how those disagree? If you're using homebrew (which you should be!), you can build the client libs/tools only (universal style) as follows:

brew install mysql --client-only --universal

Then, to install the gem, you need to pass some fancy flags to get the mysql gem to link against your new libraries:

HOMEBREW_PREFIX=/usr/local # if your prefix differs, modify this line

gem install mysql -- --with-opt-include=$HOMEBREW_PREFIX/include/mysql/ --with-opt-lib=$HOMEBREW_PREFIX/lib/mysql --without-mysql-config

Your gem should build with no errors, and your new shiny universal mysql client libraries should serve you well in the future if you use both 32-bit and 64-bit rubies.

Sunday, June 27, 2010

A Series of Impossible Events

So, Saturday we hiked to Stewart Falls w/the kiddos. Ok, Mikkie rode on my shoulders most of the way, and walked maybe 1/20th of the time (I had to teach her several times that my eyeballs were not a good place for her to cling to for support… nor my mouth, my throat, my ears…. where’s a baby girl to hold on to?).

Anyways… the strangest of coincidences. Of the 20 odd people we must’ve passed on the trail that Saturday Evening, one face struck a vein of familiarity, and the name “Gwen” came to mind. Risking an awkward moment of “oh, I’m sorry, I mistook you for someone I knew”, I turned around and said her name aloud, waiting to see if she would respond. To my surprise, she stopped, turned around, and not only did it turn out to be her, she was there with both Brandon, and Jill (two other very prominent people in my childhood whom I hadn’t seen nor talked to for at least 5 years)! We talked for a bit, had a brief round of catching up, and both commented on the impossible odds that were beaten for us to both be on that trail, crossing at the same time, on that day. And how funny it is was that I, Jill and Brandon passed us by without noticing (Jill and I were best of friends between the ages of 2 and 10, a friendship that unfortunately dwindled to the status of “acquaintances” when I moved to another neighborhood).

This isn’t all: earlier that day I was helping my friend Ronny move into his new house. I became acquainted with another fellow helper, whose first name I’d only asked: Jake. After some good conversation, the subject of where we lived came up, to which he said South Jordan, and I said Saratoga Springs. He said “Saratoga Springs, I have a brother who lives in Saratoga Springs”. “Oh really?” I asked, “which part”. He couldn’t remember the name, so I asked how far out. “Way out there… like passed Jacob’s Ranch” he replied (my memory faintly recalls the word “boonies” used to describe the distance). I started naming the neighborhoods as I could remember them (Saratoga Springs is organized like that), and when I named ours, he said “yeah, that’s it.” I felt certain that it must be someone I knew, so I asked what his brothers name was, and it turned out to be my next door neighbor! And to comment on how further these seemingly impossible odds were aligned, in that very moment, after we made this connection, Mark called his brother Jake on his cell phone. Wanting to capitalize on this moment, I asked Jake if he’d let me answer it. He agreed, and Mark was pretty confused as to why his neighbor was answering his brother’s phone. It turns out that Ronny’s wife’s family and my neighbor Mark’s family were friends while growing up in California.

I’m still somewhat amazed at how all of that came together yesterday, and not just one coincidence, but two, occurred. I wonder how often we pass down the same road as a childhood friend, or pass each-other in a crowded mall, without giving notice to the occasion.

This isn’t particularly edifying in anyway, but I suppose it could serve to remind one to toss a spark to kindle an old friendship, and take a moment to notice and admire the little things.

Anyways…. as you were.

Tuesday, May 18, 2010

Hyper Inflation in the USA?

I found this documentary on our economy informative: http://www.youtube.com/watch?v=eb1n1X0Oqdw

I wouldn't ignore that there could be some sensationalism in the film to try and sell gold, but in spite of that I think the material in it is solid. Essentially, it's stating our economy hasn't recovered from the recession, any sign indicating that we have recovered is actually just inflation occurring, and our country can either make some radical changes now to cut spending and prevent the economic collapse and hyper inflation, or be forced to make some radical changes after our economy collapses.

I'd encourage everyone to watch at least the first 10 minutes and evaluate whether or not you wish to invest a full 55 minutes of your life to watching the whole thing.

Wednesday, May 12, 2010

Whose Line Is It, Anyways?

Funny story: we decided to install a fence recently. A few days ago, I get a call from Mark (the guy installing the fence) saying that while he was digging fence-posts, he went straight through my neighbors sprinkler line which ran nice and snug along the property line. We comment about what a bad idea it is to install a sprinkler line there, and I call my neighbor to inform him of the misfortune and begin working towards a solution. He tells me there's no way his sprinkler line is on the property line, we assert that the line is indeed on the property line, have checked with the city, and have measured and verified that the property line is indeed where the markers say it is.

Since I felt it was his fault for having the line so close to the property line, part of me didn't feel I was obligated to do anything to help fix it. However, wanting to keep good feelings between neighbors, and since it was in fact my idea to install the fence, I agreed to buy the material to fix the lines if he'll agree to help me do the work. Saturday comes, I bought the pipe and fittings, and my neighbor and I are digging up the grass to fix the line. Once again, I note how obviously close his sprinkler line is on the property line, and even in one spot it clearly comes into my yard an inch! Then, a thought comes to my mind: "what if it's really my sprinkler line? That would be kind of funny, wouldn't it?" I joke about this out loud. Then we look at each-other, and the joke quickly turns into a prime suspect (one that neither of us had thought of until this point). The city irrigation water was now turned on, so I run and flip on my irrigation valve and cycle through my sprinklers. Hilarity ensues as water sprays everywhere, clearly verifying that my neighbor was in fact right: his sprinkler line WASN'T close to the property line at all, but mine was!!!

I told my neighbor he could go home, that this was my responsibility and I needed to fix it. However, he was really cool, stayed and helped anyways, saying "I don't care whose fault it is, just that it gets fixed". That was awesome of him and made me feel grateful to have such a good neighbor. More so, I'm extremely grateful that we were able to laugh about it instead of me feeling like a complete idiot (as opposed to just a partial idiot).

A couple of things in retrospect:

  • When discussing what to do to fix the line, I was really glad I put into practice a few principles I'd learned from the fantastic book on negotiating "Getting to Yes". Had I engaged in positional bargaining (this is your fault so you fix it!) instead of principled negotiation (do you agree that it's fair if...), I would have felt like a lot bigger idiot in the end. Being slow to jump to positions saved a lot of face and made what could have been a big drama, a funny story instead. (trying to avoid "tooting my own horn" here while lending witness to the superiority of principled negotiation over positional bargaining, and the effectiveness of the mentioned book in teaching the subject)
  • If you must err (which, being human, we will), err on the side of mercy. I'm grateful to still have a good relationship with my neighbor, and even if it really was his line, how much is amicability between neighbors worth? I'm not advocating that we be soft negotiators and dart straight to any agreement that's unfair to us, there's a line there, somewhere :)

What's the worst neighborly dispute you've had with a neighbor? How did you resolve it?

Saturday, February 6, 2010

Emacs baggage

In a prior post, I articulated why I liked Emacs. There are plenty of reasons, certainly! This week, however, I rethought of my decision to switch completely over to Emacs. It has a lot of baggage holding it into the past, and I get the feeling it needs to be reborn (an Emacs rewrite in clojure would be awesome). Leaving Emacs and returning back to my TextMate editing environment has turned out to be a relatively good experience: even though I miss a few features, I don't miss the fiddling.

I really did give Emacs a fair shake. I wrote a campfire mode (a chat client for 37 signals campfire right within Emacs), contributed several improvements to a few scripts, submitted a variety of scripts to the ELPA, and otherwise invested a plethora of hours into learning it.

At first, the cool features that Emacs has kept me going. It was a lot of investment, and I found myself thinking "it will get easier, the overhead will go away". After two months, it still hasn't. Emacs is full of 80% complete features, so lots of things bugged me, constantly requiring my attention to fix. When you fiddle with Emacs, some issues don't manifest themselves until the next time you try to start it. Therefore, every time I started up Emacs, something would fail somewhere. In the end, this was throwing gravel into the engine of my productivity.

Another thing I noticed: my wrists seemed to have more problems when I was using Emacs. For whatever reason, TextMate seems to be easier on my wrists. TextMate might require more keystrokes then Emacs to perform certain editing tasks, but the movements aren't as awkward.

There is no question that Emacs is more extensible than TextMate or vim. But, in the end, even after several months of usage, I still found myself more productive using simpler editors that just worked well out of the box.

I will probably continue to use Emacs in some form or another, probably for LaTeX and Clojure. For really quick editing jobs, I still prefer vim, because it is really powerful and starts up fast. But, as far as Ruby on Rails development goes, I'm not sure it gets any better than TextMate.

EmacsBaggage

Saturday, January 30, 2010

Getting ruby to use readline instead of libedit

I prefer readline for a variety of reasons:
  • I'm used to it, it's the same command editor that powers bash
  • It's very powerful.
  • In Ruby, it doesn't block other threads from running while waiting for input.
When I installed ruby 1-9 using rvm, it got compiled against libedit. I didn't feel like reinstalling, so I followed these instructions over here.

I'd thought that `port install readline` would suffice, but it didn't. I had to install readline-6.0 from source. Ruby doesn't compile against readline-5.0, it just spits out a load of errors. The following is what I did, if you would like to follow along:

Install readline: (I use homebrew, see here for an alternative method)
brew install readline
Then, go into the src ext/readline folder where rvm built your ruby. Mine was ~/.rvm/src/ruby-1.9.1-p378/ext/readline.
cd ~/.rvm/src/ruby-1.9.1-p378/ext/readline # <- your path will vary
ruby extconf.rb --with-readline-dir=/usr/local/Cellar/readline/6.0
Make sure you see this line in the output:
checking for readline/readline.h... yes
Then, build it:
make
When it finishes, run otool -l readline.bundle. You should see this:
       name /usr/local/lib/libreadline.6.0.dylib (offset 24)
 time stamp 2 Wed Dec 31 17:00:02 1969
    current version 6.0.0
compatibility version 6.0.0
If you see libedit anywhere in that output, it didn't link against libreadline. Failure. Now, if it's all successful, install the new readline.bundle.
  make install
Good luck!

Update:

If another version of Ruby is used to run the extconf.rb then the target version of Ruby for which you are compiling read line, you will get another stream of build errors, perhaps something like this:

gcc -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I. -DHAVE_READLINE_READLINE_H -DHAVE_READLINE_HISTORY_H -DHAVE_RL_DEPREP_TERM_FUNCTION -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_BASIC_WORD_BREAK_CHARACTERS -DHAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS -DHAVE_RL_BASIC_QUOTE_CHARACTERS -DHAVE_RL_COMPLETER_QUOTE_CHARACTERS -DHAVE_RL_FILENAME_QUOTE_CHARACTERS -DHAVE_RL_ATTEMPTED_COMPLETION_OVER -DHAVE_RL_LIBRARY_VERSION -DHAVE_RL_EVENT_HOOK -DHAVE_RL_CLEANUP_AFTER_SIGNAL -DHAVE_REPLACE_HISTORY_ENTRY -DHAVE_REMOVE_HISTORY -I/usr/local/include   -fno-common -arch ppc -arch i386 -Os -pipe -fno-common  -c readline.c
readline.c: In function ‘readline_readline’:
readline.c:82: error: ‘rb_io_t’ undeclared (first use in this function)
readline.c:82: error: (Each undeclared identifier is reported only once
readline.c:82: error: for each function it appears in.)
readline.c:82: error: ‘ofp’ undeclared (first use in this function)
readline.c:82: error: ‘ifp’ undeclared (first use in this function)
readline.c: In function ‘filename_completion_proc_call’:
readline.c:703: error: ‘filename_completion_function’ undeclared (first use in this function)
readline.c:703: warning: assignment makes pointer from integer without a cast
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: warning: assignment makes pointer from integer without a cast
readline.c: In function ‘readline_readline’:
readline.c:82: error: ‘rb_io_t’ undeclared (first use in this function)
readline.c:82: error: (Each undeclared identifier is reported only once
readline.c:82: error: for each function it appears in.)
readline.c:82: error: ‘ofp’ undeclared (first use in this function)
readline.c:82: error: ‘ifp’ undeclared (first use in this function)
readline.c: In function ‘filename_completion_proc_call’:
readline.c:703: error: ‘filename_completion_function’ undeclared (first use in this function)
readline.c:703: warning: assignment makes pointer from integer without a cast
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: warning: assignment makes pointer from integer without a cast
lipo: can't open input file: /var/folders/jz/jzGJ6Q4BFumSODlDitruR++++TM/-Tmp-//ccvDT283.out (No such file or directory)
make: *** [readline.o] Error 1

To resolve, run extconf.rb with the same version of Ruby for which you are recompiling readline.


Update 2:

ruby 1.8.6 and ruby 1.8.7 appear to have their threads (and signals) blocked by readline now. This seems to be a recent development as I have used readline with ruby 1.8.6 without blocking threads in a past build.

Ruby 1.9.1 doesn't currently block threads with readline


Update 3:

I have updated this entire post, consolidating and simplifying the content. Then I renumbered the updates. My blog is not immutable.

Wednesday, January 6, 2010

Open in Emacs finder droplet

Here's a handy finder droplet to open a file in Emacs (for MacOS X): OpenInEmacs Here's how you install it / use it: Demo Video