TalkingQuickly's Today I Learned

5 posts about #rails

Installing Old Versions of Event Machine

I recently needed to install Event Machine 0.12.10, hardly the most recent release. To get native extensions to build on Sierra, you'll need to do something like:

brew install openssl
bundle config build.eventmachine --with-cppflags=-I$(brew --prefix openssl)/include`

Wildcard Searches in Mongoid

I'm not sure I'll ever reach the point where I can be described as a fan of Mongo, but discovered today that wildcard searching is very easy with Mongoid:

User.where(email: /STRING_TO_SEARCH_FOR/i)

Phantom jobs in sidekiq-cron

Still not entirely sure of the underlying logic. But it appears that sidekiq-cron does not purge jobs which are not found from the scheduled set. It's therefore required to do one of the following before a deploy to remove either all jobs or a specific one:

#destroys all jobs

#destroy job by its name
Sidekiq::Cron::Job.destroy "Job Name"

Scheduling using sidekiq-cron at specific times

The sidekiq-cron gem syntax for scheduling things at specific times each day is as follows:

'00 12 * * * Europe/London'

E.g. five total fields, not six.

Installing old versions of therubyracer Gem

If working with a codebase which relies on an old version of therubyracer gem (in my case 0.9.9) there are likely to be lots of errors building native extensions.

This can be worked around by using an old Apple GCC version temporarily as follows:

brew install homebrew/dupes/apple-gcc42

export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2

brew uninstall v8
gem uninstall libv8

And then running bundle as usual. This will also resolve issues with old versions of twitter-bootstrap-rails failing to installing (in my case 2.0.3).