Geoip_city on Mac OS

Today, I spent a time to install gem geoip_city. So what did I do:

    wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz
    tar zxf GeoIP-1.4.6.tar.gz
    cd GeoIP-1.4.6
  • Read file README.OSX. Found simple instructions to compile this lib.
    export GEOIP_ARCH='-arch i386 -arch x86_64 -arch ppc -arch ppc64'
    export MACOSX_DEPLOYMENT_TARGET=10.4
    export LDFLAGS=$GEOIP_ARCH
    export CFLAGS="-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk $GEOIP_ARCH"
    ./configure --disable-dependency-tracking
    perl -i.bak -pe'/^archive_cmds=/ and !/\bGEOIP_ARCH\b/ and s/-dynamiclib\b/-dynamiclib \\\$(GEOIP_ARCH)/' ./libtool
    make
  • When run all this stuff, I did not get a success result, I still have a error when install gem.

  • show available SDKs in you host

    ls /Developer/SDKs 

    I got two: MacOSX10.5.sdk MacOSX10.6.sdk

  • So change line in readme file before

export CFLAGS="-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk $GEOIP_ARCH"
to
export CFLAGS="-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.6.sdk $GEOIP_ARCH"
* and execute all steps from README file. * but found a problem in step configure:
% ./configure --disable-dependency-tracking 
checking for gcc... gcc
checking for C compiler default output file name... 
configure: error: C compiler cannot create executables
See `config.log' for more details.
  • I choose another SDK and set to “MacOSX10.5.sdk”

  • run again all steps

  • then install gem and all works fine

if you have troubles to install gem and still see next message:

checking for GeoIP_record_by_ipnum() in -lGeoIP... no
you must have geoip c library installed!
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-geoip-dir
    --without-geoip-dir
    --with-geoip-include
    --without-geoip-include=${geoip-dir}/include
    --with-geoip-lib
    --without-geoip-lib=${geoip-dir}/lib
    --with-GeoIPlib
    --without-GeoIPlib

So you should add include /usr/local/lib to DYNLD_LIBRARY_PATH. Or do next: in step of configuration do ./configure —disable-dependency-tracking —prefix=/opt/GeoIP and then next steps from README. I suggest do make clean before each compiles. And then sudo gem install geoip_city — —with-geoip-dir=/opt/GeoIP to install gem.

0 comments »

Mac Book PRo could not write DVD+R

Tried to burn files to Verbatim DVD+R disc with 16x available speed. Mac OS only support 4x and 8x. So I was impresed. The device name is HI-dt-st DVDRW GSA-S10N.

0 comments »

GOD redefine 1.day

We add gem bundler to our rails application. So we add all gems from production server to bundle and restart app. After we find a strange thing: 1.day return 86400. but before it returns 1.day and if we do “Time.now.to_date + 1.day” we get a 86400 day from now.

So we research our bundler gem list, and remove not used gems for rails.

0 comments »

Install Nokogiri on Mac OS

sudo gem install nokogiri — —with-xml2-include=/usr/include/libxml2 —with-xml2-lib=/usr/lib —with-xslt-dir=/usr

0 comments »

Share scout plugins

I have recently created repository for scout plugins http://bitbucket.org/jetthoughts/scout-plugins/src.

Added Postgres Mememory Monitor.

0 comments »

Change size of images shell script

I had a issue: Find all images in directory and change size to “150x200”. So lets start.

  1. Find all images find .
  2. Convert size of image: convert -geometry ‘150x200’ image.gif image.gif
    for i in $(find .)
    do
      convert -geometry "150x200" $i $i
    done

If you want get only image size use: identify image.png

0 comments »

Jruby and Spork

When you try run spork you have to enable fork for spork (instead you will have error

spork/forker.rb:18:in `initialize': fork is unsafe and disabled by default on JRuby (NotImplementedError)
). So it should like:

jruby -J-Djruby.fork.enabled=true <path-to-jruby-binaries>/spork
0 comments »

Remote Rails Console

Many times we want execute some commands in remote servers. We login to server, change directory, run script/console. Thanks to Capistrano we could only add next snippet to config/deploy.rb of our rails app:

desc "remotely console" 
task :console, :roles => :app do
  input = ''
  run "cd #{current_path} && ./script/console #{rails_env}", :once => true do |channel, stream, data|
    next if data.chomp == input.chomp || data.chomp == ''
    print data
    channel.send_data(input = $stdin.gets) if data =~ /^(>|\?)>/
  end
end

And then when we need remote console, just run: cap console

0 comments »

Rails assets host with ssl

When we use simple assets server as ActionController::Base.asset_host = "http://assets%d.example.com", so we have a problem with pages which used ssl and some browsers alert users,that some content is not safe.

So I found in the google next solution:

ActionController::Base.asset_host = Proc.new { |source, request|
    "#{request.protocol}assets%d.example.com" % (source.hash % 4)
}

It is beautiful, because for each image we use only one host, so when you refresh you page, a image always have example host ‘assets1’ in each page, not random host.

0 comments »

Mutable branch for capistrano deploy script

I always had troubles, when test new feature. I forgot to change branch in capistrano config. So I found one solution wich help me:

set :branch, `hg branch`.chop || "default"

or for git:

set :branch, `git branch | grep '*' | sed 's/^[^a-zA-Z]*//'`.chop || "master"

Thats all.

0 comments »