RedBook - A simple Ruby program for your daily logging needs

Posted by h3rald Sat, 29 Sep 2007 20:05:00 GMT

Logging your daily activities is important. If you don’t believe me you’d better check at least these three posts on LifeHacker, which feature different scripts and applications:

I had a look at each one of them, and I believe they are quite useful, although I didn’t really find what I was looking for. Why? Well, for example:

  • I don’t believe a GUI is necessary—you’d better off with just a shortcut key or command to run from Launchy or QuickSilver, that’s much faster.
  • They just log timestamped messages on a file, there’s no real way to search through them and display them except by using a test editor
  • They are Windows only—not that it matters for me, but others may not be happy about it.

That’s why I thought I’d roll out my own: meet RedBook. Let me say it’s nothing fancy: I’m not a full-time programmer but I do like playing with Ruby during my lunch breaks at work, so that’s why RedBook is just a humble, tiny Ruby script. This automatically makes it cross-platform: you can install Ruby very easily on Linux & alikes, Mac OS X and Windows. Furthermore, if you are on Windows and for some weird reason you don’t want to install Ruby, you can just try out the packed EXE file (made with RubyScript2Exe)—it’s about 2MB, but you won’t need anything else.

Read more...

Posted in  | Tags , , , ,  | 11 comments | no trackbacks

Introducing RedBook (and the new Code section)

Posted by h3rald Sat, 29 Sep 2007 08:12:00 GMT

I’m somehow pleased to announce the opening of a new section on this site. Nothing too big actually, it’s just a page with a few (one for now) brief descriptions of open source programs and scripts I made and I’d like to share with my readers.

Don’t expect fancy stuff: (luckily) I don’t code for a living, I code for pleasure and I code small things. Lately I’ve been trying to write a small Ruby program able to log my daily activities and also display them in a pleasant enough way, so I started using my lunch breaks at work more constructively and I came up with RedBook an interactive command-line program written in Ruby.

Main features:

  • Log timestamped and tagged messages to a single YAML file
  • Load and display messages containing a certain string, or certain tags or within a time frame.
  • Calculate the time elapsed between two or more tasks.
  • Export loaded messages to YAML, TXT or CSV format.

All done via command line via simple commands:

:log This is a test message :tags test

:load :last 30 :from last week

:timecalc 2 5

:save test.txt

Thanks to the wonderful Chronic library, you can specify your time frames using natural language expressions like “8 in the morning”, “this tuesday”, “last month” and so on…

Here’s a screenshot showing RedBook in action:

RedBook is of course free, open source software licensed under the terms of the BSD license. It can be installed on any machine able to run Ruby and there’s also an EXE version for the lazy windows folks who don’t want to install Ruby, packed with RubyScript2Exe. A more in-depth article explaining how RedBook works will hopefully be completed soon is available :here

Posted in  | Tags , , , ,  | no comments | no trackbacks

To REST or not to REST?

Posted by h3rald Mon, 24 Sep 2007 11:48:00 GMT

Lately I’ve been reading quite a bit about Rails’ REST approach, and to be totally honest I’m not 100% convinced it can always be a good idea. The purpose of this post is to re-evaluate the situation, and ask other people their opinion on the matter.

Let’s see…

Key Benefits

To cut a long story short, from my understanding REST can be a good thing because:

  • It introduces the powerful concept of “resources”, which is independent from the presentation. This basically means that you can have your “resources” represented in HTML. XML etc. etc. “for free”. If you are making an extensive use of web services, this is truly a bless.
  • Each CRUD action is carried out using a different HTTP command (get, post, put and delete). At present, because most browsers don’t understand PUT or DELETE requested, this is somehow simulated by Rails.
  • By thinking and modeling your application in terms of resources, everything should always be “in the right place”.

Downsides?

Let’s now try to summarize what made me think more carefully this approach…

  • While I really like Rails’ convention over configuration philosophy, this sounds a tiny bit too extreme for me. In the end it could be good, but it requires developers to completely re-think the way they develop their application in order to be 100% RESTful.
  • URLs aren’t that pretty anymore. While someone suggested a way to improve the way RESTful URLs look, that sounds like extra hassle to me. It’s subjective, I know, but I really don’t like using IDs in the url… I’d rather go for an univocal code any day (check out this site… I don’t even like dates in my blog).
  • Sometimes, it may take quite a bit to figure out how to model some functionality using resources. While it is straightforward when you want to perform CRUD operations, modeling a search action or authentication may be a bit tricky and may also feel a bit forced. Again, maybe it’s just me.
  • It may be a bit too early to take full advantage of this approach. PUT and DELETE are simulated, and this doesn’t sound right—agreed, that’s the only way for now, but it still sounds like a forceful workaround. Browsers are not RESTful (yet)!
  • All resources are virtually accessible by a URL. I’m not a security expert, but this scares me a bit.

Here are some posts which made me think a bit:

