Tag Archives: technology

Simple wrapper for Ruby scripts running in an RVM environment

Ruby is a fantastic programming language, but I’ve not been all that happy with the community’s viewpoint of the execution environment. Ruby is fast moving, so you often encounter scripts or applications that require specific versions of Ruby. This problem isn’t unique to Ruby, but the solutions the Ruby community offers are.

Typically, versioned interpreters are installed using a convention that works something like this. If Ruby 1.9 and Ruby 1.8 were installed concurrently, the interpreters would be installed using /usr/bin/ruby19 and /usr/bin/ruby18. Scripts that require Ruby would have their shebang altered appropriately. You’d also typically symlink /usr/bin/ruby to your preferred (default) Ruby install.

Ruby eschews this convention. Ruby interpreters that come with many Linux packages use this convention, but most Rubyists will advise you to avoid OS packages because of other issues. As a system administrator, the entire scenario borders on horrifying. I get why Rubyists feel the way they do, but to people on the “other side”, it’s terrifying. Hearing “just install from source” keeps sysadmins up at night.

Enter RVM. Ruby enVironment Manager is a tool for installing and managing Ruby interpreters and RubyGems (Ruby’scripts library package manager). At it’s core, RVM is a collection of bash scripts, written by author Wayne Seguin. It’s an excellent tool, and while it gets some public criticism over methodologies like overriding common shell commands like cd, I’m generally happy with it. I’m one of a growing group of sysadmins who cross over in to the programming side of things, so the power and flexibility of having multiple Ruby interpreters and multiple RubyGems gemsets is has a lot of value to me.

RVM works by altering the execution environment. I won’t go in to details about how to use RVM, but you should be able to glean enough from this simple statement to get some idea of what’s going on:

$ rvm use ruby-1.9.2-p290@sprinkle

This tells RVM to “use” (load) the environment for Ruby version 1.9.2, patch level 290, and use the “sprinkle” gemset. A gemset is just a collection of gems that you give a name. This appears to work like magic, but it’s really quite simple. RVM changes a set of environment variables that are relevant to the execution of Ruby and RubyGems. Basically, a bunch of load and execution paths. That’s all.

So where’s this all headed? The beauty of RVM is that it encapsulates Ruby execution environments. The primary drawback of RVM is that it encapsulates Ruby execution environments. How’s that? Take the ruby executable path for example:

/Users/myser/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

Not exactly as friendly as /usr/local/bin/ruby. Fortunately, that’s a solved problem. We have /usr/bin/env to work around that problem. The catch is, env works by searching the current environment. As we know, RVM dynamically loads an environment that works for each Ruby. What happens if RVM is never executed, and why would that be the case?

One example is cron. When you run a cron task, a very minimal environment is loaded. This means that RVM isn’t loaded. The standard solution to this is to source the rvm script prior to execution, but this means including the source line in every cron task, which A) requires that you remember it, and B) adds a lot of visual clutter to the crontab. When you’re reviewing a list of cron tasks looking for something specific, all these source lines make a real mess.

Additionally, if you write shell scripts in Ruby, you may need some scripts to run in Ruby 1.8, while others work in Ruby 1.9. In an interactive session, Ruby shell scripts are executed in the currently loaded environment, so you may not get what you expect. I’d prefer a self contained script that loads an expected interpreter and environment explicitly.

Wayne provides some example code for loading the RVM environment on the scripting page, but stops short of a working script example. I’ve taken the very, very small leap to a working script wrapper. The benefit of this wrapper is that it is portable to any environment where RVM is available at a user or system-wide level. You will, however, have to ensure that the appropriate Ruby and gemset are available. The script looks like this:

#!/usr/bin/env bash

# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"
else
  printf "ERROR: An RVM installation was not found.\n"
fi

# Configure ruby and gemset
rvm ruby-1.9.2-p290@gemset_name >/dev/null

ruby <<-rb
  puts "Hello!"
rb

I’m a jack of all trades, so I’m sure that there are different ideas and methods that may be better than this. I’d love to hear about them! Trackbacks are open on this page, so please comment and let me know what you think.

Augmenting my command line tool kit

A nice little list of command line tools for a variety of tasks. I’m probably not going to be using the calendar any time soon, but I already use htop, iptraf, mtr, and siege (along with the obvious ones like xargs and vim).

