Having a highly optimized and productive development environment is key to being efficient when writing software.    In this short 7min video on writing web apps (for Rally  Software but that’s irrelevant to this post), I present a wicked near mouse-less, browser-based development environment with Chrome that keeps your hands on the keyboard and yields a rapid dev/test cycle.

Screen Shot 2013-12-15 at 10.56.26 AM


Chrome, Chrome Terminal, Tmux, Vim  (or other CLI editor, like that heavyweight emacs – ha!)

When writing software, we’re all free to choose any tool that slows us down.  Take a moment every week and every month to realize there may be a better, faster, more effective set of tools to make your coding life easier!


Tonight I was reviewing my linux syslog for a totally different problem.  To my amazement, this log file was alive.  literally.  It was growing at a rate of 1Mb / 15min.   The follow log message was feverishly printing out several times per second – and it had been happening for days.  Good thing I have several Tb of free space ;)  [note: I installed ubuntu 12.04 on my alienware aurora last weekend].

Sep 12 22:34:59 aurora kernel: [  108.809444] [fglrx:irqmgr_wrap_enable_hifreq_interrupt] *ERROR* Failed to enable IRQ source: 1610613760

I found no solutions online except for some guy who posted the same error message on his twitter account… We’ll see if he has any advice.

In the meantime, I followed this guide and booted my kernel with the ‘noapic’ option and the logging abuse stopped.  Note: in grub menu, press ‘e’ to edit and add ‘noapic’ to the linux params (e.g. I put mine here ‘…. quiet splash noapic …’)

For the rest of the world, here are my specs in case you encounter a similar situation:

Continue Reading »

ESCape the help

Years ago, I started using 2 keyboards for fun… simultaneously.   A happy hacker on the left and an ancient (ps/2), cover stripped dell with exposed keys on the right.  Fun times.

TactX Keyboard

Nowadays, my use of two keyboards depends on the sun cycle.  By day, I code exclusively to the harmonic Model-M style clicks of a Das Keyboard Ultimate.  By night, when the kids go to bed (adjacent room), I switch to my quieter Alienware TactX with programmable backlights — fitting for night time hacking.

F1 adjacent to ESC

Now that we’re caught up, here’s my point of this post.   The TactX keyboard, while fun, has been frustrating me to no end because of a custom vertical row of Function keys on the left side adjacent to the ESC key (see pics)   This means that bloody F1-mapped “help application” launches 100+ times per day as I’m using vim and toggling modes hitting ESC.

Key remapping to the rescue.   Tonight, in Ubuntu (12.04) I not only prevented the help app from launching when hitting F1, but I mapped F1 to… ESCape!    Now my fat fingering can keep on trail blazing.

  1. $ xev     # hit any key and record the keycode displayed
  2. $ xmodmap -pke  | grep <keycode>     # confirm what is mapped to the key
  3. $ xmodmap -e ‘keycode 67 = Escape’
  4. [Optional] Add ‘keycode 67 = Escape’ to $HOME/.xmodmaprc for persistent settings

So what about accessing that help application?   phhht…  that’s what man pages are for :)

My favorite new hotkey for launching a terminal is Alt-LShift.


Today’s adventure in technology included a visit to an old, old friend… Oracle sql*plus.

I’m migrating/generating/transforming data and need to spool the output to a several files who’s name are specific to a particular ‘run’.   So I wanted to dynamically name the output file.   After 20min of finding dead oracle links and basically no solution, some thoughtful hacking found a good solution.  The following lets me pass in a name and uses it to construct the output file:

-- gen_data.sql
-- Usage: sqlplus @gen_data <filename>
SPOOL output_&FILENAME\.sql
... # bunch of sql

Notice the backslash in \.sql.   If you don’t do that, sql*plus automatically forces the file extension to be ‘.lst’.  Odd.  But I stopped asking quesions about why sql*plus works the way it does 10 years ago…

Hope this helps somebody.

food for google: dynamically generate sqlplus spool output filenames

Over the last few months I have been deep in my latest VIM integration (announcement coming soon) written with 95% ruby (core) and 5% vim (wrapper).  At this point in it’s development I have proved out the functionality for vim-ruby communication, key mappings, data display, CRUD operations, exception handling, logging, and most importantly, aspects of (mouse-less :) usability.  Now, there is clear line of sight to start building functionality at a very rapid pace.  However, I am forcing myself to stop. cold.

Stop. Think. Refactor.

Why stop?  To stop and embrace the evolutionary aspect of designing the architecture.   If I continue, I run the risk of building 10-20x more code on top of user paths with incomplete exception handling, lots of FIXME and TODOs, and quite frankly, various areas with fairly good but really just prototype code.   The existing code is not a loss.  Rather is was a series of experiments; ‘successful’ experiments.  Even the failures were a success.  And I refactored a lot along the way, so the current body of code is still quite valuable.  But it’s time to inspect.

