InquiryLabs

Politics, Programming and Possibilities

Archive for February, 2006

"syncPeople on Rails" 0.6

Due to some great comments already, I decided to fix up what I can for the night and wrap this up. Version 0.6 will ask you before overwriting an already-existing partial, and the Intelligent Go To File command is a little bit more robust.

There’s also a subversion repository of this TextMate bundle at:

svn://syncid.textdriven.com/svn/opensource/syncpeople_on_rails/trunk

You can download version 0.6 here.

The original announcement of version 0.5 can be found here.

TextMate Backtracer 1.1

Added a small feature to the TM backtracer: it will now only load on Mac machines, helping prevent clutter for group projects where there are some Mac/TextMate developers and some non-Mac developers.

If anyone has a good way of detecting if TextMate is being used on the Mac as well, let me know.

Download the TextMate Backtracer Plugin v.1.1

More Goodies for TextMate

After introducing the controller-to-view textmate shortcut yesterday, my coworker (Pete Lasko) and I got excited about the possibility of expanding this idea. So from some of our ideas I built the “syncPeople on Rails” bundle for TextMate, in honour of the company we both work for.

Features of v.0.5

  1. Open Controller / View — option-command-up
  2. Create Partial from Selection — option-command-p
  3. Intelligent Go To File — keypad ‘enter’ key

The Open Controller / View feature is the same as yesterday’s feature. It is superceded by the Intelligent Go To File command, however, and may soon be deprecated.

The Create Partial from Selection feature lets you select a section of text in your view, hit option-command-p and then name your new partial. In place of the selection you’ll get a “render :partial => [partial name]” and a new partial file to match.

The Intelligent Go To File feature is perhaps the coolest feature of the set. Hit the keypad ‘enter’ key and you’ll be taken to whatever makes the most sense. For example, if you’re on a line that reads “render :action => ‘list’” and you hit ‘enter’, you’ll be taken to that list action in the controller. If you’re inside a view file but not on any particular “render” line, you’ll be taken to the controller. It tries to use a best-match scenario, and for the most part, I think it does well enough. It still has some significant limitations, however, that I will be eliminating as I develop Rails apps with it.

Installation - 5x Easier!

Download the syncPeople on Rails Bundle and untar/unzip it in to the following folder:

~/Library/Application Support/TextMate/Bundles

Done!

Enjoy!

Synopsis

Add a shell script to TextMate that moves you from a controller file to its corresponding view (.rhtml) file in one keypress.

UPDATE

See the syncPeople on Rails Bundle for even more features and a much simpler installation.

Navigation Blues

One of the most inconvenient things about the Rails directory structure is the relative distance between the controller and its corresponding view files. While it’s organizationally sound, it’s often a pain to go hunting for a view (especially in a complicated application that has modules and modules within modules).

I discovered a fantastic little key-combo within TextMate the other day that almost did what I wanted–if you hit command-option-down, you will be taken from the controller to the corresponding functional test (or from a model to the corresponding unit test). Try it out, it’s really cool.

The Shortcut

But what I wanted was ease of navigation from my controllers to my views and vice versa. From what I could tell, that’s not a built-in feature of the Rails or Ruby TextMate command bundles. So I wrote one and bound it to command-option-up. Read on to add the command yourself.

Installation

Put the rails-open-view-partner.rb file in to the following directory:

~/Library/Application Support/TextMate/ \
    Bundles/Rails.tmbundle/Support/bin

Next, in TextMate go to the Automation -> Run Command -> Edit Commands menu (ctrl-option-command-c). Navigate to the Rails commands and add a command by clicking the ” ” sign at the bottom of the window. Call this new command something like “Open Controller / View”. It should be next to the “Open Test Case” command which is the other command I mentioned above.

In the Command(s) window on the right, add this code:

rails-open-view-partner.rb "$TM_FILEPATH" &>/dev/null &

For “Input” choose “none”, and for “Output” choose “Discard”. For “Activation”, choose “Key Equivalent” and type a key combination in to the input box next to it (I chose command-option-up, since it matches the command-option-down quite nicely).

Finally, for Scope Selector, type “source.ruby.rails, text.html.ruby”. Whew. You’re done.

Note: As we’ve discovered in the comments, it’s important to make this file executable by adding the permission: “chmod u x rails-open-view-partner.rb”. Also remember that the scoping rules for this command apply to Rails mode not just Ruby mode.

Usage

Now that you’ve got that all set up, try it out. Go to a controller, and within that controller move your cursor inside of some action (e.g. between “def new” and “end”). Hit command-option-up and you’ll be taken to new.rhtml. From within new.rhtml, hit command-option-up again, and you’ll be taken right back to the controller.

Enjoy!

Update for RadRails Users

Justin Forder pointed out that the RadRails team is looking to do something similar. Kyle Shank has posted about this very same issue and it looks like they’re going to add a quick shortcut command too. Nice work, guys!

Textmate Backtracer 1.0

The backtracer has been around for a while now, and seems to have done its job well enough to deserve a 1.0 mark. This release includes a small improvement from Geoff Grosenbach that limits the loading of this plugin to development mode only. Geoff notes that this “simplifies the backtrace when running tests”. Thanks Geoff.

Download Version 1.0

Enjoy!

Ralph Douglass has made some nice improvements to my earlier instructions for installing Ruby SDL on Mac OS X. In fact, his instructions are a mere 25 lines compared to my 90!

Now if only someone more knowledgable than myself would wrap this all up in to a Port file… :)

[tags]ruby, simple directmedia library, sdl[/tags]

Setting up OpenCV on Ubuntu

OpenCV is a fast and well-designed C library for computer vision research and development. Since I’m not aware of an OpenCV library for Mac OS X, I’m using my old Ubuntu box to get things up and running.

So I don’t forget what I did, here’s some of the configuration I had to do:

  • Install libraw1394-dev Ubuntu package
  • Using ‘testlibraw’, check permissions
  • # sudo chgrp video /dev/raw1394
  • # sudo chmod g rw /dev/raw1394
  • Download OpenCV 0.9.7
  • # ./configure –with-apps; make; make install
  • # export LD_LIBRARY_PATH=/usr/local/lib
  • Compile and run my app with the following script

#!/bin/sh
export LD_LIBRARY_PATH=/usr/local/lib
echo `pkg-config --cflags opencv`
echo `pkg-config --libs opencv`
g `pkg-config --cflags opencv` -g -o igaze igaze.c `pkg-config --libs opencv`
./igaze