Thursday, January 31, 2013

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

I ran to this issue couples of week ago
Installing oj (2.0.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/viki/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
>>>>> Creating Makefile for ruby version 1.9.3 on x86_64-darwin11.4.0 <<<<<
creating Makefile

make
compiling cache.c
compiling cache8.c
compiling dump.c
compiling fast.c
compiling load.c
compiling oj.c
compiling saj.c
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal 2 (use -v to see invocation)
clang: note: diagnostic msg: Please submit a bug report to http://developer.apple.com/bugreporter/ and include command line arguments and all diagnostic information.
clang: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/qw/xj8ns4cn09jfv1x5qq1mhn7m0000gn/T/saj-4CFmfe.i
clang: note: diagnostic msg: /var/folders/qw/xj8ns4cn09jfv1x5qq1mhn7m0000gn/T/saj-4CFmfe.sh
make: *** [saj.o] Error 254


Gem files will remain installed in /Users/viki/.rvm/gems/ruby-1.9.3-p194@raynor/gems/oj-2.0.2 for inspection.
Results logged to /Users/viki/.rvm/gems/ruby-1.9.3-p194@raynor/gems/oj-2.0.2/ext/oj/gem_make.out

I could find the way to fix it. It was quite frustrated at that moment because the only way to get passed this error to start our web server again is to downgrade oj gem.

But eventually, I found the way to fix it. As I understand, this error causes by bug in llvm (Apple's gcc that comes with XCode). Here is the steps of how I fixed the issue.

First you need to install gcc4.2 with brew

brew update
brew tap homebrew/dupes
brew install apple-gcc42
Then reinstall your Ruby with this command (I use RVM)

CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 rvm install 1.9.3-pXXX
After this you should be able to install oj or the other gems as usual.

I composed solution from many links but sorry I forgot to take note of those.



Wednesday, November 14, 2012

4 Rules of Simple Design


  • Pass all tests
  • Clear, Expressive and Consistent
  • Duplicates no behavior or configuration
  • Minimal methods, class and modules
By Kent Beck

Thursday, November 8, 2012

Keep adding types use Polymorphism, keep adding functionalities use Struct

If we set minimize the changes as a goal, object-oriented programming people tend to agree that conditionals are bad smell, we should consider refactor them to types and use Polymorphism mechanism instead so that when we have a new type of data we can have a small change just to create a new types. But there is a good point in the early part of this podcast Something Else Was Smellier stated that if we are working on the problem that number of types are likely to be stable but what always changes are the behavior, we should consider keep behaviors separate(Separate function) from those types and leave the types as plain data structures(Struct).

For Polymorphism, if we are adding a new functionality to a class hierarchy we have to add it to every class in that hierarchy otherwise you will get no method error. In the opposite, if you just create a separate function to hold that new functionality while you know that you are not likely to have a new data type, you can just handle those types with case statement which each case response to each type. You can also simply ignore the data types that you don't interested in for that new functionality by fall it back to default case. If you have an another new functionality, just add a new function. If you follow this direction, all changes you have to add will rest in one place, you don't have to modify multiple places(types) as in Polymorphism approach, which leads to the goal of minimize the changes.

More visual example I can give is cards for card game. For example, you try to transform 52-cards deck(Type/Struct) to magic game card deck. You want to add attacking power(behavior) to those cards(Polymorphism), you have to draw value of attacking power on to every cards, which is quite a lot of work. Instead, you can draw a separate attacking power mapping table in a paper(Separate function) then you don't have to modify those cards. You changes will always in the table. And if you want to add defensive power you can have another mapping table. You can always have a new mapping table for every new functionality without touching those cards. The pain will occur when you need to add a new card(Type) because you have to go and modify every tables. If you always have a new card(Type), don't use a mapping table approach step back and go for modifying the card approach (Polymorphism).

One downside of emphasizing the struct is that you will have a hard dependency on that struct and you have to adapt the functionality to be match with that structure. When the struct get modified, your functionalities that rely on that struct are likely to change. For example the same 52-cards deck(Struct), which is a stable type never change structure, you can apply as many kind of games(behavior) you want on it easily but your game have to be sufficient of using only these 52 cards. When one of those 52 cards is modified, your games are screwed up.

Tuesday, October 16, 2012

Modern product development motto


Don't launch if you aren't going to monitor
Don't monitor if you aren't going to improve
Don't improve if you don't know who to improve for

Sunday, October 14, 2012

Weird Clojure build-in function names

Clojure has a rich set of build-in functions for manipulating data structures. Library developers have to name each of them as concise as possible to make them convenient to use. Selecting a word that can describe the whole behavior of each function is a very important step and they did this very well.

But for non-native English speaker that coming from Java and Ruby world, I found that some of the
function names are hard to guess and remember what they do. These are an example list of them.
  • quot
  • assoc
  • dissoc
  • interleave
  • interpose
  • juxt
  • reductions
  • trampoline

Btw, I have a feeling that I remember them now after wrote this blog. :)

[VIM] + and * register don't work with clipboard on MacOSX

This problem is because VIM version that shipped with MacOSX doesn't enable xterm_clipboard. You can check this by run :version command in VIM. Enabled xterm_clipboard VIM must have +xterm_clipboard but the version shipped with MacOSX has -xterm_clipboard.
If you want it to be enabled, you need to compile VIM yourself with clipboard enabling flag.

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...