Journeymandev's Notebook

General ramblings, things I don't want to forget, and an occasional rant.
The “goto” raptor sits on the top of my cubicle, guarding the area’s code.

xkcd goto

The “goto” raptor sits on the top of my cubicle, guarding the area’s code.

xkcd goto

Reading list. Obviously I need to read the David Allen book first.

Reading list. Obviously I need to read the David Allen book first.

Rails, Growl and Windows?

Lately I have been developing Rails apps in Windows. Don’t judge. During that time I tried multiple installation techniques from RVM in Cygwin, Ruby Installer to JRuby. The clear winner, at least for me, was JRuby. Since I like the way JRuby has been treating me, I thought I would do a high level post documenting my setup. I make the assumption that you are familiar with Ruby and Rails, and that you have enough experience to install Java and supporting applications.

Environment

As of this writing I use Windows 7 (64 bit) Professional, Java 1.7.0 (64 bit), JRuby 1.6.5, and Rails 3.1.1 but I believe these steps will be applicable for varying configurations. To get started developing in Ruby or Rails on Windows, we will need to download and install the following programs.

Java

The “J” in “JRuby” means Java. We need to download and install the flavor of JDK (32 bit or 64 bit) that is appropriate for our system.

JRuby

"JRuby is a 100% Java implementation of the Ruby programming language. It is Ruby for the JVM." That pretty much sums it up. Visit the JRuby site for the benefits of using JRuby over other implementations. My reason for using JRuby is that in my Windows experience JRuby executes faster than MRI. Installation is painless with the provided installer. Be sure to check the box to “add paths to your environment”.

Growl

Does watching the Railscasts, or Peep Code screen casts make you jealous of their Growl notifications? No more! Growl is available for windows now. When used in combination with autotest and autotest-growl it is an indispensable tool for easily tracking the status of our unit tests. Go ahead download and install Growl now.

Developing

Once we have completed installation of Java, JRuby and Growl, we can begin setting up our application.

Open up a command prompt and install the Rails gem. I already had Rails installed so do not be surprised to see gem automatically install other dependecies. Notice that in JRuby commands are preceded with a ‘j’ so instead of ruby, gem, irb we will use jruby, jgem, jirb.


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\nate>jgem install rails
Successfully installed rails-3.1.1
1 gem installed

C:\Users\nate>

Now all we have to do is create our Rails app. Please note the -S argument to the jruby command. This is the recommended way to run jruby commands as documented here.

C:\Users\nate>jruby -S rails new testapp

At this point Rails will produce lines describing the creation of directories and files. Rails will also call Bundler and install those gems required by Gemfile.

Now we have a working Rails app. Just cd into the directory and run it!


C:\Users\nate>cd testapp

C:\Users\nate\testapp>jruby -S rails s
=> Booting WEBrick
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-10 18:16:03] INFO  WEBrick 1.3.1
[2011-11-10 18:16:03] INFO  ruby 1.9.2 (2011-10-25) [java]
[2011-11-10 18:16:03] INFO  WEBrick::HTTPServer#start: pid=5348 port=3000

Point the browser to http://0.0.0.0:3000 to view the default rails app in action. To stop the server issue Ctrl-C twice. Proceed to setting up autotest!

Growl & Autotest

Here comes the fun part. The default install of Growl is all we need. So the only Growl configuration we have to do is to choose a notification theme, which I will leave for you. We just need to make sure Growl is running after we have installed it. Check for a claw in the system tray.

To get Growl notifications for autotest we need to install some supporting gems. Add the following lines to the Gemfile and run bundle install. I use rspec so I include rspec and rspec-rails to the Gemfile.


gem 'rspec'
gem 'rspec-rails'
gem 'autotest'
gem 'autotest-notification'
gem 'autotest-growl'
gem 'autotest-rails'

Tell autotest that we wish to use autotest-growl. In the .autotest file in the root directory of our application, add the following line.

reqiure 'autotest/growl'

Install rspec using the generator.


C:\Users\nate\testapp>jruby -S rails g rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb


Now we will create an ‘article’ model using scaffolding.


C:\Users\nate\testapp>jruby -S rails g model article
      invoke  active_record
      create    db/migrate/20111111005801_create_articles.rb
      create    app/models/article.rb
      invoke    rspec
      create      spec/models/article_spec.rb


Thats it! Run autotest! Below is the console output with the deprecation and console color warnings removed.


C:\Users\nate\testapp>jruby -S autotest
loading autotest/rails_rspec2

--------------------------------------------------------------------------------

Pending:
  Article add some examples to (or delete) C:/Users/nate/testapp/spec/models/article_spec.rb
    # Not Yet Implemented
    # ./spec/models/article_spec.rb:4

Finished in 14.88 seconds
1 example, 0 failures, 1 pending


If everything went well, we should see an application registration notification and a test result notification from Growl. Happy testing!

Rails, Growl and Windows?

Lately I have been developing Rails apps in Windows. Don’t judge. During that time I tried multiple installation techniques from RVM in Cygwin, Ruby Installer to JRuby. The clear winner, at least for me, was JRuby. Since I like the way JRuby has been treating me, I thought I would do a high level post documenting my setup. I make the assumption that you are familiar with Ruby and Rails, and that you have enough experience to install Java and supporting applications.

Environment

As of this writing I use Windows 7 (64 bit) Professional, Java 1.7.0 (64 bit), JRuby 1.6.5, and Rails 3.1.1 but I believe these steps will be applicable for varying configurations. To get started developing in Ruby or Rails on Windows, we will need to download and install the following programs.

