Sunday, December 07, 2014

Grunt-based JavaScript CodeShip build

I have been playing around with CodeShip lately. I really like it! Here's what I'm doing for Grunt-based builds on CodeShip, running the Jasmine specifications on Karma with PhantomJS.

Setup Commands

gem install compass
nvm install 0.10.33
nvm use 0.10.33
npm install
npm install -g grunt-cli
npm install -g bower
bower install


Test Commands

grunt test

Thursday, December 04, 2014

Creating a Rails 4.1 app using JRuby

Notes around creating a Rails 4.1.8 application on JRuby 1.7.16.1.


Creating application

Using RVM to manage my rubies.

rvm use jruby-1.7.16.1
gem install rails
rails new .

Configuring Rails app for PostgreSQL and JDBC

Add the following to the Gemfile.

gem 'activerecord-jdbcpostgresql-adapter'

Also add the following towards the top of the Gemfile.
ruby '1.9.3', :engine => 'jruby', :engine_version => '1.7.16.1'

My Gemfile as it currently stands:

source 'https://rubygems.org'

ruby '1.9.3', :engine => 'jruby', :engine_version => '1.7.16.1'

gem 'rails', '4.1.8'
gem 'activerecord-jdbcpostgresql-adapter'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'therubyrhino'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'puma'

Configuring database.yml

Set up your databases environments, similar to what I have here:

default: &default
  adapter: jdbcpostgresql
  encoding: unicode

development:
  <<: *default
  host: localhost
  database: foobar_development
  username: postgres
  password: postgres

test:
  <<: *default
  host: localhost
  database: foobar_test
  username: postgres
  password: postgres

production:
  <<: *default
  host: localhost
  database: foobar_production
  username: postgres
  password: postgres

Tuesday, September 02, 2014

Exposing PostgreSQL on vagrant to host OS

I've been working with vagrant lately on a Ruby project and I wanted to the ability to view the PostgreSQL database on the vagrant image through DbVisualizer on my OS X system. This is quite easy to set up in PostgreSQL and vagrant.
  1. Add a port forwarding entry to your Vagrantfile: config.vm.network "forwarded_port", guest: 5432, host: 15432. I'm using Vagrant 1.6.3 here. Start/restart your Vagrant image.
  2. Edit the pg_hba.conf file on the vagrant image. This file may reside in different areas; ours was in /etc/postgresql/9.1/main/. Change the IPv4 local connections entry from...

    host    all             all             127.0.0.1/32            trust
    

    to

    host    all             all             0.0.0.0/0               trust
    

  3. Restart PostgreSQL on the vagrant image: sudo service postgresql restart
  4. Configure your database tool to connect to localhost, port 15432.
You should be able to connect to your Vagrant PostgreSQL databases now.

Wednesday, June 18, 2014

NAT port forwarding in VMware Fusion 6

More of a reminder to myself than anything. Found this blog posting really helpful for enabling NAT port forwarding in a VMware Fusion 6 virtual machine. Important that you restart VMware Fusion after making this change. Just restarting the VM will not pick up the change to nat.conf.

Monday, May 05, 2014

Resolving issue with Yeoman-generated Angular web project and the jasmine framework provider

I'm kicking off a new Angular web client project today and I'm using Yeoman to get me up and going here. Seems the angular-generator for Yeoman doesn't properly link in the plugins needed for running Jasmine specs within karma, reported on this StackOverflow question. Add the following to your karma.conf.js file in the project root directory:
plugins: [
    'karma-jasmine',
    'karma-coverage',
    'karma-junit-reporter',
    'karma-phantomjs-launcher',
    'karma-chrome-launcher',
    'karma-safari-launcher',
    'karma-firefox-launcher',
    'karma-ie-launcher'
],
I also needed to install these node packages and save the configuration to the package.json file:
npm install karma-jasmine --save-dev
npm install karma-coverage --save-dev
npm install karma-junit-reporter --save-dev
npm install karma-phantomjs-launcher --save-dev
npm install karma-safari-launcher --save-dev
npm install karma-firefox-launcher --save-dev

Tuesday, April 22, 2014

Using the pound key as a valid choice in a Tropo ask

More of a reminder to myself, but might be useful for others, as I found this through trial and error. We have an ask in our call flow that wants to capture the pound key (#) as a valid choice. Seems easy enough, just add the pound symbol '#' as a choice to the choices array. But that alone doesn't work. You also have to assign a different terminator to the ask (e.g. '*'). You won't actually use the terminator, but reassigning the terminator to something other than '#' seems to free '#' up to be used as a valid choice.

Monday, March 31, 2014

Getting websocket-rails up and running on Heroku

I wanted to document my endeavors to get websocket-rails up and running on Heroku. In my case, I'll be adding Redis to the mix, as I'm trigger server-side events from a worker process that is running delayed_job tasks. Thus, in a multi-process environment, Redis has to be used to communicate from the worker process to the Rails process (which actually maintains the web socket infrastructure). My experiences with setting this all up were actually quite pleasant and things just worked without many issues. The documentation for websocket-rails could benefit from elaborating some non-development environment scenarios, but that's a very minor gripe.

Step 1: Get the solution running in development

Pretty straight-forward. You have to get everything working in your development environment. Nothing earth shattering here, but if you plan on triggering server-side events to your JavaScript clients from something like delayed_job, you will need to use Redis. I'm using OS X Mavericks here, so I install tools through Homebrew. Here's how I got Redis up and running in my environment:
  1. Install via Homebrew: brew install redis
  2. Start up Redis from the command line: redis-server /usr/local/etc/redis.conf
If you need to monitor Redis, use the redis-cli: redis-cli monitor Now that we have Redis up and running, get websocket-rails integrated into your application. I won't belabor how to do that--the documentation does a good job of detailing how. I use a channel to communicate from the client-side and the server-side. Another thing to note is that for anything I do on the client that I want an event for coming from the server, I use a correlation ID from the client-side that I can keep track of on the client-side, so when an event from the server-side is received, I can determine whether I'm interested in it because it contains the original correlation ID. Read more here about the correlation ID design pattern.

Step 2: Get the solution running on Heroku

Now that everything works in development, I needed to get the solution out to Heroku.
  1. If you previously installed SSL, you will have to disable it before enabling websockets support. Remove the certificates: heroku certs:remove, then remove SSL support through the Dashboard.
  2. Enable websockets support: heroku labs:enable websockets
  3. Add a Redis provider Heroku addon to the app if you haven't done that already. Note the Redis connection information.
  4. Update the websocket_rails.rb initializer with the Redis connection information. I had to add some conditional logic to determine which environment I was deployed in. Also import here is that host and port won't typically be enough to connect to a Redis add-on. You'll definitely need a password and probably a username. Those can be passed through the redis options in this initializer. Currently my websocket_rails initializer has some code in it like this:
    
        if ENV["RAILS_ENV"] == 'production'
            config.redis_options = {
                username: 'rediscloud',
                password: 'UHDDBHD&*#$DFkkdfha',
                host: 'pub-redis-88885.us-east-1-3.3.ec2.redisdomecity.com',
                port: '15204'
            }
        else
            config.redis_options = {
                host: 'localhost',
                port: '6379'
            }
        end
    
    
    This will invariably change so I can differentiate between staging and production, but you get the point.
Doing all this I was able to get the websocket-rails stuff to work and have not had any issues with it, even with dynes spinning up and down.