codemonkey like you

Pidgin2adium 3.2.0 Released (works with 1.8 again)

As always, get the latest version by running: gem install pidgin2adium.

This is a bugfix release, but an important one: it makes pidgin2adium work with Ruby 1.8. When I made pidgin2adium 3.1.1 work with Ruby 1.9, I accidentally broke 1.8 compatibility. Thankfully, now it’s fixed.

Thanks to Artem Zolochevskiy for bringing this bug to my attention.

A tiny bit of Vim

I’m trying to reorganize my monolithic zshrc into discrete files, so I was putting e.g. all the setopt commands in ~/.zsh/opts, and I discovered a neat thing.
You can visually select a chunk of text, do :w file_name, and Vim will create a new file named file_name, with just the selected text in it, while leaving you in your original file.
I just discovered this. My thought process: “I only want to write out part of this file…I’ve heard Vim is kind of like a language for text editing, so let’s see if this works…YES! IT WORKS!” And then I stared at the screen in wonder. No, really. For like 10 seconds, just staring.

Vim is pretty awesome.

How to get ZSH to complete CMD1 like CMD2

I tested out git-achievements (my achievements are here), and it seemed like a fun little toy. Then, I did this (with alias git=git-achievements in my zshrc):

git <TAB>

aaaand, nothing. Just completion of files in the current directory. Where’d my ZSH git completion go?! Why didn’t it work across aliases?

My initial reaction was just to remove the git-achievements alias and use straight git. Then I decided to enter the Lair of the ZSH Completion Docs* and see if I could fix it. My first attempt was to edit my zshrc to add all the git completion functions to git-achievements:

alias git="git-achievements"
compdef git-achievements git-add git-am <...etc...> git-write-tree

Note that these were copied from /usr/share/zsh/4.3.9/functions/_git. That didn’t work. So I dove back in and found it:

compdef [ -an ] function names… [ -[pP] patterns… [ -N names… ] ]

…all the arguments may have the form `cmd=service‘. Here service should already have been defined by `cmd1=service‘ lines in #compdef files, as described above. The argument for cmd will be completed in the same way as service. [bolding mine]

Even that is hard to puzzle out, but it means that you can do this:

alias git="git-achievements"
compdef git-achievements=git

..and everything is fine and dandy.

*Note: I know that the ZSH documentation writers must be trying, and it’s mostly clear(ish), or at least comprehensive. But there’s so many options that it’s basically a hopeless task. I mean, I found this tip out on something like my 10th read of that page.

I Will Learn You A Crucial Bit Of Haskell: Comments

Learn You A Haskell For Great Good! is awesome (so far – I’m on the first chapter), but it’s missing crucial information: how to comment a line in a Haskell file. So here it is.

-- This is a single line comment
{- This is a multiline comment.
It can span more than one line. -}

Thanks to this page for the info. I wonder what a documentation comment is? Oh well, I’m sure I’ll find out.

Rails 3, Heroku, and Hassle

When I moved my Rails app to Rails 3 on Heroku, Sass broke. Or rather, Hassle, the plugin I was using to allow me to use Sass on Heroku’s system, stopped working, because it’s Rails 2 compatible, not Rails 3.

Thanks to this blog post, I found out how to fix it, and it’s quite easy. Assuming that you have the hassle plugin in #{Rails.root}/vendor/plugins/hassle, do this:

  1. Delete the hassle directory: #{Rails.root}/vendor/plugins/hassle
  2. In your Gemfile, add this line:
    gem 'hassle', :git => 'git://github.com/koppen/hassle.git'
    This is a Rails 3 compatible fork of the original Hassle plugin.
  3. Run bundle install.

And you’re done. Hopefully, this will save someone else some hassle (sorry).

Pidgin2Adium 3.1.1 Released

Well, this is a bit late, but Pidgin2Adium 3.1.1 was released. So go out and do a gem install pidgin2adium today! Read on for what’s changed.
Source: http://github.com/gabebw/pidgin2adium/tree/v3.1.0
Gemcutter: http://rubygems.org/gems/pidgin2adium

Straight from the ChangeLog:

  • Moved BasicParser and its subclasses into parsers/ subdir
    • You can now do “require 'pidgin2adium/parsers/all'“,
      though the old “require 'pidgin2adium/log_parser'” will still work
  • Moved Message and its subclasses into messages/ subdir
    • You can now do “require 'pidgin2adium/messages/all'“,
      though the old “require 'pidgin2adium/message'” will still work
  • I also actually removed the balance_tags.rb file (the old Ruby implementation of balance_tags_c)
  • LogFile now has Enumerable included so that you can do log_file.each_with_index {|msg, i| …. } or log_file.max(), which will give the  message in the LogFile that was sent most recently, and log_file.min(), which will give the oldest message (the message sent the longest time ago).

Pidgin2Adium 3.1.0 Released!

Source: http://github.com/gabebw/pidgin2adium/tree/v3.1.0

Gemcutter: http://rubygems.org/gems/pidgin2adium

