Tag Archives: ruby

Hash bars – simple ASCII-art charts in your console, database or Excel

When you have some data like this:

MONTH COUNT
2011-10
417
2011-09
903
2011-08
1051
2011-07
759
2011-06
835
2011-05
647
2011-04
393

it may be difficult to spot a trend in it. That’s why people use charts and other visualization tools and there’s a lot of them (you could use Excel, Google Charts, gnuplot, sparklines etc.).

However, sometimes it’s not possible or convenient to use any of this tools. In such cases, you can easily create a simple ASCII-art style chart. Doesn’t this look better?

MONTH COUNT  
2011-10
417
########
2011-09
903
##################
2011-08
1051
#####################
2011-07
759
###############
2011-06
835
################
2011-05
647
############
2011-04
393
#######

It’s actually so embarrassingly obvious I would not bother posting about but in the last couple of days several people told me that they think it’s a great idea that they wish they knew earlier. So here it is.
Continue reading


Java and Ruby: how language principles influence users’ mindsets

I’ve been doing some Java development lately and Java’s verboseness sent me looking for a way to shorten some of the monstrous generic type declarations. I know there is no typedef or similar concept in Java, but hoped that maybe some Java or Design Patterns gurus invented some clever trick or pattern to do something similar. It’s better to use a ThreeLevelHashMapOfStrings type instead of HashMap<String, HashMap<String, HashMap<String, String>>>, right?

Continue reading


Using assert’s message to boost your unit testing productivity

Here’s a quick tip for enhancing your test writing productivity: use assert‘s last parameter, the message. Virtually all assert_... methods accept it. You may have noticed in the docs that the last parameter is always message = nil or message = "". Too bad the docs don’t give examples on how to use this message. So, let me fix that.
Continue reading


TextMate shortcuts you should be using

This is my list of TextMate‘s keyboard shortcuts that are very useful for Ruby and Rails developers, but are not used as widely as they should (according to my very scientific observation on a very representative sample, i.e. my colleagues). I skipped all the obvious ones (like “open file”, “save file”, “go to next window”, “close window” etc.) that most people use anyway. My list includes shortcuts that are very useful but sometimes might be hard to grasp at first or might require a little explanation.
Continue reading


Cromwell version 0.4 is out!

While you weren’t looking, Cromwell — Lord Protector of your scripts turned 0.4. The new features include:

  • logger support,
  • inspect and change Cromwell’s state,
  • restore original traps after protection end,
  • custom traps support.

…and I have run out of To Do list items. So if you use Cromwell (the gem has been downloaded 165 times from Gemcutter as the time of this writing and the github project has 22 watchers so I assume there are some users of it) and you miss some feature or you found some bug or incompatibility, let me know. Otherwise, happy protecting!


Exploiting obscure Ruby quirks for fun and profit

Here’s one quirk I accidentally discovered in Ruby. Check this out (this is copied from my irb session):

>> defined? x
=> nil
>> x
NameError: undefined local variable or method `x' for main:Object
	from (irb):2
>> if false
>>   x = 3
>> end
=> nil
>> defined? x
=> "local-variable"
>> x
=> nil

What’s going on here?

Continue reading


Eliminating code duplication with metaprogramming

Duplication of code is one of the worst code smells. It should be refactored in order to keep DRY if only possible. This is generally easy. But what if the code itself is not duplicated, but its structure is? That could be a little bit more difficult, but with Ruby‘s metaprogamming facilities it’s not that hard. Read on to see how.

Continue reading


Follow

Get every new post delivered to your Inbox.