“A little collection of cool unix terminal/console/curses tools”:http://kkovacs.eu/cool-but-obscure-unix-tools

unix-tools.png

It’s not greed, it’s narcissism

The folks over at Readability published an “open letter to Apple”:http://blog.arc90.com/2011/02/21/an-open-letter-to-apple-reprint/ today, explaining their dissatisfaction with the rejection of the Readability app for reasons related to Apple’s new subscription content policy. I’ll leave aside for a moment the interesting study of whether or not Readability is a content app or a utility and focus on something more abstract. In their letter, Readability accuses Apple of being greedy. I believe it’s far more insidious than that. Apple has stepped beyond greed and wholly in to corporate narcissism.

Let’s step back for a moment and look at iOS apps and the iTunes App Store business structure. If I decide to develop an iOS app, I know that Apple is going to want a 30% cut. I structure my business around this model, and it works out well for a few reasons. Many iOS developers are independent developers that would normally have to rely on typical publisher distribution channels, which actually makes Apple’s 30% plan look attractive. Big players have been forced to re-adjust a little bit. For example, in the game market, EA has been forced to lower their price, but you’ll notice that many EA titles only dip in to the indie price-point realm of $0.99 when they’re on sale. Traditional big-name titles retain their higher price point. The distinguishing factor is that Apple has not placed any price constraints on app publishers’ price points outside iOS and the App Store. The developers of Angry Birds are able to offer their app on Android for free. The contrasts are less apparent in other app categories, because iOS software has a natural tendency to be iOS exclusive. This is owed to other constraints, such as the requirement that apps remain authored in Objective-C and Cocoa Touch from their inception. Apple has written their rules in such a way that cross-platform apps are discouraged. This is by design, and arguably, developers and users have benefited by having access to well-written applications at a reasonable price.

The rules of the “app” game are set up in Apple’s favor, but native apps were Apple’s first step in to the broader development pool. Moving in to more current events, we can see how Apple is taking the lessons learned — well, some of them anyway — and applying them to their new “content” fee scheme. I use the word content, rather than subscription, explicitly because of the Readability case. Readability is not a publisher. They’re strictly a facilitator. I was called a little bit crazy for bringing up Flipboard in my last example, but I believe it is now more relevant than ever. Flipboard may not have any plans to build a subscription model, but anyone eyeballing their platform as a possible candidate for subscription content now has to accommodate Apple’s 30% cut.

Back on topic, I posit that Apple doesn’t really care about traditional media at large. A lot of the outcry is centered around the fact that Apple’s rules make it hard to structure a business that crosses boundaries. If I build a subscription content model that sells to iOS users, as well as the internet and traditional print media, I have to account for Apple’s 30% cut of my subscriptions that sell through the iOS ecosystem. This dilutes my margins outside the iOS world, effectively forcing me to “subsidize” my iOS users at the expense of everyone else. In simple terms, I will be forced to charge everyone more, because I can’t pass the Apple content tax on to iOS users alone thanks to Apple’s price consistency stipulations. Apple doesn’t care about that because they’re not in the business of helping you sell content. They’re in the business of building the iOS ecosystem

Apple’s goal is to fill their App Store with exclusive content; content designed specifically for iOS, and available nowhere else. “The Daily” is a prime example. “The Daily” is a new media property. Take in to account that Rupert Murdoch’s company, News Corp, is the third-largest media conglomerate in the world, yet they did not select an existing property to bring to the iPad. This is not a coincidence. Apple wanted an exclusive property, and News Corp is willing to try anything to save their struggling model. Don’t get me wrong, there are good reasons to make this a new property. By doing so, News Corp side-steps any pre-conceived notions users might have about what the content should cost, how it should be purchased, and with what frequency it should arrive. When you make something new, you get to set the rules. Sound familiar? Yes, News Corp took a page right out of Apple’s playbook, and I’d be willing to bet that Steve Jobs handed them an annotated copy.

