One of the things that bothers me the most in software development is when you come across a problem for which there simply is no nice solution to be found. You come up with some ugly hack and get the job done, but the nagging feeling of having fallen short lingers for days.

Problem in question: A project I’m working on sells stuff and uses a payment gateway for this. API access is expensive so we’re opting for the proxy method, meaning that the page that reads credit card information is actually served by the payment provider. It looks something like this:

http://epay.dk/proxy.cgi/http://myshop.com/payment

This means that our /payment page is a very special case. All asset paths must be relative, ie. images/foo.png instead of /images/foo.png. In contrast, links must be absolute, http://shop.com/about instead of /about.

I want the rest of the site to follow normal Rails conventions, so I need to special case this very page. This in itself is a challenge, because as it turns out my ugly hack will affect the application layout as well.

I first tried a few different routes:

  1. Override url_for and set :path_only => false. This solves only half of the problem (asset paths would still be wrong) and turned out to be painful because of the two different url_for implementations. Figuring out why is left as an exercise for the reader because frankly, I can’t be bothered to explain why. Leave a comment if you want to know.
  2. Define some default_url_options. For some reason, I never got this to work reliably, and after some time of fruitless digging trough the Rails source, I abandoned the idea.
  3. Create middleware that kicks in only if controller == Xxx and action == Yyy. It would then process the HTML and change href=”/…” instances to be relative etc. You may object that this is a terrible way of abusing the middleware system, but if it had worked, it would actually have been the least intrusive option. The reason it broke down was unexpected and enlightening: I was able to rewrite the HTML, but afterwards the Apache module pagespeed rewrote it again to optimize CSS includes etc. Obviously this only happened in our production environment, so it took me a couple of hours to track down.
So it would seem that my quest to solve this (somewhat) elegantly had failed. So be it. Time to resort to the nasty hacks.

The solution

Warning: You will be appalled.

What I ended up doing was:

  • In views/layouts/application.html.haml, I only include JS and CSS if we’re not on the payment page.
  • In the payment view, I include all JS/CSS like this (notice that the path does not begin with a slash): %script{ :src => “javascripts/jquery.min.js”, :type => “text/javascript” }
  • Also in the payment view, I added some JS that absolutifies all links. It looks like this:
  $('a[href^="/"]').each(function (idx) {
    fullUrl = "http://myshop.com" + $(this).attr("href");
    $(this).attr("href", fullUrl);
  });

Conclusion

I have created some code that works, but which I’m really, really unhappy about. I hope that some day I’ll come up with a better idea and fix this, but I doubt it. Suggestions are obviously welcome – please leave a comment.


As the title suggests, I expect this to be the first in a series of articles about how I use org-mode. Right now I’m at the point where I’m really starting to see the light. I’ve known about org-mode for several years, but only recently decided to give it a serious try.

Since I started my own company, I have been looking for a simple, effective tool for keeping track of all the various projects I am working on. I’m already using Harvest to track billable hours. For detailed planning of each sprint in an ongoing project, I love Pivotal Tracker, and I’m going to stick with that for the time being.

But I needed something else to get an overview of all those projects and ideas that are floating around in various stages of completion. Both in my head, in emails, on my hard drive and in Google Docs. Something to record all sorts of metadata about each project (estimates, ideas, contracts) as well as actual work artifacts (pointers to code commits, design docs, links to user stories).

I’m going to skip the details, but I briefly evaluated Highrise (for projects and tasks), but quickly discarded it. I may explain why in a separate post, but the gist of it is just that the workflow didn’t really feel natural to me.

So I decided to have another go at org-mode, and this time I think I nailed it!

Basics

Org-mode is an Emacs major mode which provides features for organizing information in a hierarchical manner. Lists of items can be nested into sublevels, and each item can contain plain text contents. There is support for links to URLs and to places in other files.

There is also support for lots and lots of other stuff. A much better introduction can be found at the Org-mode website.

File structure

One of the things I found hard to begin with was file organization. How do you layout the directory structure? Should you create a folder per project, with files like “plan.org”, “estimates.org” etc. inside each? Or maybe organize the files by contact?

Eventually, I ended up simply having a bunch of files in a single directory:

buzz.org 
leads.org 
links.org 
notes.org 
passwords.org 
projects.org 
readinglist.org 
todo.org 
wb.org

Side note 1: passwords.org is of course encrypted and, incidentally, replaces my use of 1Password (which worked fine but I never bothered to learn 90% of its features so the UI felt very bloated to me).

Side note 2: The file notes.org collects stuff I capture with remember.el.

Everything related to projects (whether active, planned or potential), goes into projects.org. Each project just gets a top-level item with related information organized into sub-items.

Artifacts

This was the real revelation for me: Links.

It sounds trivial, and it is, but linking to all kinds of stuff seems to be one of the best ways for me to organize my work. I have no idea why I didn’t realize this sooner. One of the reasons I tried out Highrise was because of its support for organizing emails. I still think that this is pretty clever, but org-mode is just simpler and more versatile.

Example:


The text “Data model” links to the Google Doc containing the data model description. Likewise, the text “Mail about data model” links to an email (in Gmail) I sent to the client about the data model.

This is a very simple building block, but very powerful. I can insert into my project any resource I can link to, which means almost anything these days. Commits in Github, web pages (obviously), documents, spreadsheets, presentations, video clips.

Estimates

Org-mode is ideal for breaking down major tasks into subtasks, so it makes sense that it also has support for attaching estimates to these tasks.

What you see here is column mode in action. The estimates on the lowest level tasks (cyan items) are entered by hand, and Org-mode then sums up these values in the higher level items, ending up at the root with a total estimate of 36 hours.

Tasks

Highrise has support for tasks, and I’m sure it’s good.

However, I created support for tasks just by creating the file todo.org. I really don’t need anything more fancy than a list of text strings right now. When I do, org-mode has lots of nice features for tracking deadlines, time spent on tasks etc.

Exporting to PDF

This is really easy once you have everything set up.

Suppose I want to export this very simple file:

This is done with the command org-export-as-pdf, and here is the resulting PDF.

Next steps

I’m not sure, what do you think? Any suggestions for improvements on these workflows would be greatly appreciated. Just drop a comment.

Follow

Get every new post delivered to your Inbox.