The other day I came across a puzzle that involved implementing a spreadsheet class. Like a
regular spreadsheet the cells were referenced as A1, A2 etc .. I wanted to iterate the cells
in the spreadsheet. My first stab at the implementation looked as follows
Spreadsheet iteration v1
But its possible to have a nicer interface to iterate over the cells by implementing Iterator
trait. It also results in better encapsulation of the internal structure of the Spreadsheet
class. Following is an implementation of Spreadsheet class with Iterator trait.
Spreadsheet iteration v2
The iterator code is not a core part of the Spreadsheet’s logic so there is no need for the
Spreadsheet class to directly implement Iterator. The iterator implementation can be moved out
into a separate class and the Spreadsheet class’s implementation can be kept simple.
As many of you might know that the HBase shell is a jruby repl. So you can write ruby code in the
shell. You can also save your custom ruby functions in ~/.irbrc and the next time you
start the hbase shell those functions will be available to you. At work I often need
to truncate a bunch of HBase tables before I can begin my testing. I wanted to automate
this. So I wrote the following custom function to truncate a list of tables and added
it to my ~/.irbrc
You have to restart your HBase shell for this function to be available in the shell.
Now this custom function can be invoked from the shell as follows
For more information refer to the following links: