Project specific .irbrc
Users of Ruby’s interactive, REPL-tastic program irb should know about the ability to bootstrap your irb environment using ~/.irbrc. If such a file exists, Ruby will load it before giving you a prompt to start entering lines of code. You can put whatever Ruby code you want in there!
Here is my ~/.irbrc file, part of my “dotfiles” project on GitHub: http://github.com/greatseth/dotfiles/blob/master/irbrc
There are a few handy code snippets in there. Here is one of my favorites:
# Project-specific .irbrc
if Dir.pwd != File.expand_path("~")
local_irbrc = File.expand_path '.irbrc'
if File.exist? local_irbrc
puts "Loading #{local_irbrc}"
load local_irbrc
end
end
This says: If we aren’t in ~/, we look for .irbrc in the current working directory. If we find it, we load it!
That snippet enables an intuitive and really simple hook for project-specific irb bootstrapping. Here’s an example from my latest labor of love Walter:
require 'grit'
GRIT_EXTENSIONS_PATH = File.expand_path './lib/walter/grit_extensions.rb'
def reload_grit_extensions!; load GRIT_EXTENSIONS_PATH; end
reload_grit_extensions!
No big whoop, but it’s awesome to have stuff you do all the time in your irb hackings utomatically setup for you.
easier said.
Seth Godin recently wrote about the importance of being on time. He used special emphasis when he wrote:
Boy that’s simple. Apparently, it’s incredibly difficult.
I’ve been paying more attention to this attitude lately, this assertion of what is easy. Recently on the Shoes mailing list somebody wrote the following(details omitted for clarity of the point here):
I was wondering if shoes could [do this cool thing]. [The system]
natively supports [this other cool thing that would be helpful for the aforementioned, desired but as yet unrealised cool thing], so it couldn’t be very hard…
Godin asserts that being on time and respecting the time of others is easy. This fellow on the Shoes list asserts that adding some desired behavior to his programs couldn’t be very hard. If the former were true, Godin wouldn’t have much of a blog post. If the latter were true, the fellow probably would have fixed his problems instead of going to the group at large for support.
Honoring others at all times is not easy. Programming is not easy. Many things in life are not easy. Sure, people make things harder than they have to be sometimes, but I think most love an easy win, too. Perhaps there just aren’t as many out there as we’d sometimes like to think.
Ender’s game: price overrides OR how I got the iPhone 3G for $199 despite The Man trying to screw me.
So, I went to the Apple store the other day to get the iPhone 3G in honor of my landing a new job and, yeknow, ’cause it’s faster and shit. As the baby blue t-shirt clad chap helped me complete my purchase, he informed me that I wasn’t eligible for the “upgrade price” because my current AT&T contract is less than a year old. Instead of the widely advertised $199 price I would have to pay $399. I had never heard of such a thing, and my quick appraisal of the notion only cemented my initial reaction of “WTF?” Why would they penalize people who had contracts less than a year old? I called up AT&T and they confirmed this bizarre rule. Pissed off and confused, I left that day without a new iPhone.
Yesterday, I went back, resigned to my overcharged fate. I just couldn’t bear the thought of the EDGE network and no GPS until next April. Another baby blue t-shirt clad chap helped me and also pointed out the ridiculous AT&T pricing rule. I explained how I knew and what I knew. “Weird,” he said. “I know,” I replied. “Let me see what I can do on my end,” he said and walked off to god knows where. Probably a room full of baby blue t-shirt clad hipsters.
Eventually, he returned and informed me that he was able to hook me up with a “price override” and that I would be getting my new phone for the upgrade price of $199 plus tax and some shady changes in my phone plan required by AT&T when upgrading to the new phone. Whatever.
The big take away here is that, should you find yourself presented with the same bullshit $399 deal, don’t quit there! Ask about “price overrides” or come back later and look for a nerdy lookin’ fellow named Ender (Thanks, broseph!). Just know that victory can be yours, oh yes.. it can be yours.
on Rand and The Fountainhead
I always think of The Fountainhead like a great comic book redone as a novel. Or something like that. The characters are so extremist, the style and passion attractive.. it’s got epic intensity. I guess if you really dig into Rand’s ideas about reality it gets nutty or whatever, but I don’t give a fuck about that. Nor do I have to. So, fuck off with your knee-jerk judgement because I read a goddamn book.
Anyway, I tried reading Atlast Shrugged later, and I felt like it was the exact same book. Only about trains. And longer somehow. So, I got bored and stopped reading. I think I gave up while riding a train, actually..
modern reason.
it took me forever to figure out how to write something on that stupid event wall didn't see the tiny link and then i was wandering around in yet another unfocused internet journey that started with my bitching about that interface on twitter until i eventually came back to gmail and thought i'd just fucking email you
geocoding info in Ruby.
Sometime last year, around the time of the 2007 RailsConf if I recall correctly, I wrote a tiny little gem called google-geo. It’s a simple group of classes for making queries against Google’s geocoding service and getting some classy objects in return.
Here are some choice examples from the README.
geo = Google::Geo.new API_KEY
addresses = geo.locate '1600 Amphitheatre Parkway, Mountain View, CA'
addresses.size # 1, :locate always returns an Array
address = addresses.first
address.country # 'US'
address.city # 'Mountain View'
address.full_address # '1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA'
address.query # '1600 Amphitheatre Parkway, Mountain View, CA'
address.accuracy # 8
In the case of sufficiently vague queries, Google::Geo will return more than one:
addresses = geo.locate 'hell'
addresses.size # 2
addresses.map { |a| a.state } # ['PA', 'NC']
Somebody recently contacted me about including this gem in a OpenBSD package, so I added in a LICENSE and put the project up on GitHub.
The “package” is just an OpenBSD application package. It would be similar to FreeBSD or NetBSD’s ports or Debian’s apt-get system. I’m using your Google-geo library in the web app I’m currently building. I found it very clean and helpful and though the rest of the OpenBSD community should know about it, so I’m creating an application package for it. Therefore, someone can just do a `pkg_add ruby-google-geo` and have your library installed. Also, if someone queries the OpenBSD packages looking for some kind of geo coding library, your library will pop up.
Very cool! Thanks, Clint.
I’ve always been pleased with this library. I think it’s a great example of simple quality.
- First, it has tests. The tests use fixtures based on reasonable assumptions about what we can expect from Google’s service. This means that you can run the tests anytime and very quickly.
- Second, it has no dependencies outside the standard Ruby libraries. XML parsing is relegated to a couple simple methods that use regular expressions to extract values from the response markup. Heresy, eh? No, quality. The overhead and complexity of a “real” parsing library is simply. not. needed.
- Aaannnd you get great objects to work with.
Score!
runpacker.
I’ve noticed that RubyGems(as of version 1.0.1, anyway) does not offer a convenient way to unpack a specified gem and all of its dependencies. So, I decided to try to come up with something simple to work around that. After a few minutes inspecting the Gem API and some help from drbrain, I ended up with this:
#!/usr/bin/env ruby
if ARGV.empty?
puts "Usage: runpack gem_name"
exit
end
require "rubygems"
gem_specified = ARGV.first
Gem.gem gem_specified
gems_to_unpack = [gem_specified] +
Gem.loaded_specs[gem_specified].dependencies.map { |d| d.name }
gems_to_unpack.each { |g| system "gem unpack #{g}" }
be offended. be very offended.
I left the following as a comment on a recent failure, and I was just pleased enough with its coherence that I thought I would post it here:
Taking personal offense to something is a subjective experience. Everyone has the right to that experience, but what I don’t think they have the right to is asking somebody to take back something like this. Where do you draw the line? “OK, this is offensive, but that is not.” Great. What about me? What about that guy? What about the guy who hasn’t even entered the situation yet?
Be offended if you must, but leave it at that and move on.
a poor man’s YouTube API in Ruby.
I’ve been playing with a little Merb app for my new personal website. One of the focuses of the project is for me to focus less on engineering principles and so-called best practices and more on features and doing new, creative things.
Recently I thought it would be cool if YouTube videos I linked to via my Delicious account were automatically embedded in the HTML representation of the Yahoo! Pipes feed which powers the main view of my new site. I came up with this:
CGI.unescapeHTML Hpricot(open(link)).at("#embed_code")[:value]
Now, if you want to split hairs, it’s definitely questionable. However, context is everything, and in my current one, this solution works great.
hacked bot.
I was recently clued into Hackbot’s HaHa’s. It is a delightful and simple concept:
- Images of robots from earlier science fiction are funny.
- Cheesy computer synthesized voices saying things people might say are funny.
- The two combined are even funnier.
So, I made an RSS feed for Hackbot. It is powered by Dreamweaver created HTML, some of the finest quick hackery this side of The Appalachians, and the promise that new jokes are published every Tuesday.
Here’s hoping..



leave a comment