"They sound a little tired and frustrated, don’t they? That’s the sound of legacy code."

— Giles Bowkett - Rails as She is Spoke

tech-angels:

Tired of writing long git paths to github repositories in Gemfile? Then you will find this useful. When the repository you need is public, you can use :github shortland instead of :git. And just specify github username and repository name separated by slash.

If repository name and username…

(Source: tech-angels)

The Last Train

"No distance of place or lapse of time can lessen the friendship of those who are thoroughly persuaded of each other’s worth." — Robert Southey

It occurred to me that once I stepped onto the train this morning it will be my last time for what will probably be quite a while. Moving to a new state at the end/beginning of a year really drives the point home. There is a definite feeling of closure and new opportunity.

That got me thinking about my journey ahead and how I ended up at this point. I’d like to thank the people around me that helped define who I am in my career path.

It pretty much started with myself and a pirated copy of Agile Web Development that led me to find others interested in Ruby programming. It was a tough time but that is when I stumbled into Ray Hightower leading a Ruby Meetup in a library meeting room. Thanks Ray, my involvement in ChicagoRuby, I feel, is what really moved my career into the fast path.

Next up is Dave Giunta, Courtney Braafhart, and Jim Hassan who believed in me enough to take a chance and give me my first full-time Ruby dev position. Thanks… I was crazy nervous trying to play it cool in my interview (with my pinstripe suit). This is also where I met Adam Walters, Chris Hallendy and Stephen Korecky. Who have become good friends and I’m always learning from each of them.

This is about where I attended an Obtiva TDD Bootcamp taught by one Dave Hoover. Dave must have been semi impressed with me cause he asked if I was interested in trying out for Obtiva shortly after that. Of course I jumped at the chance to work along side people I looked up to in the dev community. So thanks Dave Hoover, Kevin Taylor, Todd Webb and Kat Reid. That quadruple interview was intense and I know I bombed Kevin’s interview but again… thanks for believing in me.

I can say that once I started with Obtiva it was Noel Rappin, Joe Banks, and Chad Pry that really put up with me and taught me to become a half way decent dev.

Now my journey continues to Florida to join the Hashrocket family. It is my honor to be a small part of another great dev shop. So thank you, Hashrocket, for taking me on and letting me continue this crazy career path I’ve set myself on.

To all who were mentioned and those that were not… thanks for the friendship and experiences. They will not be forgotten.

minimalmac:

So, the Internet is shaking with the power of ten thousand wagging fingers over Go Daddy’s support of SOPA, the evil legislation that threatens everything we know and hold dear about the ‘verse. It is even so evil that it threatens the things we don’t care about too.

I have never used Ho Daddy…

Initialize those Settings

http://www.flickr.com/photos/whiteoakart/

When starting a Rails project you will generally start loading in your ‘goto’ gems. You know, the ones that you are familar with and provide quick value for you and your project.

One of these for me is settingslogic. This has always been one of my first setup steps. This gem is great. It allows you to set your application settings in a YAML file and then gain access to that data in normal ruby object method calling syntax.

ex: Settings.aws.secret

Cool… now we’re on the same page. It’s a pretty simple gem to set up to boot! Just add it to your Gemfile to get started.

In my example above I was using a Settings constant. Let’s get that created. In an initializer I would create a file settings.rb.

ex: config/initializers/settings.rb

class Settings < Settingslogic
  source "#{Rails.root}/config/settings.yml"
  namespace Rails.env
end

That was easy! We’re just telling Settingslogic where to look for our config file and how to figure out different namespaces. Namespacing is key here because it allows us to have different setting entries based on environment. Now you are able to enter test keys for your payment gateway instead of the live production keys.

ex: config/settings.yml

defaults: &defaults
  use_online_storage?: false
  aws:
    access_key: longstringofchars
    secret: supersecret
    bucket: immabee-usin-settingslogic

development:
  <<: *defaults

test:
  <<: *defaults

production:
  <<: *defaults
  use_online_storage?: true

Now the fun part… lets use this bad dog. Say I want to upload some files using the fantastic Carrierwave gem. This is about how your settings would look like.

ex: config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: 'AWS',
    aws_access_key_id: Settings.aws.access_key,
    aws_secret_access_key: Settings.aws.secret
  }
  config.fog_directory = Settings.aws.bucket
end

Notice how I’m just gaining access to my settings via the Settings constant using what appears to be method chaining? Pretty cool, right? This is not really a new concept, I just think Settingslogic encapsulates this functionality well.

If you peek back up at our settings.yml, you should notice that the method chaining maps cleanly to the nesting of the YAML file… easy peasy.

That’s pretty much it. Now, funny thing, the reason I started writing this article was to show you some tips I found valuable. Thought I should set up the article with an overview of Settingslogic so we’re all on the same page.

If you had the above code implemented and tried to start your server or console you will most likely hit a brick wall. By chance you were following along… this may look familiar:

uninitialized constant Settings (NameError)

Gross, right? What the hell is it talking about? If you were to use the Settings constant anywhere else in your app this would probably not be a problem. This issue has to do with the order in which files are getting loaded in our app. We’re trying to use Settings before it has been evaluated.

I hit this wall a lot because a lot of times the reason I want to use this method is to cleanse my initializers of data points that shouldn’t be stored as part of my app like various api keys.

Rails loads initializers top down in alphabetical order. This should be no surprise that the ‘s’ in settings.rb is coming after the ‘c’ in carrierwave.rb. ‘That sucks!’, you say? The fix is pretty simple, you just need to think out of the box a little. Just rename your settings.rb file to _settings.rb. This now reorders its place in the alphabetical listing and allows the Settings constant to get loaded before your other initializers.

Hooray, settings goodness can now be had by all!

  • Daughter 1: which one is that?
  • Me: uranus
  • Daughter 2: I know my anus.
"Anything that plays in the forties or fifties and i’m there. Actually I wish i was born back then. That was a great era. Except the lack of Twitter. That makes me be like “Eh, never mind”. But if the forties and fifties had Twitter, I’d be like “YES, put me there… hashtag Gee Willikers”."

— Ryan Connolly

Digging for XPath Treasure using Chrome

http://www.actionrecon.com/2010/10/professor-longhair-big-chief-show-off-their-parkour-skills/ I was never a fan of using XPath in my cucumber step definitions… mostly because I didn’t really understand how it worked.

Recently I had the chance to work with some people that use XPath way more than I do and I extracted this nugget of info from them. (Thanks John!)

You can use $x in the Chrome javascript console. No extensions needed.

$x("//img")

I’ve seen a few questions on StackOverflow about this and all the answers related to installing a chrome extension. I thought it was definitely worth writing down.

RVM Ruby Install on Lion Got You Down?

After a fresh install of OSX Lion, RVM decided no more of my ruby friends could come over and play. So I was all like “what’s up, RVM… y u no like my ruby exchange students anymore?”

Turns out Lion made some changes to what default compiler is getting used which makes building ruby via RVM unhappy. After some searching, the fine folks over at StackOverflow are full of win again.

Here is the solution that works for me:

CC=/usr/local/bin/gcc-4.2 rvm install <ruby version>

It was recommended that the CC variable declaration could be put in your profile reducing the need to enter it every time, but I’m uncomfortable just blindly making that change. If this is the only time I need to do this, I think I’m OK with it.