Rubymine print current line

Posted by Jason Noble on 01/28/2012 in Uncategorized with Comments closed |

One way of debugging your ruby scripts is to print out the value of variables in different sections of your code.

Rubymine has a feature called live templates that allows you to type a short command and have RubyMine extract it in to full blown code. Some built in shortcuts exist, such as def (creates a method), desc (create a RSpec test), it (RSpec test), etc.

To create your own, go to RubyMine -> Preferences -> Live Templates. Click one of the existing templates and hit Copy.

I named mine pl (Put Line Number) and put the following content in:

puts “#{__FILE__:#{__LINE__}”

Now when I’m typing code, I can hit the following:

p “Hello”

And it will print out the following:


I’ve found this helpful for tracking down where a specific print statement is located.

Updated: Rails3 Custom Environment Variables

Posted by Jason Noble on 12/03/2011 in ruby on rails with Comments closed |

A while back, I wrote a blog post on adding custom environment variables to Rails3.

This has gotten much easier with a change made by Jose Valim back in March.

The change allows you to create your own custom configuration variables like so:

# config/environments/development.rb
Demo::Application.configure do
  config.json_url = ""
# config/environments/test.rb
Demo::Application.configure do
  config.json_url = ""

This allows you to add any configuration variables you want to your Rails app. What if you have a bunch of configuration values? You don’t want to pollute your config.* namespace. Wouldn’t it be helpful to have config.my_app.json_url and config.my_app.other_url?

That’s easy enough:

# config/environments/application.rb
Demo::Application.configure do
  config.my_app =
# config/environments/development.rb
Demo::Application.configure do
  config.my_app.json_url = ""
# config/environments/test.rb
Demo::Application.configure do
  config.my_app.json_url = ""

Now you can do the following in the Rails console:

$ rails console
>> Demo::Application.config.my_app.json_url
$ rails console test
>> Demo::Application.config.my_app.json_url

Now your Rails application will have access to all the configuration you need.


Visiting Pivotal Labs in Boulder, CO

Posted by Jason Noble on 02/17/2011 in Uncategorized |

I recently had the opportunity to visit Boulder, CO (Wiki, Map). The reason for my visit was to visit the Pivotal Labs office and spend a day pairing with them.

One of the cool/interesting features of the Pivotal office is that the company provides breakfast in the morning. I walked into the office to find two quiches, pears, strawberries, Orange Juice, Milk, Coffee and several choices of breakfast cereal.

The day started out with a standup. We then split off into pairs and worked on our respective projects. It was interesting to be thrown into the fire and within a half hour I was working on a large, well known website, implementing features that are now live on that site.

We split for lunch around 11:30. After lunch we switched pairs and I worked on a different portion of the code. Pivotal has a strong TDD/BDD approach to coding. We wrote tests that failed, then wrote the code to make them pass. After all the tests passed, we refactored. This is what Rails development is supposed to be.

The afternoon/evening was rounded out with a team retrospective meeting. After the meeting, the office all joined in for a game of StarCraft II.

I thought my interview/pairing day went really well, and I’m happy to say that I’m moving to Boulder to start working for Pivotal Labs March 14th.

Here’s some pics:

The Snow was falling as I arrived at Denver International Airport

The Pivotal office has a full size, full time ping-pong table

This is the view from the office.

The spotting scope is from a Russian Destroyer. One of the Pivots said during the summer you can see mountain climbers climbing the distant mountains. The large grill is for hosting summer parties.

This is from across the street. Pivotal Labs is on the second floor. Ted’s is an easy lunch.


Rails3 Custom Environment Variables

Posted by Jason Noble on 02/14/2011 in ruby, ruby on rails |

I recently saw a question on Stack Overflow regarding custom variables that have different values based on which environment you are running for Rails.

It turns out it’s very easy to accomplish.

# config/initializers/configuration.rb
class Configuration
  class << self
    attr_accessor :json_url

This gives you access to a Rails variable called Configuration.json_url. Now we just need to initialize this value in our environment files.

# config/environments/development.rb
#   Put this inside the ______::Application.configure block
config.after_initialize do
  Configuration.json_url = ""
# config/environments/test.rb
config.after_initialize do
  Configuration.json_url = ""

Now you can test it in the Rails console.

$ rails console
>> Configuration.json_url
$ RAILS_ENV=production rails console
>> Configuration.json_url

Now your Rails app has access to these variables, so you can use them in your Controllers, Models or Views as needed.

Pushing Depot to Heroku

Posted by Jason Noble on 10/31/2010 in ruby on rails with Comments closed |

