meetteem: tech addict

software development, etc.

GottaDash with Shoes

In my previous job, I regularly used the (10+2)*5 procrastination hack to boost my productivity. I was pretty comfortable with the system. It kept me focused in what I was doing. It allowed me to conserve my energy for my tasks. Sticking to the system sort of developed my discipline. Because I was aware that I was working and I had progress in my tasks, I felt encouraged and motivated to even more productive. My boss and colleague suggested that we implement a tool to facilitate that (10+2)*5 hack, and we did. The company named it GottaDash. Mikong made a JavaScript version, while I made a Flex version. In making that Flex version, I had to spend some time learning the basics of ActionScript, MXML, and the SDK because I wasn't familiar with the platform and the languages. My learning of Flex had a very good motivation -- RIA using Flex and Ruby on Rails. GottaDash in Flex was the tool I used at work.

But then my MacBook crashed, and along with its hard drive, all my programs and files were obliterated, including the source code of the Flex version. Sigh. I didn't have the time to re-implement the Flex version, and it already took a lot of my work hours, so I decided not to re-implement it.

Last Saturday, I felt that my body was missing its productivity juices; my mind, its focus. So I quickly cooked up GottaDash using Shoes, a tiny UI toolkit for Ruby.

Coding in Shoes was a little bit challenging. Why? Because I wasn't able to find a comprehensive documentation (in RDoc). I switched back and forth between my code and the Shoes manual. There was one time that I wanted to know the api of the Shoes::Every, because I wanted to subclass it. Nope. I failed to find it. It isn't in the internets? That's weird. I ended up getting the Shoes source code and going through it. I wasn't able to find the documentation for the :styles options for elements.

Another thing I had a problem with was the video command (I only needed to play the alarm sound). You can't play hidden videos. They have to be visible in order to play them. I ended up creating a stack element with a size of 1x1 pixel just to hold the alarm mp3.

So here it is. Grab it, open it with your Shoes installation, and feel the joy of being productive!

P.S. In the spirit of open source, I've uploaded the GottaDash source code in github, if you want to take a look at it. It's released under MIT license.

P.P.S. A friend recommended to me that I should set up a way to accept donations, possibly through PayPal. I haven't done so and I'm still wondering if people would actually want to donate money to me. But I sure hope that this will be useful for many. It's useful for me.

Update There are times when Shoes would crash. I couldn't trace the bug atm, but when I have the time, I'll update the thing, maybe refactor the code a little bit to make it smaller and simpler.

My Reading List

I added a small Django app to sort of track my progress in reading books. I hope this will motivate me to read the books I bought over the past year and a half. Last time I checked, I haven't even touched about 25 of my books.

So little time, so much to do.

Now, to actually add the books to the list...

LOL! Name That Code

LOL. Got this from Mia.

Name That Code

Another Django Update, 1.0 Draws Near

Django 1.0 alpha was released yesterday. I'm running this blog on trunk so I updated this blog to use the bleeding edge feature recently merged to the trunk: the newforms-admin. The last time I updated was when the queryset-refactor branch was merged to the trunk. With Brian Rosner's walkthrough and screencast, the migration wasn't a pain. It took me about 10 minutes to migrate, switching back and forth the NFA wiki and the blog code.

Thank you, Django people. You've made the world a better place.

Factory Girl!

Last month, factory_girl was featured in the RailsEnvy podcast. factory_girl is one of the best things that happened to my Rails TDD/BDD life. It's the only other thing I use with rspec and rspec-rails, though I'm pretty open, so suggestions to make making tests easier are very much welcome. The one con is that factory_girl is tied to ActiveRecord, but it's not really an issue for me because all my non-personal projects use AR. If you are still using fixtures, take a look at factory_girl. It's really nice. Anyway...

factory_girl has a nice feature that lets you define a sequence which you can use to generate unique things. For example, to generate an email address, you can do this (taken from factory_girl's rdoc):

# define a sequence
Factory.sequence :email {|n| "user#{n}@example.com" }

# calling the `next` method
Factory.next :email
# => "user1@example.com"

Factory.next :email
# => "user2@example.com"

However, one of the behaviors in my projects that is not so easy to do with factory_girl is generating unique strings that cannot contain numbers.

I added this behavior in my projects using the following monkey patch I made.

class Factory

  def self.sequence(name, initial_value = 1, &block)
    self.sequences[name] = Sequence.new(initial_value, &block)
  end

  class Sequence

    def initialize(initial_value = 1, &proc)
      @proc = proc
      @value = initial_value
    end

    def next
      prev, @value = @value, @value.next
      @proc.call(prev)
    end

  end

end

This would make the sequence more generic such that anything that has a next method can be passed. A string object has next method so we can use that to generate unique and sequential strings, with no numeric characters. For example,

Factory.sequence :email, 'aaaa' {|s| "user#{s}@example.com"}

# calling the `next` method
Factory.next :email
# => "useraaaa@example.com"

Factory.next :email
# => "useraaab@example.com"

We can even implement a PrimeSequence class and pass it to Factory.sequence to generate a prime number sequence. ;)

Last night, I forked factory_girl in GitHub and applied this monkey patch to the fork. The clone url is git://github.com/teem/factory_girl.git. You can check it out here. I've included specs as well, which has the prime number sequence I mentioned earlier.

Hope this helps you in making the world a better place.

P.S. I recently found Rick's model_stubbing. I haven't looked at it so atm, I have no idea how it works, but the features look promising.

Tagging

I've added tagging to this site. As most of my avid readers know, this blog is made in Django.

A little background how I did it and why I choose to do it that way.

I had two options on how to implement tagging: generic relations using the contenttypes framework and many-to-many relations.

I went with the many-to-many relationship primarily because I had the impression that Contenttypes API isn't stable atm:

Generic relations will most likely be moved out of core and into the content-types contrib package to avoid core dependencies on optional components.

Well, as far as I can see, the django trunk has already made this change.

The second reason I went with the ManyToMany relationship was because I didn't need or want the Generic relations. I just needed to tag posts.

So there.