Category Archives: Uncategorized

Monkey and Crow

If you have enjoyed any articles on this blog, then come visit me on Monkey and Crow where I am once again actively posting about Ruby, Javascript, and development in general.

1 Comment

Filed under Uncategorized

A Quick Look at CodeMirror 2

I recently wrote a brief overview of three interesting browser based editors. Marijn Haverbeke the author of CodeMirror mentioned that CodeMirror 2 would be much faster, and I have to say I’m impressed. CodeMirror 2 is using virtual rendering to display and format code much more quickly.

This trick is achieved by only rendering rows as they are needed. As they scroll off the top, rows are removed and and new ones are added to bottom of the scrolling element. This is becoming more common as web applications tackle larger amounts of data. I have also seen this technique used for displaying large tables of data in libraries such as SlickGrid, UkiJS, and we use a variant of this at LiquidPlanner for displaying large and complex project schedules.

CodeMirror 2 also has some interesting demos showing off code completion, search and replace, and parsing embedded languages. If any of this sounds interesting to you, I suggest you skim the manual and watch Marijn’s CodeMirror 2 repository on GitHub. It looks like it’s shaping up to be a great project.

1 Comment

Filed under Uncategorized

Getting Help Inside IRB

Here’s a quick tip, ruby’s ri utility will look up documentation about a method. For instance you can type ri String#split to see the documentation for String’s instance method split. If you have an irb session open you can tell irb to shell out using back ticks like this:

  ruby-1.9.1-p378 > puts `ri String#split`

You can also make a little helper method like this:

  def ri(signature)
    puts `ri #{signature}`

Leave a comment

Filed under Uncategorized

Switching Tabs in Textmate

The most recent update of Textmate, version 1.5.10, made one major change which remapped the keys for switching tabs to ‘cmd-shift-[‘ and ‘cmd-shift-]’, while this makes TextMate behave the same as most other OSX apps, it’s a little annoying if you’re used to the old shortcuts.

To get the old behavior back, you can customize TextMate’s shortcuts by opening ‘System Preferences’, choosing ‘Keyboard’, and then switching to the ‘Keyboard Shortcuts’ tab. If you then select ‘Application Shorcuts’ you can add an override for TextMate’s ‘Next File Tab’ and ‘Previous File Tab’.

1 Comment

Filed under Uncategorized

Find Duplicate Ruby Tests

In ruby, if you define a function twice in one class, the second definition overrides the first. This is really tricky if you accidentally use the same test name twice.

Here’s a quick one liner to find any duplicated method definitions in your file:

grep test/**/*_test.rb -e 'def ' | uniq -c | awk '$1 > 1'

If you have any duplicates, you will see something like this:

2 user_controller_test.rb: def test_updating_user
3 cake_controller_test.rb: def test_applying_frosting

Now go and get those tests fixed up!

Leave a comment

Filed under Uncategorized

Graphs for ruby-prof

I recently found myself in the unenviable position of having to dig into some performance issues. After wallowing in self pity for a while, I whipped up a dot graph printer:

Example ruby-prof dot graph

As an added bonus, it groups method calls by class, which helps when reasoning about performance. Roger Pack kindly already merged it into the github repository, so you can try it out (you’ll have to build the gem from source until someone pushes 0.9.0).


Filed under Uncategorized

Migrating Ruby Gems Between Ruby Versions

I found this quite handy after install ruby enterprise edition:

ree -S gem install /Library/Ruby/Gems/1.8/cache/*

Where ree is the ruby environment you want to copy your gems to and /Library/Ruby/Gems/1.8/cache/* is the path to your existing gems. Should also work for MacRuby and friends (assuming the gems will build on that environment anyways).

Leave a comment

Filed under Uncategorized

OpenGem 1.4.2

I just gathered up a few patches and merged them into OpenGem. This includes:

  • Respect the VISUAL environment variable above EDITOR. (cwninja)
  • Use Launchy gem to read rdocs (ngauthier)

Install with gem install open_gem.

Leave a comment

Filed under ruby, Uncategorized

TextMate Bundle for Pure

Pure is a fairly new interesting language based on term rewriting. Unfortunately I lost track of time last night and whipped up a TextMate bundle with some basic support for the language. It is pretty minimal at the moment though it does support basic syntax highlighting, some useful completions, and documentation look up.

You can find it on Github.

Pure Documentation Tooltip

Leave a comment

Filed under Uncategorized

Using the Mac OS X Find Buffer for Text Navigation

Mac OS X has a nifty text feature where you can hit Command-E, and your selection will be placed into a find buffer. Hitting Command-G and Shift-Command-G will find the next or previous instance of your selection.

I find this really useful when poking around in code. For instance if I want to go look somewhere else in a file, I will select a unique chunk of code, and stash it in the find buffer. I go about my business and then as soon as I need to go back, I just hit Command-G. It’s one of those basic little things that really makes working on a Mac quite enjoyable.

Any other good keyboard shortcuts people tend to miss?

Leave a comment

Filed under Uncategorized