The Blog

Posts from November 2010

Nov 30

To Version or Not To Version Your Gems in Gemfiles

By David Czarnecki

I don’t like moving targets. I’m a software developer, not a sharpshooter. So why don’t more people version all of their gems in a Gemfile?

Here is a sample Gemfile for a Rails 3 application I was looking at yesterday.

{% gist 721842 %}

The gems for Rails and thin have been versioned. Why aren’t the gems for will_paginate, nokogiri, and haml versioned? I consider un-versioned gems moving targets. Why? You’re going to get the latest version of a gem. The developer doesn’t know (or necessarily care) you depend on XXX functionality in version 1.0.23 of their gem. And so what if in version 2.0.0 of their gem, they make incompatible changes that break your application? I consider versioned gems a virtual “stake in the ground”. To the best of my abilities, with rigorous testing of course, I know that given these specific versions of gems, my application performs as expected.

What’s your opinion?

UPDATE:

Good point from my co-worker, Blake, who says that bundle will install the lastest version of a gem and then lock the version in your Gemfile.lock file on the first go-round. It could still be an issue if you do a “bundle update” locally or in your deployment process.

You can find more hilarity over on my Twitter account, CzarneckiD.

Nov 30

A Better Way to Avoid a Project Named Server

By Blake Taylor

Yesterday I posted about how I avoided creating the annoying rails server projects when accidently running rails server under a rails 2 application. I wanted to follow up with a much more concise script that accomplishes the same ends through different means. Using this script requires no changes to how you start the development server and, even cooler perhaps, allows you to start the rails 2 server as if you were in a rails 3 project. Shout out goes to Intern Mike for the assist.

{% gist 722473 %}

Nov 29

Moving to Rails 3 Pain Point: rails server

By David Czarnecki

Update: I have posted a better solution!

Working with rails 2 and 3 projects back and forth, day to day has been pretty painless thanks to rvm and .rvmrc files. That is with the exception of accidentally running rails server on a rails 2 project. I do this all the time and it results in generating a new rails project called server rather then starting the rails server, my actual intention. It’s almost as frustrating when running script/server on a rails 3 project but at least it doesn’t spit out a bunch of useless files. Incidentally, all of the built in rails command (i.e. generate, console, …) set the same trap. To avoid falling prey, I have created a bunch of shell functions which I would like to share with everyone in case they would like to be privy as well.

The shell code is included in the gist below. I load these functions into my .bashrc file (actually my .zshrc file). Once they are are available just get in the habit of running rails-server or rails-generate or rails-whatever and the correct command will always be issued. Also, if anyone knows a better solution, do share!

As one final note, I run rails-server so often that I have is aliased to s . If you would like to do the same add alias s=rails-server to your .bashrc file.

{% gist 720619 %}

Nov 24

Interactive Git Stash For Stashing Single or Multiple Files

By David Czarnecki

TL;DR git stash save –patch

From the git docs, “With –patch, you can interactively select hunks from in the diff between HEAD and the working tree to be stashed.”

This past week, I came across a situation where I wanted to stash a couple of working files in a git repository, pull in some changes, and then apply the stash. However, I couldn’t immediately see the forest for the trees or some other stupid metaphor. Basically it was just a case where I had to RTFM for git stash. In the gist below, I go through a simple example of stashing 2 out of 3 files, making some changes to the repository, and then applying the changes of the 2 stashed files.

{% gist 714660 %}

I hope you found this example useful. I know that it’s some git-fu I’ll be using more often.

You can find more hilarity over on my Twitter account, CzarneckiD.

Nov 23

Halo::Reach::API.new

By David Czarnecki

If you’ve ever wanted to access your Halo:Reach statistics from Ruby, you can now using the Halo:Reach Ruby gem.

The API methods should be pretty self-explanatory and you can check out the gem’s RDoc online or look at the unofficial API method documentation for more information. Maybe the one caveat to getting involved in the project or using the API in general is that you need a Bungie Pro account to generate an API key. This will cost you 750 MS points per year. An 800 MS point pack will cost you $10.

You can also get involved in the development of the API over on the Halo:Reach Ruby API GitHub project.

You can find more hilarity over on my Twitter account, CzarneckiD.

Nov 23

Agora Games & Major League Gaming participate in the web's first multicast transmission

By David Czarnecki

When you send a unicast message it gets routed within a network to a single destination.  Unlike unicast messages, multicast messages get delivered to every node within a network.  If not properly controlled however you can experience routing loops which, like feedback between a microphone and a speaker, cause what networking techs call “multicast storms”.  Because of this many corporate networks block multicast messages from ever leaving a single broadcast domain.  For the same reason, multicast messages are blocked by all Internet Service Providers at the network’s edge.

Apparently it was just a matter of time until someone with a big enough backbone started letting them through.

On November 12, 2010 during Major League Gaming’s National Finals in Dallas we working with AT&T and Octoshape to deliver the first open-web multicast video stream.  Who doesn’t love the bleeding edge?

Check out the details here:

http://www.attinnovationspace.com/2010/11/23/first-ever-open-web-multicast-event/#more-523

More musings can be found on my Twitter account, genexp

Nov 22

Winning at the Career Fair (A How-to)

By Clarke Foley

Recently I had the pleasure of representing Agora Games at two Western New York career fairs held at RIT and my alma mater, University at Buffalo. It was a interesting experience to be on the flip side of the job search process for a change, sitting at our table answering questions, taking resumes, and evaluating applicants' skills to see if they might be the right fit for our team.

One question that was asked repeatedly by fair-goers over the course of the two events was, ‘What skills do I need, or what courses should I take, to be the best candidate to work at your company?’. This was a tough question to answer.

