Archive for the ‘Technology’ Category
Several things have changed since the last time I wrote about gotchas when installing rmagick on mac osx.
Now a days, you need Homebrew instead of Port.
Install ImageMagick using homebrew first
$ brew install imagemagick
Before, you install rmagick gem though, find out the homebrew folder where imagemagick libraries are installed.
$ Magick-config --prefix
Change directory into this directory.
$ cd `Magick-config --prefix`
Now, symlink the versioned library to what the gem is looking for.
$ ln -s libMagick++-6.Q16.dylib libMagick++.dylib $ ln -s libMagickCore-6.Q16.dylib libMagickCore.dylib $ ln -s libMagickWand-6.Q16.dylib libMagickWand.dylib
Your specific versioned library may differ a little bit.
Now, you should be able to infall gem just fine.
$ gem install rmagick
If you are using thinking_sphinx for your text search needs on a rails project, you will need to have searchd service monitored in production. Monit service allows us to monitor a unix service. However, there is no good/recommended init script that exists. Here’s one that could work for your rails3 project.
It used to be that giving professional reference to your potential employer was just about sharing a few names along with their phone numbers. Not anymore. Winning the technical interview is just half the battle, and especially at senior level positions, the response from your professional reference(s) matter more than ever. Preparing and grooming your references before you actually need them and maintaining elevated communication with each referee can pay huge dividends.
Most potential employers require around 3 professional references. When you start your job search, you are better served getting initial permission from folks that you think could be your professional reference. This is a good time to inform them about why you are looking for new opportunity. Also, confirm phone number, email where they can be reached for reference. You should have about 5 people at various levels (boss, direct report, colleague) available before you actually need them.
While most of us do this right, we forget a few things.
It makes a huge difference if you could share important information about the job with your referee and the person checking reference just before the call happens. Here are some of things you should do before each of your potential employer decides to check on your reference.
Give following information to your referee (person giving professional reference):
- Company detail: Share name of company, website and a brief description of what they do. This saves your referee time to research the company and prepare their answers. It also conveys that you value their time and remain ready to make it as easy as possible.
- Position being interviewed for: Share the title of the position (Sr. Business Analyst, Architect) and job description. This helps them understand the nature of your work in that position so they can highlight the alignment with the job in an enhanced manner.
- Name, phone number, email of person calling. This is important since most people don’t pickup phone if they don’t recognize the number. Also, sharing approximate time of expected call helps a great deal in making sure that they connect the first time!
The same goes for the other side of the equation:
Give the person performing reference check following information:
- Referee’s contact information: Name, phone number, email, preferred time to contact. This is obvious. During initial cultivation of reference, check and confirm which phone, weekday/time works best for them.
- Brief description of nature of professional relationship (boss, direct report, colleague): Thinks like “I worked closely on X project with Y colleague” or “He/she was the lead and I reported to him in Sr. developer capacity”.
- What are some of the things that the person can provide information on: Things like “he can talk about my people skills more than my development ability” or “He can vouch about my progress since our time at X company”. No, this is not cheesy at all. It helps your potential employer understand what are some of the highlights of each reference. Sure, they will not follow the script exactly as you laid out but it will be pretty close.
All in all, your goal with reference should be to get truthful and consistent story (about you) to come out. Preparing your references takes a little effort/time but it is well worth the effort.
Finally, don’t forget to send thank you email to all referee that you’ve used in your search and inform them about your decision to choose a particular company.
If you are upgrading from ruby 1.8 or Ruby Enterprise 1.8.7 to ruby 1.9.2, you may encounter this error.
Installing rbx-require-relative (0.0.5) Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/ bundler/issues so that we can fix it. Thanks!/Users/sjain/.rvm/rubies/ruby-1.9.2-p290/ lib/ruby/site_ruby/1.9.1/rubygems/ installer.rb:364:in `ensure_required_ruby_version_met': rbx-require-relative requires Ruby version ~> 1.8.7. (Gem::InstallError)
This most likely happens because you are declaring a dependency on ruby-debug gem in your Gemfile.
group :development do gem 'ruby-debug' end
With ruby 1.9, you need to update this with new gem name ruby-debug19.
group :development do gem 'ruby-debug19' end
This will eliminate the dependency on rbx-require-relative and fix the issue.
Any a developer switching from linux to mac, the way to set environment variables is similar yet different enough that is annoying at times. I have so far failed to find a good documentation on where and how to set those in mac osx. Today I found one here.
Mac OS X applies .bash_profile and .profile only for Terminal.app environment and Apple’s technical documentation suggests using ~/.MacOSX/environment.plist for other applications. So, by default PATH value will differ for RubyMine and the console.
For managing the global environments, it also recommends a system preference pane app. This worked for me.
If you find that your tests pass when run alone but fail with “unexpected invocation” inside “rake test”, you are most likely seeing behavior that is caused by mocha load order.
It happens when mocha gem is listed as library dependency inside rails app. The library gets loaded too soon. The fix is to load mocha after rails has booted up.
For rails < 3.0.0, this means removing -- config.gem 'mocha' -- entry from config/environment.rb and adding -- require 'mocha' -- at the bottom of test/test_helper.rb.
For rails >= 3.0.0, this means adding — :require => false — inside Gemfile entry as follows.
# Gemfile group :test do gem 'mocha', :require => false end
And then adding following line at the bottom of test/test_helper.rb:
# test_helper.rb require 'mocha'
Commands for installing image-magick package and rmagick gem on max osx:
sudo port install tiff -macosx imagemagick +q8 +gs +wmf sudo gem install rmagick
Sooner or later, the need arises to assign default values to model attributes. In rails this is usually done in model’s after_initialize() with a new_record? guard.
class User def after_initialize if new_record? self.country = "US" end end end
This initializes the object with proper default so the UI form gets properly populated and the database gets proper default if user hasn’t overridden it.
Sometimes, you realize that you have (pre-existing?) objects in database that also need the same default if the current value is nil. In such case, you may modify your initializer like this:
class User def after_initialize self.country ||= "US" end end
This works for both scenarios: User.new and User.find.
However, it introduces a behavior that may not be apparant immediately.
$ script/console ree> User.find(u.id) User Load (0.9ms) SELECT * FROM `users` WHERE (`users`.`id` = 1) ree> User.exists?(:id => u.id) RateSearch Load (0.6ms) SELECT `users`.id FROM `users` WHERE (`users`.`id` = 1) LIMIT 1 ActiveRecord::MissingAttributeError: missing attribute: country /[prj]/app/models/User.rb:3:in `after_initialize'
A closer look reveals that ActiveRecord tries to be smart and only fetch ‘id’ column when performing Model.exists? call.
Many people have tripped this and logged it as a bug. The report has been silently ignored, and I believe, for good/performance reasons.
So, what do we get around it? Here’s one way.
class User def after_initialize self.country ||= "US" rescue ActiveRecord::MissingAttributeError # this should only happen on Model.exists?() call. It can be safely ignored. end end
As they say, it is not a bug, it is a feature.
Rubular, is a tool that you may find handy when developing ruby regular expression for scraping unstructured data needs.