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.

Advertisements

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}`
  end

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).

3 Comments

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