The best answer that I could give was, ‘There is no predefined skill-set. Today we are looking for Ruby on Rails developers, but tomorrow that may change. In a few months we may be looking for C++ or PHP or Flash devs depending on what we need at the time, so there’s no real way to say.’

To hear that probably sounds like a kick in the pants, like there’s no way to prepare yourself, but the truth is that the software industry changes so fast that there really isn’t any way to predict what technologies will be in style or what skills will be in demand tomorrow. However, there are things you can do to distinguish yourself from other candidates despite this ugly truth. I offered the following prescription:

  1. Release code. Find or start a project that you’re excited about and contribute. It doesn’t matter what language or framework, but just get something out there. The best candidates that we found were the ones that showed initiative and put forth extra effort in some little hobby project that they posted on sites like github.

  2. Get involved. Pick a conference or local user group on some topic that interests you and go! Conferences such as RailsConf, RubyConf, Game Developers Conference (GDC ), and even Penny Arcade Expo (PAX) offer great opportunities to meet and interact with like-minded developers. What could be more fun than hacking on a project together with your new friends? Maybe some of that code could even be released back into the community, or used as samples to show a future employer… hmm…

In the end, the answer is to do what you love. If your goal is to code, then so do. Get involved and code. The code you produce, experience you gain, and connections you forge will have a beneficial side-effect of making you stand out in any future job search despite any new trend.

Nov 22

Going All The Way With factory_girl and rails3-generators

By David Czarnecki

I responded to a few tweets from Barrett Clark about factory_girl noting that you can get a lot more functionality out of factorygirl than just replacing fixtures. However, let’s keep things simple to start and just replace fixtures with factorygirl in a simple Rails 3 application.

I want to replace fixtures in my new Rails 3 projects with factories. One of the best ways of doing that is to start a new Rails 3 project. Let’s do that.

{% gist 710407 %}

To add factorygirl functionality, as well as functionality for factorygirl generators, we need to pull in a few gems into our Gemfile.

{% gist 710412 %}

Run “bundle install” to install the gems. Now let us add a scaffold for a person with firstname and lastname attributes.

{% gist 710417 %}

BOOM! We specified a fixture replacement when generating our scaffold using “-r factory_girl”. You will also notice that the scaffold generated a people factory in test/factories/people.rb.

{% gist 710424 %}

That factory looks remarkably similar to a fixture, eh? Great, we are ready to run rake and deploy this application to Heroku.

{% gist 710427 %}

Uh oh. Our functional test for the people controller is still living in fixtureville. So, we need to change that test’s setup method to use a factory, not a fixture.

{% gist 710439 %}

And if we run our tests again, SUCCESS!

{% gist 710441 %}

If factory_girl and rails3-generators are tiring you out, you can always fake it. There is also an ASCIIcast that also describes Generators in Rails 3. You can find more hilarity over on my Twitter account, CzarneckiD.

Nov 21

Pretty MySQL listings

By Jason LaPorte

Tired of MySQL wrapping long rows when running selects from the command line?  Here’s a crazy useful tip:  add \G to the end of your ‘select’ statement and your output will go from gobbledygook to great.

Here’s an example:

{% gist 709399 %}

Nov 19

HTML and CSS Horizontal Delimited Navigation Done Right

By Joshua Childs

When we, as front-end developers, set out to build a horizontal site navigation, what markup come to mind? Thoughts of a standard semantic design pattern, an unordered list (UL) with list items (LI) floated to one side, possibly with delimited items to help visually separate each link.

This design pattern generally produces markup that looks something like:

{% gist 704052 %}

And styling like: {% gist 704057 %}

This doesn’t look so bad, but there’s a problem. Those pipes (|) don’t belong in the markup. Because they don’t describe any piece of the document, and they are not content, they are purely presentational. As such, they belong in the presentation layer (stylesheets).

For a some time now, front-end developers have had to settle for mixing content and presentation in order to maintain a single experience across browsers and platforms due to inconsistent implementations of css2.

Today, notions of one user experience for a website have been shattered by paradigm shifts such as increased market penatration of mobile browsing devices. This shift combined with improved client support for css2 and css3 modules, as seen in IE9pr3, has given us the freedom to build similar but different experiences for users. We are free to build on strengths of each browser while accepting that some browsers may not fully support the presentational features desired.

With that in mind:

{% gist 704060 %}

Our navigation markup now looks the way it should, meaning it’s a list of links in no particular order, with only relevant content. There are no pipes (|) or other delimiters meant only for presentation purposes. The wrapping DIV element has been substituted with a NAV element to be more descriptive.

The following CSS does the same basic styling as the first, but notice the last two rules. {% gist 704064 %}

The last two rules are how we’re able to put those delimiters in the presentation layer. Let’s take a closer look. {% gist 704067 %}

This rule is adding the pipe (|) delimiter to all of the list (LI) element that have nav.site-nav as their ancestor. {% gist 704069 %}

And here we look up the last list item (LI) of our unordered list (UL) and remove the pipe delimiter (|) we added with the previous rule.

Some of you may be saying that this won’t work in all browsers (< IE9pr3, < FF3, < Safari4, ect). This is true, it won’t work in all browsers, but when you’re thinking about doing something like this, ask yourself, “Do I need this for users to be able to use my site?” If yes, then by all means put those load bearing delimiters in your markup. If no, enjoy the knowledge that you can have a more semantic html document, a stylesheet file that takes advantage of modern implementations of css, and a flexible user experience that degrades gracefully in older browsers. Make the move to more cleanly separated content and presentation layers.

You can find more of my musings on the Twitters,  @JoshuaChilds.