Category Archives: Uncategorized

Monkeypatching for cleaner code

Recently, after reading Object on Rails, I started thinking and experimenting with various ideas of making Rails applications code cleaner. Here’s one of these ideas.

Let’s imagine we have two model classes, connected with a has-many/belongs-to relation, e.g.:

# file user.rb
class User < ActiveRecord::Base
  has_many :posts, dependent: :destroy
  # ...
  # rest of the user stuff
  # ...
end
# file post.rb
class Post < ActiveRecord::Base
  belongs_to :author, class: "User"
end

The above code is probably how most of Rails programmers would go about implementing a “user has many posts/post belongs to its author” scenario. It’s the tutorials-approved way. But when you look at it from a architectonic point of view, you have just created a circular dependency.
Continue reading


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


The endless cycle of code vs docs

Hereby I present to you a very first chart comic on this blog.

The endless cycle of code vs docs

Click picture for full-sized version

Nods and acknowledgements to The System Comic. I hope they don’t mind the stolen graphic. Any similarity to this particular comic is not quite unintentional.


WeekProgress — complete iPhone application source code available

While you weren’t watching I went and created a small iPhone app: WeekProgress. Don’t expect too much functionality (or sense!) there – it was born mainly for learning purposes. It features a main screen and 3 (three!) screens worth of settings.

Working week progress bar

Working week progress bar

On the main screen you’ll find a progress bar that tracks your way through the working week. It starts at 0% on Monday morning and goes to 100% on Friday afternoon. The settings allow you to select working days and change working hours, so you can adjust it to your schedule.

Changing working hours

Changing working hours

And it’s free! And it features insightful and funny comments! And it looks like a couple of folks already installed this! So what are you waiting for?

But there’s more: I’ve made the source code available! And it is a brilliant and beautiful source code (if there is such thing as beautiful Objective-C code). And it features unit tests! How cool is that?


Hello World

Hello World! I knew you needed yet another blog, so here it is! :)