Updating Multiple Git Repos
Adam Lowe has a great writeup on setting up Vim for Ruby/Rails work. It’s a pretty great solution, using pathogen.vim and the git repos for the bundles, but he didn’t mention how to update your bundles in an easy manner…
$ find . -name ".git" -type d -prune -execdir git pull \;
This is a little command line snippet that will search for git repositories in all of the subdirectories of wherever you run it and update them. Really handy in this case, because you can update all of your bundles at once, but it will work in any case where you have cloned a bunch of repos and want them to all stay up to date.
Passenger can’t find Rails
If you are running in to an issue where you are trying to get a Rails app up and running, but are receiving the error “Missing the Rails 2.x.x gem…” when you attempt to access it despite Rails being installed and available to your system, do not panic. Rails is just giving you an extremely unhelpful error message.
Rails catches *any* problem loading the Rails gem, and then responds with that error.
rescue Gem::LoadError => load_error $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) exit 1
If you inspect load_error from the line above, you should see the actual error message. In my case it was that ActiveSupport required Rack v1.0.0, but Passenger had already instantiated Rack v1.1.0. This led to a failure when loading the Rails gem, which was of course incorrectly reported. My quick solution was to uninstall the new version of rack, and force the install of the older version.
As a side note: I have the world’s worst code highlighter.
Getting Ruby Going on App Engine
I gave a talk last night at the Atlanta Ruby Users Group meetup about using JRuby on Google App Engine. It was more of an overview about what App Engine is, and how to get started with a Sinatra app. The Github repository for the application is located here, and you can see the application in action here.
The application demonstrates a few app engine concepts. In models.rb you’ll see a sharded counter implementation using the direct Datastore API, and a traditional model using Datamapper as your ORM (ODM?) to Datastore. The counter also demonstrates usage of the Memcache API. Inside app.rb you can see some simple usage of the Users API, including how to check to see if a user is logged in, present a user with a login screen, and interacting with the object. Lastly, you will find an example of how to determine your app’s name and version in config.ru.
Following the presentation I received a number of requests for my slides, so they are included below. Slide 13 illustrates pushing your own app to App Engine. As I mentioned in the talk, I strongly suggest setting aside one of your app ids for testing new ideas, since you only get 10 ids total.
Arduino In True Color
As part of a larger project, I needed to have a way to allow a computer to “see” the color of an object. In this case, size and shape of the object were unimportant, however the position of the objects that need to be sorted means that the detector must be able to fit into a very small space. This ruled out using cameras and the like.
In order to accomplish this, I turned to my Arduino, and started brainstorming. My initial thought was to use a very bright light and three photoresistors with RGB screens over the top. This has the benefit of being *very* fast, but it still requires a good amount of space as well as finding the right material to use for gels. I’ve tried to find good colors like that in hobbyist quantities before, and it was always a pain.
The solution I decided on was to using a single tri-color LED paired with a single phototransistor. By cycling through the colors and measuring the resistance at certain times, I should be able to retrieve something very close to the correct color. I placed the phototransistor in one of the analog read pins. I hooked my common anode LED up by placing the anode to +v, and the cathodes to PWM leads set to “OUTPUT”. They work a bit opposite of what you may be used to, requiring you to bring the pin low (via an analog write of 0) to turn them on.
It is very easy calibrate by measuring a black object for your minimums, and then a white object for your maximum values. After that quick setup you have a working color detector that can fit into the area of a single LED and a photoresistor. You can see it in action below.
