one-liner to install nginx with passenger and ssl

Just build this little guy for our puppet script, maybe someone needs it too ๐Ÿ™‚

export V=0.7.67 && wget -O /tmp/nginx-$V.tar.gz http://sysoev.ru/nginx/nginx-$V.tar.gz && cd /tmp && tar xzvf nginx-$V.tar.gz && sudo passenger-install-nginx-module --nginx-source-dir /tmp/nginx-$V --extra-configure-flags="--with-http_ssl_module" --auto --prefix=/opt/nginx-$V && rm /opt/nginx && sudo ln -s ย /opt/nginx-$V /opt/nginx

(If you like the stock nginx without ssl, youll need the –auto-download option)

Maximum and minimum for MongoMapper

A small hack to get minimum/maximum functionality on MongoMapper, its not 100% secure(can be wrong when inserting twice at the same time etc), but good enought for our usecase ๐Ÿ˜‰

Usage

  User.maximum(:friend_count)
  User.minimum(:friend_count)

Code

module MongoMapper::Document::ClassMethods
  def maximum(column)
    first(:order => "#{column} desc").try(column)
  end

  def minimum(column)
    first(:order => "#{column} asc").try(column)
  end
end

IRB History and colors with Wirble

For a nicer irb experience there is wirble, a gem that adds history and colorization, the only thing missing so far was actual support and bugfixes, which i finally found on blackwinters branch, now history scrolling is fun again ๐Ÿ™‚

A small excerpt from my dotfiles irbrc

def require_without_bundler(gem, file)
  return require(file) unless defined?(::Bundler)
  if gem_path = Dir.glob("{#{Gem.path.join(',')}}/gems/#{gem}*").first
    $LOAD_PATH << "#{gem_path}/lib"
    require file
  else
    raise LoadError, "Gem #{gem} not found via require_without_bundler"
  end
end

begin
  # nice history and color
  require_without_bundler 'blackwinter-wirble', 'wirble' # blackwinter branch has history_uniq fixes
  Wirble::History::DEFAULTS[:history_uniq] = 'reverse'

  Wirble.init
  Wirble.colorize
rescue LoadError
  # No wirble use defaults to get at least history
  require 'irb/ext/save-history'
  IRB.conf[:USE_READLINE] = true
  IRB.conf[:SAVE_HISTORY] = 10000
  IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
end