18 Feb 2013

Executing Ruby from Vim

Want to run a Ruby script in Vim? Maybe you’re testing a little commandline snippet. Maybe you want to run a quick query against a webpage. Maybe it’s none of my business why you want to run the Ruby script!

Well here’s a little selection of my Vimscript that accomplishes just that:

Typing your leader key (mapped to ’’ by default but remapped to ‘,’ by you, right? ) and hitting ‘rr’ in quick sequence will execute the current file using your Ruby interpreter. If you’re using RVM to manage your Rubies, you might also want to consider adding the vim-rvm extension to use the ‘correct’ Ruby.

29 Dec 2012

Trello-Archiver from Scratch

Trello-Archiver is a set of Ruby scripts that allows one to export their Trello board into a CSV, TSV, or XLSX file. It was started by another person on Github.com named Mad_Typist. Early on in the process I sent them a pull request to contribute my changes back… but they don’t seem to be around. Given that, I’ve forked the project and continued to develop it for my own benefit.

Trello-Archiver relies on a few conventions that exist in the Ruby world. 1. Project dependencies are managed with Bundler 2. A semi-recent version of Ruby is used >= 1.9.2

To use the project on a system that isn’t setup for Ruby development, the first step is to install a recent version of Ruby. I prefer to use a tool called Ruby Version Manager for this RVM.

Install a sane Ruby Version Manager along with Recent Rubycurl -L https://get.rvm.io | bash -s stable --ruby

Source the installed script to allow for using RVM this first time w/ this command: source ~/.rvm/scripts/rvm

Future logins will automatically source RVM using your bashrc or zshrc.

The next step is to clone the Trello-Archiver repo from Github.

Then cd trello-archiver and run bundle install. Bundler installs the necessary dependencies for Trello-Archiver. The nice feature about Bundler is that it manages individual projects’ dependencies independently :).

Next, cp config.example.yml config.yml. Config.example.yml is the template for where the authentication credentials are stored along with any default settings.

Open up config.yml with your favorite text editor. Instructions are inclosed in there for how to gather your secret credentials from Trello.com.

First, open https://trello.com/1/appKey/generate in your web browser. Copy the first key as your ‘public key’ and the second (longer) key as your ‘private_key’.

Next we need to enter those values into a special url: https://trello.com/1/connect?key=PUBLIC_KEY_FROM_ABOVE&name=ANYNAME&response_type=token&scope=read,account&expiration=never The two values that need replacing in this URL are PUBLIC_KEY_FROM_ABOVE nd ANYNAME. ANYNAME is a placeholder for any text that you want to use to identify this key, ie it could be TrelloArchiver. Also note that this is authorizing Read-Only access. This way, even if there’s a bug in the software the token won’t allow changes to your Trello information.

Past that value into your web browser and click allow on the confirmation webpage.

The following page that loads has your ‘access_token_key’. Copy this value into your config.yml. Save config.yml and exit to commandline.

That’s it for authentication setup! Make sure to be careful with this config.yml and don’t go adding it to any public git repos ;).

Now for backing things up :). Decide if you want a specific board backed up or all of them.

Let’s backup a single board: -ruby bin/trello_backup.rb -Choose your board by number and hit enter -Enter a filename or not (it defaults to name of board and date stamp) -Defaults to exporting as XLSX (this is easily changed in script).

Now let’s backup all the boards: -ruby bin/trello-autoarchive.rb -Sit back and wait for it to finish! -It’s set to backup all boards with default names and using XLSX filetype.

Caveats: It saves these files into the current folder. Apparently I broke CSV functionality with some recent changes. I’ll get it working again. The spreadsheet structure is what works for me. If you need a different configuration, please let me know and I’ll look into it. Not all info is backed up. For full backup, download your JSON export from Trello. The main thing that I didn’t include in Trello-Archiver is a set of timestamps for when a Card is moved to each List. This could be a future feature if others have a need for it.

Below is a Gist showing the shell commands

15 Dec 2012

rcodetools and VIM

I’ve been listening to RubyRogues which introduced me to Avdi Grimm from the Ruby community. I’ve also been subscribed to his RubyTapas screencast series which is a 2x a week Ruby show.

He uses a neat tool called rcodetools to execute Ruby code from within an Emacs buffer. Unfortunately, it wasn’t working when I tried to use the VIM counterpart, with segfault codes showing up. Here’s the fix: ( I’m using RVM to manage my Ruby Versions ) *Install Tim Pope’s excellent rvm extension for VIM cd ~/.vim/bundle git clone git://github.com/tpope/vim-rvm.git

*Install rcodetools using RVM gem install rcodetools

*Remove keybindings in other programs (ie Dashboard & Expose) for F10, F11, F12 or rebind the keys per README.vim

Now enter a VIM file and type F12 on any lines that you want the output from followed by F11 to evaluate the whole file. If you want to only re-evaluate the current line use F10 instead of F11.

It’s a great tool for terminal screencasting! Thanks Avdi for letting me know that this tool is available.