CodeGnome Consulting, LTD

Programming - Project Management - Information Security

Locking Files With Ruby

| Comments

Ruby’s File#flock doesn’t always work as expected when separate attempts are made to lock a given file. Some Rubyists avoid this method entirely because they assume it’s broken. It’s not broken; it’s simply incorrectly documented.

This post will explain some of the common errors encountered when following the official documentation. It will also provide some concrete examples of how to use File#flock correctly.

Not All Hashes Are Created Equal

| Comments

In Ruby, there’s often more than one way to do something. The language contains a lot of synonyms such as Enumerable#reduce and Enumerable#inject. It also contains a number of work-alikes such as hash literals like {} and hash constructors like Hash.new.

In general, programmers can treat this cornucopia of syntax as a matter of personal preference, or choose synonyms to communicate more clearly about the intent of a given piece of code. However, there are cases where work-alikes are not identical in terms of performance. Let’s look at some of those use cases.

Enumerator#each_cons

| Comments

If you are a Ruby programmer and you haven’t found a use for Enumerable#each_cons, you just probably haven’t thought about it yet.
     —– Michael Feathers (@mfeathers)

Well, Ruby is a great language, with a lot of nice surprises tucked away in its dustier corners. The Enumerator class is certainly a common one to reach for when solving problems, but I can honestly say I’ve never needed the Enumerator#each_cons method. After seeing Michael’s tweet, I took a look to see what it does.

Rails Note Tasks

| Comments

Even if you work with Ruby on Rails every single day, it’s a large framework with a lot of dark corners. Today, we shine some light on one of those under-utilized dark corners: the rake notes task.

Road Map to Programming Excellence

| Comments

The very best programmers are passionate about their craft—-and it is a craft. However, passion by itself isn’t really enough. If you want to be one of those programmers who is an order of magnitude better than your peers, you need a road map.

Like any destination, programming excellence has more than one route to reach it. Here are some sign-posts to help you on the way.

Parsing Initials From GECOS

| Comments

Why Would You Need a User’s Initials?

Some programs want you to enter someone’s initials for tracking edits in a word-processing document, or perhaps you need to find all the user stories assigned to one person using their initials as search criteria for the Pivotal Tracker API. Whatever the reason, I’ve occasionally needed to have a programmatic way to extract a user’s initials.

Remote Forwarding With SSH and Git-Daemon

| Comments

Local Git Repositories for Remote Machines

Have you ever needed to track changes to files on a remote host, but haven’t wanted to set up a dedicated Git repository on an external host? I certainly have.

I considered a variety of solutions, and settled on using remote SSH forwarding to a temporary instance of git-daemon running on my local machine. It’s fast, simple, and no less secure than storing your repository on the remote host in the first place.

Bootstrapping RVM on Mountain Lion

| Comments

The Dangers of a “Walled Garden”

No one seriously argues against the viewpoint that Apple’s OS X provides developers with a walled garden. While OS X runs Darwin under the hood, it’s still very much a closed ecosystem. Even if you install some third-party tools such as MacPorts or Homebrew, you’re still fundamentally stuck with some of the options that Apple makes on your behalf, very often in a “take it or leave it” way.

In the case of RVM, Ruby, and RubyGems, the walled garden has been systematically weeding out standard compilers in favor of LLVM-based compilers as provided by the 4.x series of Xcode. In practice, that means many rubies and gems will not compile without jumping through hoops—-and sometimes not even then. Even versions of Ruby that will compile with LLVM may require gems that won’t, so this is a non-starter for serious Ruby or Ruby on Rails development.

Luckily, even if you use a Mac on a regular basis, there’s hope. With a little help from MacPorts, VirtualBox, and some exported compiler settings, you can get a minimal Ruby environment running well enough to bootstrap a Linux virtual machine that “just works” for Ruby development.

Connecting an Ooma Scout

| Comments

In a recent post, I said:

[My wife] can’t set up her own voicemail messages or forward unanswered calls…separate from mine. With Ooma, we are forced to share those features[.]

It turns out that that she can have her own voicemail inbox. There’s a whole series of steps you need to take to make this happen, and the order of the steps isn’t strictly orthogonal. Nevertheless, here’s one sequence to get it done with the obsolete Ooma Hub and Ooma Scout.

Canonical Hostnames

| Comments

You can consolidate your domains, sub-domains, and hostnames with Apache 2 to provide a canonical destination for web requests. This can improve the user experience and simplify analytics.