Currently showing posts tagged: hacking

measuring email inbox sizes

By Adam, November 28, 2010 6:35 pm

Like many people, for a long time I have been drowning in email. I am perhaps bit unusual in that whilst my personal google inboxes are permanently overflowing, my work inboxes are generally very close to empty. This is because as a (bad) practitioner of GTD and sometime reader of Inbox Zero and similar sites, I do actually know how to get grips with email, and through professional pride apply the techniques fairly religiously when I’m working. In contrast, when it comes to dealing with personal mail, I’ll always favour procrastinating on some other interesting project instead. God forbid I should ever get my personal life in gear!

Well, this bad habit has been stressing me out for a LONG time now. I’m a long-term fan of Gretchen Rubin’s Happiness Project, and the other day stumbled across one of her older posts entitled Measure what you want to manage. I’d been wanting to graph the size of my inboxes over time, to get some grip on how bad my backlog actually is, and her post gave me the nudge to actually sort it out.

As usual, Ruby makes it almost ridiculously easy. There’s a beautiful written gem called gmail which uses IMAP to talk to your gmail account. So then it’s just a matter of writing a little program to append a line of gmail folder sizes to a CSV file every time it gets run:

#!/usr/bin/env ruby

require 'pathname'
require 'rubygems'

# sudo gem install gmail
# Note: this is an improved version of Daniel Parker's ruby-gmail
# http://rubydoc.info/gems/gmail/0.3.4/frames
require 'gmail'

# sudo gem install fastercsv
require 'faster_csv'

USERNAME = 'your.account.name.goes.here@gmail.com'
PASSWORD = 'your.password.goes.here'

CSV_FILE = Pathname(ENV['HOME']).join(
  "choose", "a", "path", "to", "gmail-counts.csv"
)

labels = FasterCSV.open(CSV_FILE, 'r').shift[2..-1]

FasterCSV.open(CSV_FILE, 'a') do |csv|
  Gmail.connect(USERNAME, PASSWORD) do |gmail|
    now = Time.now
    counts = [ now.to_i.to_s, now.strftime("%Y/%m/%d.%H:%M:%S") ]
    labels.each do |label|
      unread = label.gsub!(/ unread$/, '')
      folder = gmail.mailbox(label)
      count = unread ? folder.count(:unread) : folder.count
      puts "%s: %d (%d unread, %d read)" % \
        [ label, count, folder.count(:unread), folder.count(:read) ]
      counts << count
    end
    csv << counts
  end
end

Then create gmail-counts.csv in the folder referenced in the script, whose header line contains a list of the labels you want counted (append unread if you want the unread count rather than the total, and prefix “special” gmail folders with [Google Mail]/. Here’s an example of the header followed by a single line of folder counts:

epoch,datetime,INBOX,INBOX unread,[Google Mail]/Drafts,music
1290873125,11/27/2010.15:52:05,555,20,12,1596

Then make sure the program is automatically run on a regular basis somehow. On Linux this is as simple as adding a new line into your crontab. My quietrun utility comes in handy for this:

0 6,12,18 * * * quietrun /path/to/script/count-gmail

Then you can use Google Docs or your favourite spreadsheet / charting application to plot some nice graphs. I used this script which is written in the Ploticus graphing language; here is the result:

sample graph of gmail inbox size over time

Easy!

UPDATE 5 months later! (15th May 2011): I finally made it!

Share

Maven fail

By Adam, October 7, 2010 8:18 pm

In my recent work I have encountered Apache Maven, and I think the following snippet of real-world Maven code nicely sums up why Maven is not the idea replacement for the horror that is ant:

  <profiles>
    <profile>
      <id>unix</id>
      <activation>
        <os>
          <family>unix</family>
        </os>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>set-run-file-perms</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>chmod</executable>
                  <arguments>
                    <argument>0755</argument>
                    <argument>${project.build.directory}/foo.sh</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

Dear god. 34 lines and a plug-in, just to change the permissions on a file in a platform-specific way??

I should add that the above was written by an extremely smart guy who is a top-notch programmer; no, I don’t think the author is at fault here. Even if there’s a more concise/portable way of achieving the same result in Maven (and there might well be – I admit I’m still a Maven newbie), there’s still the undeniable fact that XML is horrendously verbose, and any code written in it is by nature unnecessarily difficult to maintain. To this end I applaud the ongoing efforts supporting the use of YAML to implement the Maven POM.

It’s worth seeing what the above would look like if we wrote it in rake:

require 'pathname'

desc "Make binary executable"
task :chmod do
  File.new(Pathname.new(build_dir) + "foo.sh").chmod(0755)
end

I don’t think I need to make a case for which is more legible or maintainable. Oh, and the Ruby version is cross-platform.

To continue an anti-XML rant which has been made countless times already: what the ant and Maven people don’t seem to realise is that XML is not a real programming language and is therefore not expressive enough to deal with many cases that a build system needs. The clue’s in the name, guys! “M” is for “markup” not “Turing-complete“. That’s why every time you need to do something vaguely unusual for which there isn’t an ant taskdef or Maven plugin, you have to write hundreds of lines more Java/XML just to cope with that case. That’s why Maven needs so many damn plugins.

The accidental silver lining to this is that because it takes so much effort to accomplish simple tasks, Maven developers find themselves compelled to reuse and share plugins, and to be fair, Maven has some good ideas on how to do this, even if the implementation isn’t always the best. For example, the built-in plug-in repository management and plug-in dependency management seem to work nicely, but unfortunately for some reason it has a propensity to download plug-ins on most runs, far more frequently than any sensible caching layer should.

DSL issues aside, I’m not convinced by the fixed lifecycle philosophy behind Maven either. I wonder if it was borne out of frustration with the lack of proper dependency checking in ant.

That said, I do like how Maven encourages standardization of the build lifecycle and phase namespace thereof, since newcomers to a project immediately know some familiar entry points. But the same could be said of 99% of projects which use Make and use standard rule target names such as install and clean. And I suspect that many developers suffer when they try to shoe-horn their own project’s build requirements into Maven’s standard lifecycle.

My concern with this phased approach is that it is too linear.  The expectation is that a build process is a one-dimensional sequence of steps, and you get to choose your starting point but not much else.  This seems fundamentally wrong to me.  A build dependency tree is well understood to be a DAG, and any build system which doesn’t model this properly seems to me to be burying its head in the sand.  On the other hand, if it does model it properly, which includes implementing proper dependency resolution, the required build lifecycle should emerge naturally without having to dictate that generate-sources comes before compile which comes before test and so on.

I’ve had some ideas of what the ideal build system looks like, and how to get there from the conventional Java world. More on that soon.

Share

ant dependency FAIL

By Adam, January 5, 2010 2:28 am

Oh wow, that’s four hours of my life I won’t get back.

Four hours trying to figure out why the hell my changes to .java source files weren’t showing up in the compiled binaries, debugging an unholy mess of ant XML files, before I finally realised how badly ant’s dependency checking sucks … Then 5 minutes of googling for ‘ant sucks’ and I find two excellently written rants which confirm my discovery (you might need to consult google’s cache for the latter).

I shouldn’t have been surprised.  Anything which uses XML as a domain-specific language should have already set the alarm bells ringing, but my excitement at learning something new initially blotted out the dull headache caused by hacking in XML.  Bah!

Share

Panorama theme by Themocracy