As the picture forms, you realize a couple of things. First is that Apple is acting without regard for the larger market. That’s pretty typical for Apple. When given the opportunity, most companies target a small slice of the bigger pie. Something about “capturing just 2% of the market” makes the job sound easier, even if 2% represents millions of users. Apple eschews this thinking and attacks the small pie viciously. Have a look at Apple’s laptop strategy. Apple doesn’t sell to the low-end laptop market, but they dominate the high-end. Small pie, huge chunk. Based on that business philosophy, it would stand to reason that Apple doesn’t place a high priority on enabling apps like Readability, because they offer no iOS exclusivity. Apple would rather incentivize content like “The Daily”.

What’s striking about all of this is that there is only one benefactor in this strategy: Apple. There is one other possible benefit: that indie content creators will be empowered, much like indie app developers. Unfortunately, I’m not sure the same rules apply. Apps and games often go deep, but rarely wide. For example, look at Delicious Library. An excellent app developed by an independent developer. The problem of cataloging and organizing your personal media was thought about very deeply by its author, but where the problem gets wide, Delicious goes elsewhere. It relies on Amazon.com to provide details about the content. App developers have no problem going deep because they can simply work on the problem linearly, but going wide is difficult to serialize. Media is a “wide” problem. You can build a fantastic content publishing system that thinks of every conceivable angle and still have a commercial flop if you lack content that is high quality and diverse in interest. You need a lot of good content to make a media publication work, and that content needs to be current. Tools for creating content have never been more within reach, but there is still the question of editorial talent. Blogging, for example, still occupies a different space in my media view than a publication like The Economist. One is unfiltered, while the other is streamlined and concise. The latter takes far more resources.

For these reasons, I believe Apple stands alone in reaping the benefits of their business model. This steps across the lines of greed and into corporate narcissism. When it comes to corporations, being narcissistic might not be unethical, but it doesn’t win you a lot of friends, and ultimately hurts you over the long haul. Apple views the value of their platform from one direction only. iOS and the App Store are Apple’s gift to developers, content creators, and users. Nevermind the fact that an iPad devoid of applications is completely interchangeable with products from competitors. No value there. Apple would do well to strike a balance here.

Kitty Hawk 2.0

One of my favorite quotes from a great video titled “The Future of Money”:http://vimeo.com/16025167.

bq. “The Wright brothers weren’t thinking about all the infrastructure required to make commercial aviation happen, they were thinking ‘How do we make this thing fly?'”

It’s easy to look back over the industrial revolution and believe that somehow, this time things are different. Then you hear someone say something like this, and you realize that we’re all standing around Kitty Hawk, just trying to get this thing off the ground. The truly great things are yet to come.

Ballmer’s opportunity cost

Comments on: “Ballmer Dismisses Android. Oh, This Will Come Back to Bite Him”:http://nextparadigms.com/2010/08/02/ballmer-dismisses-android-oh-this-will-come-back-to-bite-him/

While this is mostly just a take-down piece about Ballmer and his lack of vision, there is some new insight here that I’m not sure I’ve read elsewhere. At least not written explicitly:

bq. “…when he’s [Ballmer] done nothing but extend their old business, Windows and Office, which is fine, but there are a lot of other CEO’s who could’ve done that just as well or better. Businesses don’t last forever. It takes someone special, a visionary, to create new growth opportunities in the company.”

Some time ago, there was a little storm around how poorly Ballmer had done as Microsoft CEO, mostly because of the flat-line stock. There were some good rebuttals showing growth in profits under his direction, which seemed to shock everyone in to believing that maybe he didn’t do all that badly. Everyone seemed to kick the dirt and say, “Well, we all know stocks aren’t the best indicator of success or failure of a company. While Microsoft is doing fine from financial perspective, Wall Street simply doesn’t recognize it.”

But let’s back up a moment and realize that Wall Street isn’t interested in what you’re doing today. Stocks are bought and sold based on what people thing you’re going to do tomorrow; next quarter; next year; five years from now.

Apple’s recent growth can be attributed, in large part, to iPad sales. This is a new market. Speaking from Microsoft’s market perspective, this is money that, at best, would not have been spent elsewhere. At worst, it was money that consumers might have spent on a netbook. I’ve seen research both ways, and honestly, neither side is terribly convincing.

The bottom line is that while Ballmer has managed to squeeze a little more life out of Windows, he hasn’t moved Microsoft forward. That’s inexcusable for a company with the engineering and capital resources Microsoft has.