The bottom line is: is REST really worth the hassle? Especially for small and simple applications like a blog, is it really worthwhile to coerce myself to adopt a RESTful approach when I could accomplish exactly the same things with much less hassle?

In other words, is REST really the answer to everything or in some cases it is just not necessary?

And also (OK, this may sound harsh and impolite): does it really make sense to push people to adopt a RESTful approach no matter what? Sometimes someone may get the feeling that Rails is all about REST now. Is that true, or is there still room for freedom other views?

Looking forward to hear your comments, but please be nice and civilized!

Posted in  | Tags  | 8 comments | no trackbacks

Simply On Rails - Part 4: Quick and Easy Default Data Migrations

Posted by h3rald Sat, 15 Sep 2007 19:10:00 GMT

In the last post of this series I tried to find a DRY solution to deal with tables storing “ancillary” data, i.e. names of user roles, predefined categories, page state names and other similar things. I personally chose to put this kind of data to make my application more dynamic, although I could have decided to use ENUMs or simply ordinary varchar fields—that would have been easier, but less flexible. For now, I’m sticking with my original choice.

The data in these tables is kind of a prerequisite for the application to run: I must be able to have a status to assign to a user when creating it, and the same applies to roles. Sure, I could spend 20 minutes populating these tables manually, but it would be nice if there was a less tedious way, wouldn’t it?

There is indeed. The inspiration came from a technique described in the book (which I highly recommend) Agile Web Development With Rails, in which the author outlines how it would be possible to use Rails’ fixtures and migrations to load data in the database automatically from YAML files. All you have to do is create a migration to load the specified YAML files and you’re all set.

I wanted to take a little step further, allowing the migration to load data from all YAML files in a specific directory, automatically.

Read more...

Posted in  | Tags , ,  | 4 comments | no trackbacks

10 Reasons to Learn Ruby

Posted by h3rald Wed, 05 Sep 2007 18:40:00 GMT

Preamble

I discovered Ruby fairly recently, through the excellent Ruby on Rails framework1. Although I don’t consider myself a Ruby expert by any means, I read the PickAxe2, I’ve coded a few utilities for my personal use in Ruby and I’m currently developing with Rails during my free time. Ruby is currently my programming language of choice; I started off with Turbo Pascal in high school, discovered C and C++ at university, did my thesis in Java and learned PHP from scratch because I wanted to learn how to make websites quickly and easily. I guess I feel compelled to code sometimes, more as a form of entertainment than anything else. Rather dissatisfied with what I tried language-wise, I was determined to start learning either Python or Ruby. I chose the latter because I didn’t want incorrect indentation to break my code3, and here I am, heaping praise upon it.

There are plenty4 of introductions, tutorials, articles and essays of different sorts which aim to guide the novice and advise the guru on how to get the most out of Ruby. This article, however, is not one of them.

It’s more of a modest, humble, and incomplete list of a few reasons which may (or may not) entice you to use Ruby or at least play with it a bit. A word of caution: if you are using another programming language for work or whatever, don’t complain to me if you don’t want to use it anymore – that’s exactly what happened to me, but luckily, it didn’t matter. Ruby is a very beautiful and elegant language, but like all things of this sort, it may well poison your mind and corrupt your soul…

You have been warned.

Read more...

Posted in  | Tags  | 27 comments | no trackbacks

Too many cooks... take #2

Posted by h3rald Sun, 02 Sep 2007 12:41:00 GMT

Today I was not going to post on my blog. I have the flu, I don’t feel very well so I started reading some news feeds on Google Reader. That lasted for about half an hour, so I decided to check my old Netvibes account where I kept other feeds, including a bunch of CakePHP-related blogs.

Two posts immediately grab my attention:

I don’t trust CakePHP or what should you say in public?

and

Bye, bye, CakePHP team

They’re both from Daniel’s cakebaker blog, the one I used to read when I was really into Cake.

To cut a long story short, apparently Daniel said something wrong and he got “what he deserves” for speaking out. Naughty boy!

That’s because it might have put “CakePHP and the team in a bad light”. Well, I don’t know about that, but definitely now it IS in a bad light!

I even found a bunch of comment which link this incident to what happened to me a few months ago:

“I said it when Fabio/H3rald left, and I’ll say it again—I think the biggest weakness of Cake is that the core dev team is quick to cut people out who don’t hold to every dogma the devs do. Fundamentalism, ego, call it what you will, a great community will only count for so long if the core keeps alienating its biggest allies. (not that they’re neccessarily alienating you, dho. I truly hope you stick around. You do seem to be taking it well.)”

^ Whoever you are, you’re 100% right.

A core asset (at least for his writings) of the CakePHP team is gone, and another (big) chunk of CakePHP PR strategy is out of play, now, it seems. While I’m sorry the CakePHP community has to get the butt-end of it as always, I’m certainly happy for Daniel who, like me, will now have a chance to look around and experiment with new things. That’s right man, Rails or Django are the way to go.

Posted in  | Tags , ,  | 3 comments | no trackbacks