14km

Aug 22

Jun 18

Jun 14



May 25

For when you realise that the file you want to edit is owned by root.


Jan 12

Nov 28

Jan 17

Embedding IRB into your Ruby application

I needed to play around with Capybara/Selenium, but it’s a pain waiting for Firefox to start up every time you make a small change. Fortunately, I’m not the only one with the problem. Drop this somewhere:

require 'irb'

module IRB # :nodoc:
  def self.start_session(binding)
    unless @__initialized
      args = ARGV
      ARGV.replace(ARGV.dup)
      IRB.setup(nil)
      ARGV.replace(args)
      @__initialized = true
    end

    workspace = WorkSpace.new(binding)

    irb = Irb.new(workspace)

    @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
    @CONF[:MAIN_CONTEXT] = irb.context

    catch(:IRB_EXIT) do
      irb.eval_input
    end
  end
end 

And it’s use is quite simple. When you want to drop into an irb session, you simply do

IRB.start_session(binding)

Nov 21

As of Emacs 20.3, there is indeed a repeat command (C-x z) that repeats the last command. If you preface it with a prefix argument, the prefix arg is applied to the command.

You can also type C-x <ESC> <ESC> (repeat-complex-command) to reinvoke commands that used the minibuffer to get arguments. In repeat-complex-command you can type M-p and M-n (and also up-arrow and down-arrow, if your keyboard has these keys) to scan through all the different complex commands you’ve typed.

GNU Emacs FAQ

Jul 6
Rainbow Mode:


  a minor mode for Emacs. It displays strings representing colors with the color they represent as background.


by Julien Danjou

Rainbow Mode:

a minor mode for Emacs. It displays strings representing colors with the color they represent as background.

by Julien Danjou


May 27

Mocha doesn’t play nice with Rails 3 & Bundler

Using mocha with edge beta Rails 3, I added Mocha to the Gemfile

gem "mocha"

All was going swimmingly until I ran into a problem. I reduced it to:

The result of running this test was:

#test_mock_doesnt_fail should fail, but doesn’t. Changing the require lines at the top of the file to not load Rails and only load Mocha (+Rubygems+Test::Unit):

require "rubygems"
require "test/unit"
require "mocha"

caused the test to fail as expected. After an hour or two digging around, I stumbled across a post on the Mocha mailing-list that mentioned ordering problems with Mocha and Test::Unit. Sure enough, if I rearranged the modified require lines so that Test::Unit was loaded after Mocha:

require "rubygems"
require "mocha"
require "test/unit"

the test would break — I.e. wouldn’t fail.

Following the advice in the post — modified for bundler — I changed my Gemfile to read:

gem 'mocha', :require => nil

and added:

require "mocha"

to test/test_helper.rb to make sure Mocha was loaded. This isn’t strictly needed, but it’s good to be clear.

Final result, the test fails as expected, and Mocha is seems to be working properly.


May 16

Money isn’t always a good motivator, as Alfie Kohn has been saying for years

Via Stretta


Apr 22

‘Now will this be everything, or…’

‘Well, I might need to raise an exception.’

The compiler purses its lips. ‘An exception? Hmmm… let’s see…’

JRM at Abstract Heresies

Apr 13

Be mindful of array copying

Trying

irb> d = [1,2,3,4]
=> [1,2,3,4]
irb> d[0..-2].each_with_index {|k,i| d[i+1] = "x"; puts k }
1
2
3
=> [1,2,3]
irb> d
[1, "x", "x", "x"]

Reasonable, d[0..-2] would make a copy of d

irb> d.each_with_index {|k,i| d[i+1] = "x" if i &lt; 3; puts k  }
1
x
x
x
=>  [1,2,3]
irb> d
[1,  "x", "x", "x"]

Page 1 of 2