Java

The “J” in “JRuby” means Java. We need to download and install the flavor of JDK (32 bit or 64 bit) that is appropriate for our system.

JRuby

"JRuby is a 100% Java implementation of the Ruby programming language. It is Ruby for the JVM." That pretty much sums it up. Visit the JRuby site for the benefits of using JRuby over other implementations. My reason for using JRuby is that in my Windows experience JRuby executes faster than MRI. Installation is painless with the provided installer. Be sure to check the box to “add paths to your environment”.

Growl

Does watching the Railscasts, or Peep Code screen casts make you jealous of their Growl notifications? No more! Growl is available for windows now. When used in combination with autotest and autotest-growl it is an indispensable tool for easily tracking the status of our unit tests. Go ahead download and install Growl now.

Developing

Once we have completed installation of Java, JRuby and Growl, we can begin setting up our application.

Open up a command prompt and install the Rails gem. I already had Rails installed so do not be surprised to see gem automatically install other dependecies. Notice that in JRuby commands are preceded with a ‘j’ so instead of ruby, gem, irb we will use jruby, jgem, jirb.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\nate>jgem install rails
Successfully installed rails-3.1.1
1 gem installed

C:\Users\nate>

Now all we have to do is create our Rails app. Please note the -S argument to the jruby command. This is the recommended way to run jruby commands as documented here.

C:\Users\nate>jruby -S rails new testapp

At this point Rails will produce lines describing the creation of directories and files. Rails will also call Bundler and install those gems required by Gemfile.

Now we have a working Rails app. Just cd into the directory and run it!

C:\Users\nate>cd testapp

C:\Users\nate\testapp>jruby -S rails s
=> Booting WEBrick
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-10 18:16:03] INFO  WEBrick 1.3.1
[2011-11-10 18:16:03] INFO  ruby 1.9.2 (2011-10-25) [java]
[2011-11-10 18:16:03] INFO  WEBrick::HTTPServer#start: pid=5348 port=3000

Point the browser to http://0.0.0.0:3000 to view the default rails app in action. To stop the server issue Ctrl-C twice. Proceed to setting up autotest!

Growl & Autotest

Here comes the fun part. The default install of Growl is all we need. So the only Growl configuration we have to do is to choose a notification theme, which I will leave for you. We just need to make sure Growl is running after we have installed it. Check for a claw in the system tray.

To get Growl notifications for autotest we need to install some supporting gems. Add the following lines to the Gemfile and run bundle install. I use rspec so I include rspec and rspec-rails to the Gemfile.

gem 'rspec'
gem 'rspec-rails'
gem 'autotest'
gem 'autotest-notification'
gem 'autotest-growl'
gem 'autotest-rails'

Tell autotest that we wish to use autotest-growl. In the .autotest file in the root directory of our application, add the following line.

reqiure 'autotest/growl'

Install rspec using the generator.

C:\Users\nate\testapp>jruby -S rails g rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb

Now we will create an ‘article’ model using scaffolding.

C:\Users\nate\testapp>jruby -S rails g model article
      invoke  active_record
      create    db/migrate/20111111005801_create_articles.rb
      create    app/models/article.rb
      invoke    rspec
      create      spec/models/article_spec.rb

Thats it! Run autotest! Below is the console output with the deprecation and console color warnings removed.

C:\Users\nate\testapp>jruby -S autotest
loading autotest/rails_rspec2

--------------------------------------------------------------------------------

Pending:
  Article add some examples to (or delete) C:/Users/nate/testapp/spec/models/article_spec.rb
    # Not Yet Implemented
    # ./spec/models/article_spec.rb:4

Finished in 14.88 seconds
1 example, 0 failures, 1 pending

If everything went well, we should see an application registration notification and a test result notification from Growl. Happy testing!

lesson remembered #322 Subtlety is important

Not understanding what was going on with the bug I wrote about in my previous post was driving me crazy. So, I asked the question on Stack Overflow. The answer reminded me that understanding the subtlety of a language is important.

lesson learned #432 (an error of omission)

the bug

Yesterday I introduced a “not so obvious” bug into my code. This particular bug took the form you see below.

It took a bit of searching Ruby docs and playing with the code to see the problem. It was an error of omission. File.open.readlines does exactly as expected and returns an array containing all of the lines in the file. Yes, but look what immediately follows that arrray. A block. The array returned by readlines calls no member methods. The block has nothing calling it so it does nothing. Unlike other languages, where blocks are just scope delineators, Ruby blocks are smarter. The block is not being asked to execute, so puts line never gets called.

the fix

The fix is extremely simple. Just ask the array to do something, like iterate over each element. Or even better call the each_line method and remove the need for readlines all together.

Sure this is somewhat trivial, but errors of omission, which do not throw exceptions or produce an error, are difficult to track down. This post serves as a reminder for me not to re-create this mistake. Was it self-indulgent? Sure, but aren’t all blog posts?

MySQL, Rspec, Windows 7

By default, MySQL installs in Windows 7 with strict sql_mode turned on. This causes the following error when validating date fields with Rspec.

The solution is to change the MySQL configuration to remove strict SQL


I got this info from an article found on HelpDeskPilot here.

Amazon Web Services

I consider myself a fairly technical guy. Who am I kidding, I’m a geek. I love to learn new things, different programming languages, technologies, electronics, heck even stuff not related to technology like cooking, woodworking, art. And I’m a high level novice at most of those things, except art. All of that said, for the life of me, I can’t figure out Amazon’s Web Services pricing/usage structure.