Showing posts from May, 2012

Simple activity tracker for Linux

Sometimes it is funny to gather some statistics about your activities - how much time you spend reading, how much time you spend programming, etc. There is a Gnome panel app specifically for that purpose - Project Hamster . It does it's job well, but not well enough - it still requires you to manually specify start and end of each task, and I often forget to do that. But why do we need a full-blown app for such simple thing? I really think that we can mine most of the needed information simply by analyzing the focused window properties (actually, just two of them - process, that owns that window, and title of window). For example, when the main window is from "evince" program, then I'm probably reading some book, if it is Emacs or terminal, I'm coding, if Opera - most probably reading feeds. Window title is needed only in specific cases, when you can't differentiate based on the program executable name - sadly, most of python programs fall into this cat

Running code after subclass initialization

Sometimes you need to run some code after the subclass initialization - for example, if it is a library class that users extend and you need to check their configuration. The simple solution will be simply to obligate user to call some method in your class after he is done, but it looks redundant, prone to error, and not beautiful overall. It turns out that Scala has no obvious mechanism for this, so I needed to go through some hoops to achieve the needed effect. My idea was to use the DelayedInit trait  (which is deprecated now, sadly) in order to get the initialization bodies for the parent class and subclasses, then execute them in "delayedInit", and count the amount of times it executed. Since I can get the number of superclasses for any given class, I can just execute the after-init code when I've seen enough initialization bodies. I wrapped this into a trait for easier reuse. Note that if your class extends some other non-trait, you'll need to override