An Extract Method for Perl in Vim

Awhile back I read Ovid’s 2010 post Method Extraction in Vim. I suspected I could use it but I never followed through.

At work we recently formed a book club that is reading through Fowler’s Refactoring. As a result, one of my coworkers mentioned that he was looking for an Extract Method tool for Perl in Vim. I was reminded of Ovid’s post and decided to finally follow up on it.

I ended up basing my implementation on one of the commenters’ suggestions; which referenced Crossing the Rubicon. Again or more specifically Jesse Vincent’s extract. After trying out extract I decide I wanted to tweak a few things and ended up making a lot of changes to clean it up. Feature-wise not much changed except some minor improvements in the whitespace of the extracted method and the removal of a non-core dependency. My modified version is available as a Gist if anyone is interested.

Then I added Ovid’s mapping in my ~/.vimrc:

vnoremap <leader>sub :! perl-extract<CR>

So far all I have used it for was in cleanup itself. ;-)

3D Printing

Twice this week I was made aware of someone 3D printing a custom part to solve some problem in their life. The first was printing some sort of lens cap for his Google Glass. He found an existing design online and modified it to his liking and then ordered prints through an online service. The second was bbum printing a cap for the over-sensitive power button on his bluetooth keyboard. He printed it with his own printer.

Someday I’d like to own a 3D printer. I really hope they continue to advance and that the consumables get more inexpensive.

Install Term::ReadLine::Gnu on OS X

A coworker setup an awesome repl.rc that uses Term::ReadLine::Gnu to enable tab completion, etc. in the REPL. I recently tried using it on OS X and found readline was not installed (due to OS X’s BSD heritage rather than GNU). However, if you have homebrew installed you can install the readline library easily:

brew install readline

readline is Keg-only though which means it does not get linked into /usr/local/include or /usr/local/lib so you have to specify its location manually. In order to due this when installing Term::ReadLine::Gnu you will need a version of cpanm that supports the --configure-args option:

cpanm --configure-args="--includedir=/usr/local/Cellar/readline/6.2.4/include --libdir=/usr/local/Cellar/readline/6.2.4/lib" Term::ReadLine::Gnu

Thanks to the docs for Term::RouterCLI for pointing this out!

homebrew/science on Tap

Don’t know what brew is? Checkout homebrew and install it.

brew tap homebrew/science

Looks like homebrew/science is under very active development; there are currnetly 122 formulae and 50 open issues (44 open pull requests). Some notable tools: abyss, bedtools, bowtie, bwa, octave, samtools, tabix, tophat, and velvet.

Modify Original Git Commit

On occasion I have wanted to edit the original commit of my Git repo. If it were any other commit I would just do an interactive rebase to modify it but that isn’t possible with the original commit. However, you can do the rebase manually if you follow the process below:

OLD_ROOT=$(git log --reverse --format=%h | head -n 1)
git checkout $OLD_ROOT

# If you want to add or remove files do so now and stage them using
# `git add` or `git rm`.

git commit --amend
NEW_ROOT=$(git rev-parse --short HEAD)

# This assumes you were on a branch when you started.
git checkout @{-1}

git rebase --onto $NEW_ROOT $OLD_ROOT

Based on: Can I remove the initial commit from a Git repo?