Example:  Loading ruby classes.

I struggled a lot with LOADPATH visibility in the ruby runtime embedded inside vim.  If you ‘require’ a file in your ruby class, it tried to open that class file relative to the current directory where you’re generally editing – not your vim plugin lib path.   This actually turned out to be OK because I started to just ‘require’ all the files up front.  But I had to register the names manually, load base classes before subclasses, and I didn’t want to load the universe of classes in case the plugin failed to load (e.g. remote service not available).

Refactor: This weekend I was surfing the ruby Kernel API and was reminded of ‘autoload’ to simply register the files to load only if the Class/Module is actually referenced.  I turned about 20 lines of code, located in 2 files, with nested conditions, into the following solution that relies on the [Rails-like] convention where camel-case class names match underscore filenames:

 53   # Pre-register ALL ruby files to be loaded on-demand^
 54   # convention: underscore filename => camelized module^
 55   # example: update_task_todo_controller.rb --> :UpdateTaskTodoController^
 56   rbfiles = File.join(VIM::evaluate('g:rally_lib_dir'), "ruby", "**", "*.rb")^
 57   Dir.glob(rbfiles).each do |filename_abs|^
 58     filename_noext = File.basename(filename_abs).gsub!(/\.rb$/, '')  # extract name of file, no extension
 59     modname = filename_noext.gsub(/(^|_)(.)/) {$2.upcase}  # camelize filename^
 60     autoload(modname, filename_abs)^
 61   end^

Example: Global variables.

Yes.  I know.  I felt dirty at the mere thought of using a… glo… glob… global variable.   But after looking at the code, almost 90% of it used the same variable that was passed around EVERYWHERE.   It was the connection class to the remote service that also served as a cache… the whole plugin relies on this connection across the board.  Now the initial architecture is fairly MVC… but this means that the controller grabs the connection, passes it to the model, the model passes it to utility classes.  And only the handful of view classes are immune.   This also meant that automated testing would require… ugh… mocking a connection and passing to all test classes.

Refactor:  I created a single top-level global variable ($conn).  This cleaned up SO much of the API that using the global variable actually felt… clean.   Now I’m not advocating that it was the most pure approach, but from simplification of the APIs and code… it was a great!

68   $conn = ConnectionController.new.conn^

Example: Testable ruby.

In vim, if you want to envoke ruby code, you do this:

10 ruby << FOO
11 puts "bar"
12 FOO

That only makes your vimscript file get messy by having so much ruby code mixed with vimscript.  So instead, you can tuck those lines above into foo.rb and within vim do:

10 runtime /path/to/foo.rb

But that’s the problem!  Look at your ruby file.  The file is flanked by the vim/ruby load syntax “ruby << FOO …. FOO”.   So you can’t load that foo.rb file within ruby for independent… TESTING!   I had a much bigger problem writing tons of ruby classes that couldn’t be tested (easily) than dealing with a single global variable.

Refactor: Turns out that the first example above solved this issue entirely.  By using autoload() to preload the files, those files are written entirely in pure ruby.  Solved.  Now all classes can be loaded and independently tested.


I want to also add more exception handling for core activities,  support for trap’ping interrupts (e.g. user hits CTRL-C during network activity), and review the MVC flows that currently require 5 files (controller, model, view, formatter, display manager).

I’ll “lose” about 2 weeks doing this architecture refactor.    But I’m confident that it’ll make adding features 2-3x faster and the overall codebase will be maintainable.

Ah the joys of programming.   Like spending 3 hours tracking down an elusive segfault :(

Today I managed to crash Vim with a custom ruby-based plugin I’m writing.   I can’t find any solutions on the web and don’t have time for a full day of gdb coredump debugging but managed to narrow down the culprit.   Posting this in case someone else encounters a similar situation — and drop me a line if you do!

Here is the helpful information that Vim spit out:

Vim: Caught deadly signal SEGV
Vim: Finished.

This is the ruby code initiating the segfault (line 27):

26   c.each_index do |i|^
27     VIM::Buffer.current.append(i, c[i])^
28   end^

Here is the vimscript used to create a new buffer into which the above line tries to add new lines:

241   " launch new buffer^
242   exec "silent botright new"^
243   " create a 'scratch' buffer that cannot be saved^
244   setlocal nobuflisted^
245   setlocal noswapfile^
246   setlocal buftype=nofile^
247   setlocal bufhidden=wipe^
248   setlocal nolist^
249   setlocal nonumber^
250   setlocal foldcolumn=0 nofoldenable^
251   setlocal showbreak=>>^
252   setlocal wrap^
253   if has('syntax') | setlocal syntax=rally | endif^

Turns out that removing the bufhidden=wipe setting solves the segfault crash.  So something with the ruby VIM::Buffer.current is conflicting with that setting.   I’m not sure what… but at least i’m not choking anymore.

I’ll followup if I get clarity on this situation…