Setup Passenger 4 (pre-release RC4) for Apache2 and Ruby 2.0.0

Setting up Apache2 and passenger for Ruby 2.0.0 is actually pretty simple. As of right now, for Passenger to work with Apache2 and Ruby 2.0.0 you will need to install Passenger 4 RC4 or above, which currently isn’t (technically) a stable release. I have found it’s pretty stable though.

Install passenger through RubyGems

First, install passenger through gems:

gem install passenger --pre

Continue reading

Install multiple Ruby versions on Ubuntu 12.04 using RVM

RVM or Ruby Verion Management is a library written for managing multiple version of Ruby on a single machine, and even for a single user. Using this set of libraries you can easily install a version of Ruby and switch between different version as and when you see fit. This is great for developers, especially those having to maintain multiple different applications, using different Ruby and potentially rails versions.

Installation of RVM on Ubuntu 12.04 for a single user

To start, download RVM and automatically install the latest stable version of Ruby

curl -L | bash -s stable --ruby

Here we download a file which has a series of commands for installing RVM and the latest stable version of Ruby. `-s` tells bash to read commands from the standard input, which is the downloaded file from the rvm website. This process will take a while, depending on your connection speed and processors as it downloads and compiles Ruby and Rubygems. Continue reading

Why I left Spotify and moved to Rdio

As of Sunday the 17th of March, after having been with Spotify for two years I decided to move to a new and upcoming provider, Rdio.

The significance of this post is to detail the fact that I would not in any frame of mind have moved away from Spotify if they had resolved an ongoing issue smoothly, in fact, at all.

Having used their service as a loyal customer for over two years, I thought Spotify would have dedicated more support and time to an ongoing issue that many users have experienced. The issue being Spotify no longer working with Sonos which I noticed on the 1st of January 2013 at 00:00 (quite literally). Sonos simply does not recognise my Spotify credentials, despite originally signing up as an email account holder.

I had been three months without Spotify through my Sonos, which has been a rather painstakingly difficult period for me. I require quality sound, and I require it when I want it, not when my provider decides they will solve an issue. Continue reading

Example configuration with God – Monitor nodejs

God is a very powerful process monitoring library written in Ruby. This tutorial describes how to setup a basic monitoring configuration file for a NodeJS application, telling God to restart the NodeJS app upon the process being killed (for what ever reason).

To get started, create a god/ directory within your Node app.

mkdir /var/www/sites/nodeapp/god

In this directory, create a god configuration file

vi /var/www/sites/nodeapp/god/nodeapp.god

Update the global God configuration file (Refer to previous tutorial on installing God on Ubuntu 12.04) with the location of your Node app config.

sudo vi /etc/god.conf
God.load '/var/www/sites/nodeapp/god/*.god'

Great, when you reload God it will start using the configuration, but first we must write the configuration file. Open your nodeapp.god config file for editing. We will start off by creating a basic configuration file that will allow you to:

  • Start node
  • Stop node
  • Restart node

Continue reading

Install God background process monitoring on Ubuntu 12.04

God, a monitoring framework written in Ruby is easy to configure, easy to extend and easy to use. God allows you to monitor the state of a process (whether it is running or not) and perform specific tasks dependent upon the state. These tasks can be as simple as restarting the process or go as far as alerting you via email, text, a phone call – basically, anything you can programmatically do in Ruby.

This tutorial shows you how to setup God on Ubuntu 12.04 (and I’m pretty sure it would work for earlier versions of Ubuntu too). I will cover the installation and layout of configuration files, as well as setting up an init service script allowing for God to be started|stopped|restarted easily, and automatically started at boot. Continue reading

Paginate arrays with will_paginate

There may come a time when you wish to paginate an ordinary array of objects, as opposed to an ActiveRecord collection. Thankfully will_paginate supports this out of the box, with very little work.

Firstly, you will need to include the will_paginate array library, which comes with will_paginate. To do this either create or add to an existing initializer in config/initializers/. With all projects I tend to create a file named project_library.rb. Continue reading

Ruby (Rails) constant lookup precedence

Recently I’ve been running into an interesting problem (at least, to me). Within a web application I am working on I found what I thought was a sporadic error occurring, which resulted in the need to restart Apache in order to temporarily fix it. That was, until I made a change to the controller and thus the issue appeared again, until I restarted Apache. The error:

uninitialized constant Frontend::User::ForgottenPasswordController::User

This puzzled me for quite a while, but I continued to develop while every now and again I would come up against this and look for answers. I found nothing, but knew the following:

  • User constant (model class) exists and works fine
  • This only happened in specific controllers

Jumping onto and having a chat with `workmad3` we solved the problem, and it’s a pretty simple one, once you understand how Ruby and thus Rails references constants. Continue reading

Regex: Split on uppercase

If you need to split a string based on uppercase values, for example “ComputeAsAService” in order to provide a readable string “Compute As A Service” you can do so simply by using regular expressions, in particular you can use the lookahead operator “?=”.

str = "ComputeAsAService"
parts = str.split(/(?=[A-Z])/)
>> ["Compute", "As", "A", "Service"]

Continue reading