This is a pretty big release: everything is tested (except bin/pidgin2adium, which has peculiar $LOAD_PATH problems with the C extension etc.), the code is MUCH cleaner, and it uses Time.strptime() to parse timestamps, instead of crazy regexes.

I know you desperately need to convert your Pidgin logs to Adium format, so do a gem install pidgin2adium now!

To do: Make the code even cleaner, allow parsing a String or IO object to #parse() and #parse_and_generate(), include Enumerable in LogFile to allow log_file.each_with_index(), etc.

rails.vim and those pesky “E345: Can’t find file “xxx” in path” errors

So, I’ve been loving rails.vim over the past few weeks. I haven’t even touched TextMate.

hypnotoad

ALL HAIL VIM

But there’s one thing that’s been bothering me. I kept getting these weird errors, like this: “E345: Can't find file "spec/controllers/sessions_controller_spec.rb" in path” and I then I had to restart vim to have :Rspec controllers/sessions work again. And then at a random point, it would start giving me E345‘s again. It’s a testament to how awesome rails.vim is that these apparently random failures still didn’t deter me (or maybe I’m just kind of dumb).

Today, thanks to this Github issue, I finally found the answer: The :mkview’s in my vimrc. I had this:

autocmd BufWinLeave ?* mkview
autocmd BufWinEnter ?* silent loadview

And when I commented them out, everything worked great. Of course, now I didn’t have any views – how could I get Vim to save my last cursor position without views? Thanks to this vimrc, I found the magic snippet:

autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \ exe "normal g`\"" |
    \ endif

And voila! rails.vim works, and I have my cursor position saved!

rails.vim, rvm, ZSH, and a curious (infuriating) bug

Updated again on 3/5/2011:Thanks to the RVM website’s vim integration tips, there’s a much simpler fix. Simply put set shell=sh or set shell=bash in your ~/.vimrc, and :!rails console will work. set shell=zsh does NOT work.

Updated 11/8/2010: Thanks to Will for pointing out a mistake I made with login and interactive shells. I’ve fixed the error and added a bit more to clarify the various files each type of shell sources.

I recently ran into an infuriating, apparently nonsensical bit of trickery with RVM, rails.vim, and ZSH. I couldn’t reproduce it with Bash.

A Bit of Background

You can skip this if you want.

  • RVM (Ruby Version Manager) is a command line tool that allows you to switch between Ruby versions very easily. I’m currently using Ruby 1.9.2rc2 with Rails 3.0.0.rc.
  • rails.vim is a fantastic Vim plugin that provides some very nice commands, like :Rmodel <model> (edit app/models/<model>.rb) and :Rscript console (run script/console, or rails console, for Rails 3).
  • you should probably know what Vim is :)
  • ZSH is a shell made by crazy people who want to do way too much with way too many arcane commands. In short, it’s pretty awesome (and if you want to switch it’s mostly compatible with Bash, so your ~/.bashrc might still work if you run chsh -s /bin/zsh)

Please Describe the Night in Question, Sir

I was happily working my way through Michael Hartl’s excellent Rails Tutorial (you really should check it out — I found many gems [god I’m witty] like Object#blank and the annotate-models gem). rails.vim was by my side, I was switching through files like a crazy person, everything was great. Then I run :Rconsole, and this happens:

Loading development environment (Rails 3.0.0.rc)
ruby-1.9.2-rc2 > User.all
/Users/gabe/.rvm/gems/ruby-1.9.2-rc2@rails3/gems/sqlite3-ruby-1.2.5/lib/sqlite3_api.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

Emphasis mine. Uhhh, what? I installed sqlite3-ruby like a faithful Rails acolyte (I even used bundler!). Why was rails failing me? Well, first clue: that “Ruby 1.8.7”. Why was vim using my ruby 1.9.2 sqlite3-ruby gem, but giving me a 1.8.7 version?

<2 hours later, after slogging through Google, Ruby forums, and ZSH docs>

The answer: Vim wasn’t sourcing my ~/.zshrc, and therefore not running my RVM scripts, and therefore Ruby 1.8.7 was trying to use the 1.9.2 gem and choking.

Quick fix: source your RVM scripts in your ~/.zshenv:

source "$HOME/.rvm/scripts/rvm"

But why?

Here’s the key: Vim sources dotfiles (~/.zshprofile,  ~/.zshrc) in a different way than the shell itself does. When you open up a terminal, that’s an interactive (and login) shell and so (among other files*), ~/.zshrc is run. But Vim isn’t a login shell. (It isn’t even an interactive shell.)  It doesn’t source ~/.zshrc. Instead, it only sources ~/.zshenv, because everything sources that, not just login shells. For more info, see this section of the ZSH manual.

Note that taking every single RVM reference out of my Bash dotfiles still didn’t make rails.vim choke — not sure what was going on there. I sourced my RVM script in the login shell, then ran Vim, and it didn’t choke.

* It runs ~/.zshenv, ~/.zprofile, ~/.zshrc, and ~/.zlogin (as well as /etc/zshenv, /etc/zprofile etc), but I keep my settings in ~/.zshrc, so that’s the important one for me.