Archive for the ‘Programming’ Category

Quick Tip: named_scope

Have you ever found yourself writing queries like this?

User.find(:all, :conditions => ['state = ? AND created_at > ? AND created_at <= ?', 'active', start_date, end_date], :limit => 5)

I suppose you could refactor this into a custom finder that did the heavy lifting for you…

User.find_all_active_in_date_range(start_date, end_date)

But what if you need that same query where the state [...]

Read the rest of this entry »

Quick Tip: SSH Backspace

I just ran across this informative post by Jonathan Tron that solved an annoyance I’ve had for a while: backspace not doing what I want when I use SSH.
Change your Terminal Preferences

In Terminal, select Preferences | Settings | Advanced.
Select ‘Delete sends Ctrl-H’

You may need to do this again if you change your terminal style.
Specify a [...]

Read the rest of this entry »

Quick Tip: Route Associations

Are you used to writing your routes like this?
map.resources :notes do |notes|
notes.resource :author
notes.resources :comments
notes.resources :attachments
end
Don’t fret, there may be hope for you yet. For these simple routes you can use the has_one or has_many route association options.

has_one – use it for a singleton resource
has_many – use it [...]

Read the rest of this entry »

Quick Tip: has_many :through => checkboxes

It’s really easy to create a many-to-many relationship that can be assigned through checkboxes. Check it out!
Let’s say you have Users and Groups. A User can belong to a Group and a Group can have many Users – we call this a Membership, like so (migrations omitted for brevity):
app/models/user.rb
class User < ActiveRecord::Base
has_many [...]

Read the rest of this entry »

Quick Tip: Capistrano SSH Ports

If you have changed the SSH port number on your server, then you need to let Capistrano know how to connect. Luckily, it’s pretty easy.
Add the following to your deployment file, replacing 8888 with your port number.
config/deploy.rb
ssh_options[:port] = 8888
This will apply that port number to connections made by Capistrano. If you need to specify [...]

Read the rest of this entry »

Rails Class Collisions

While trying to use Integrum’s oh-so-nifty missing spec finder on a recent project, I discovered that it was not working. Hmmm… seems that somewhere along the way Rails added detection for existing constants and won’t allow you to re-generate something. Instead it calls raise_class_collision, which raises a UsageError. Damn them.
Anyway, to work around [...]

Read the rest of this entry »

Quick Tip: SSH Config

It’s easy to create shortcuts for all those servers you need to SSH into. There should be a file in your .ssh directory called config. Simply add a few lines to this file and you can refer to those servers by their short name.
Example (~/.ssh/config)
Host foo
Hostname some.long.hostname.you.cannot.remember.com
User myuser
Port [...]

Read the rest of this entry »

An Experiment in Remote Pairing

Recently, my employer, Integrum Technologies, has allowed me to work from home one day a week. This is due to rising gasoline prices combined with my distance from work. It’s great for me as I’ll save quite a bit of money each week as well as reduce my overall emissions. However, this [...]

Read the rest of this entry »

Everything I Need to Know About Pair Programming Etiquette, I Learned From My 4 Year Old

The folks at Integrum recently had a discussion about avoiding distractions while pair programming. We all know how many distractions there are in today’s world, everything from email to blogs to Twitter. It’s hard to not get distracted by all of these things, as they have become so prevalent in our lives. We want [...]

Read the rest of this entry »

TwitterBot Gem Released

Tonight, at one of our (in)famous hack-a-mania nights at Integrum, we released a gem for accessing Twitter through XMPP. Read the full Integrum release article and then go get hacking!
I’m excited because not only did I have a hand in the creation of the twitter_bot gem, but I also helped in the development of [...]

Read the rest of this entry »