I’m working my way through Agile Web Development with Rails, 4th edition by Sam Ruby.

I just finished up with Chapter 6: Creating the Application. It’s working fine on my machine, but I wanted to push it to Heroku. Here’s how I did it:

echo "gem 'heroku'" >> Gemfile
bundle install
git init
git add .
git commit -m 'Initial commit'
heroku create
git push heroku master
heroku rake db:migrate
heroku rake db:seed
heroku open

I then added a /products on the Heroku URL that came up and my Depot application is now running on Heroku.

Tags: , ,


Playing around with Conductor by DHH

Posted by Jason Noble on 10/30/2010 in ruby on rails |

A while back, I saw that DHH had published a rails engine called Conductor. I added it to my list of things to look at and tonight, I got some time to take a look.

I’m using RVM with 1.9.2p0 and rails 3.0.1.

rails new conductor && cd conductor

I edited my Gemfile and added the following line:

gem 'conductor', :git => '', :require => 'conductor/engine'

I then ran “bundle install”.

I fire up rails server and hit http://localhost:3000/conductor (as suggested by the README) and I get an error:

Routing Error

No route matches "/conductor"

Am I missing something? I need to research Rails3 engines some more.

Tags: ,

Straight HTML/CSS for a change of pace

Posted by Jason Noble on 09/29/2010 in Uncategorized with Comments closed |

I recently worked on a personal project involving HTML and CSS. My wife’s family is trying to sell a 52 acre parcel of land in Noxon, MT. They wanted a website that showed the property better than the real estate agent was able to provide (short summary, only one photo).

The site I came up with is quickly rising in the results for Montana land for sale.

Hopefully this page will help as well. </lame seo attempt>

I got Google Analytics setup and I think Google Adsense is next.

Cruise control.rb refusing to build a project

Posted by Jason Noble on 12/02/2009 in cruise control.rb, git with Comments closed |

I ran into an interesting problem at work today. I had a cruise control project that would not build the project after a commit was made. Other projects in CruiseControl.rb were working properly.

Here’s the steps I used to debug:

Login to your Cruise Control box and cd to $BUILD_DIR/projects/$PROJ_NAME/work

Run the following command. This is how CC.rb figures out if updates have been made.

git log --pretty=raw --stat HEAD..origin/master

When I ran this command, I was getting “warning: refname ‘origin/master’ is ambiguous.” returned. After some google searches, I landed upon some mailing list messages that pointed me towards the issue.

The reason git was complaining about origin/master being ambiguous was that someone created a tag named “origin/master” (the beating has been scheduled).

I had to delete this tag locally by running the following command.

git tag -d origin/master

Then I had to delete the remote branch by running the following.

git push origin :refs/tags/origin/master

Now the CC server is working properly.

Tags: , ,

Testing syntax highlighting

Posted by Jason Noble on 09/10/2009 in Uncategorized with Comments closed |
public class HelloBlogger {
  public static void main(String [] args) {
    System.out.println("Hello Blogger!!");

rspec file is newer than

Posted by Jason Noble on 09/10/2009 in rspec simple_matcher custom_matcher be_newer_than with Comments closed |

My pair and I were working on implementing LessCSS at work this week and we ran into an interesting problem. We wanted to write RSpec tests that would figure out if the .less file was newer than the .css file, and if so provide a good error message.

We discussed this with Hosh and he suggested using a custom matcher, which we had not heard of before. In researching custom matchers, we came up with the following solution:

def be_newer_than(new_file, msg=nil, msg2=nil)
  simple_matcher do |old_file, matcher|
    old_file_mtime = File.stat(old_file).mtime
    new_file_mtime = File.stat(new_file).mtime
    matcher.description = "be newer than #{new_file.inspect}"
    matcher.failure_message = msg || "expected #{old_file.inspect} to be newer than #{new_file.inspect}"
    matcher.negative_failure_message = msg2 || "expected #{old_file.inspect} to be older than #{new_file.inspect}"

   old_file_mtime >= new_file_mtime

This allows you to do the following:

css_file = "site.css"
less_file = "site.less"
css_file.should be_newer_than(less_file)

This will tell you if css_file is newer than the less file.

The optional arguments allow you to pass custom error messages. For example:

  it "should be up to date" do
    output = "#{css_file} is not up to date.  Please run the following: "
    output += "\n\t lessc #{less_file}\n\n"
    css_file.should be_newer_than(less_file, output)

Copyright © 2008-2018 Jason Noble's Technical Adventures All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.2.3, from