Non-intuitive UIs

May 30, 2011

Have a look at this page:

http://www.thefreedictionary.com/brought

OMG, it includes the word “participle”, WHAT DOES IT MEAN?!?

Well, what you have no way of knowing is that you can double-click this or any other word and go to the entry for that word. Not a bad feature at all, but not very obvious either ūüôā

On a project, I have a “Revision” resource and URL’s like

http://foobar.dev/revisions/1

Now suddenly the client wants to rename “revision” to “edition”, so all URLs should be changed to the format

http://foobar.dev/editions/1

Unless I’m missing something in the Rails docs, there is no option to change the base part of the path without renaming the resource itself. Actions can be renamed, eg. “nuevo” instead of “new”, but I don’t think the path segment for the resource name can be changed (please correct me if I’m wrong).

I guess the proper way to go would be to rename everything: The AR model, all helper calls, controllers, tests etc. Even with lots of automation, this would be a really annoying task and I’m not inclined to spend time on this right now. Who knows if the client will change his mind again?

So instead, I ended up changes the resource from

  resources :revisions

to

  resources :editions, :controller => "revisions", :as => "revisions"

I’m changing the name of the resource, but the :controller option makes sure the right controller is still called, and the :as option controls the generation of path helpers (so I can keep using eg. edit_revision_path).

Remember to make the same change for nested resources.

EDIT: As Rasmus and Jakob point out, the :path option sets the actual path, not a prefix. I have made some minor updates to the Rails docs to correct this (most instances were already fixed).

It turns out that lots of MBP models have a well-known issue with the headphone port, and this can cause the internal speakers to become disabled. Actually, they’re disabled as a side-effect of digital output being enabled. The headphone port is used for both electrical and optical connections, and the internal switch managing this can sometimes enter the “optical connector present” state for no apparent reason.

Here’s one thread describing this issue, and Google turns out many more.

However, the reason that I’m writing this is that my machine (2010 17″ MBP) seems to suffer from a variation of this problem. All descriptions of the issue I found were rather old, and in all cases it was reported that the red light (ie. the optical signal stream) was turned on when the internal speakers were disabled.¬†On my machine, the red light was visible only some of the time.

Doing a software update, a reboot and even an SMC reset did not help.¬†I eventually fixed the issue by moving the headphone jack slowly in and out of the port while wiggling it a little bit. It took maybe 15 tries before it worked…

To monitor your (lack of) progress, open the System Preferences, go to the Sound pane and select the Output tab.

  • In the broken state, the topmost item will read “Digital Output” and a red light may or may not be visible from the headphone socket
  • When the headphone jack is inserted, this should change to “Headphones”
  • The non-broken state is “Internal Speakers”. This is when you have managed to clear the switch (HW or SW, I don’t know) that is stuck in the “optical connector present” state.

My oldish Acer Aspire One has been running Ubuntu Netbook Remix for a year or so, and I have become increasingly annoyed with how slow it is. I remember it as being much faster when I installed it, so either a) I have become faster, b) The performance of the installation has degraded, or c) My memory is incorrect yet again.

I’m actually inclined to go with b). The problem with the Aspire One (some models) is its extremely slow 8GB SSD. I know, those things are supposed to be fast, and they have done wonders for my last two laptops. But on the AA1, especially the write speed really is terrible.¬†So I’m suspecting that something has caused the Ubuntu installation to do more writes over time…whether this is disk fragmentation, the browser cache or whatever, I don’t know.

For the reinstall, I decided to try out Joli OS and so far it looks like this was a good choice! What I basically need is for this machine to be 100% quiet, reasonably responsive and able to render web pages and PDF files. That’s all, because I use it almost exclusively for reading in bed.

The entire OS is built very much like I would expect Chrome OS (which I haven’t tried) to be built. Everything revolves around the web, and it seems that most of the OS is written in HTML5. Joli OS is in fact based on Ubuntu Netbook Remix, but simplified (even further) and integrating Jolicloud, which is pretty cool. In fact Jolicloud is at the core of the user experience where it replaces the launcher found in UNR.

The idea with Jolicloud is to have a web-based, portable desktop containing all the webapps that you use all the time. Facebook, Twitter, Gmail, Flickr, YouTube, just to name a few of the ones that are added by default.

I’m not sure exactly what Joli OS adds to this (because the OS is all I’ve tried), but a feature I found especially nice is the ability to link my device with Dropbox and Google Docs. I use Dropbox for storing a lot of PDF documents that I want to have available anywhere I go. But I also use it for lots of other purposes, and actually I think this is one of the reasons my UNR installation finally gave up – because I was naive enough to have Dropbox installed and syncing everything.

With Joli, I can browse my Dropbox and open individual documents. Browsing is of course slightly slower than on my physical disk, but I tend to keep these documents open for weeks, so this is not an issue. And of course I could just download any files I want to access offline.

So far, I have done very little customization of the OS. The AA1 has a very noisy fan, but fixing this problem with the acerhdf module is a  simple matter of editing a few files. I also want Caps Lock to be an additional Ctrl, and I want both Danish and US keyboard layouts installed. Both wishes were granted after a few minutes of poking around in the settings (these are just the Gnome settings, of course).

I’m really surprised to discover that I seem to fit exactly into the target group for an OS like this. I have installed Emacs (mostly to edit org files), but apart from that, it looks like I’ll be fine with the built-in selection of programs. Which is just Chromium and the Gnome stuff.

Finally, it looks like there’s a whole social networking thing built into Joli which I haven’t explored at all yet. But I have already earned the badge “Recycler” just by installing Joli and recycling a computer that was destined to be replaced by a tablet before long ūüôā

Today, I found a bug in Rails.

On a project, I need to mail PDF files to users, and I would like to use PDFKit for that. The contents of the PDF are generated by rendering a view, but¬†I don’t really want PDFKit to hit the server to get the content. Both because this breaks down in unit tests where the server may not be running, but also because there’s just no reason to go through the entire stack.

So I decided to generate the HTML with render_to_string, then convert it to PDF with PDFkit, and finally mail it to the user.

However, it turned out that this doesn’t work. Here is a minimal example:

class NoteMailer < ActionMailer::Base
  default :from => "from@example.com"

  def foo
    @notes = []
    render_to_string(:template => "notes/index.html.erb")
    # self.instance_variable_set(:@lookup_context, nil) # <-- Workaround
    mail(:to => "example@example.com")  
  end
end

It turns out that the call to render_to_string initializes the @lookup_context of the controller (== mailer in this case). The lookup context is the object that is responsible for locating templates to render, so it contains (among other things) a list of template extensions to look for.

The call to mail() renders the actual mail, but the mailer now reuses the lookup context that was created by render_to_string. This prevents it from finding the mail template, which is (in this example) named “foo.text.erb”, because the lookup context doesn’t recognize the “.text.erb” extension.

A workaround is to manually clear the lookup context on the mailer after the call to render_to_string, but obviously this is a really bad solution.

Here is a very simple tip that has been really useful to me over the last few months.

The way I work in Emacs is by opening lots and lots of files and then quickly selecting the buffer I want with ido-mode.

However, this breaks down if I have more than one project loaded in my Emacs session. For example, when working on Rails projects, I want to be able to find the routes.rb file with just a few keystrokes. To avoid restarting Emacs whenever I switch project, I need multiple instances running simultaneously, which is not “supported” in OSX (or rather, it’s just not the OSX way).

To workaround this, I use a really simple hack: Copying Emacs

So to create Emacs2 and Emacs3 in addition to just Emacs, do

cp -r /Applications/Emacs.app /Applications/Emacs2.app
cp -r /Applications/Emacs.app /Applications/Emacs3.app

That’s it! Now you can fire up three Emacs instances at the same time. Next step will be to replace the icons of the clones to make it easier to spot them when switching applications.

[EDIT]

As discussed in the comments below, I can just start new instances with “open -n -a Emacs.app”. Thanks¬†tali713 for bringing this to my attention!


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.

If you’re OK with dark text on a light background, you can stop reading now.

Personally, I have always preferred a dark background when coding, so obviously my Emacs theme is a dark one. And switching back and forth between Emacs and Terminal.app is much easier on the eyes if the background in Terminal is dark too.

Unfortunately, the Terminal theme I like best (“Pro”) doesn’t agree with ANSI colors. Especially the color blue becomes hard to read:

Many people resolve to using iTerm instead, but I’m not really a fan of it. The shortcuts for switching between tabs are on the arrow keys, much slower than the Terminal shortcuts. And maybe I’m missing something, but I never managed to reconfigure those shortcuts. To be honest, I think the iTerm configuration UI is a bit of a disaster.

So, I discovered by accident that I can actually tweak the background color in Terminal to make the blue color readable.

ÔĽŅ

This is the color picker for the background color. The vertical slider will adjust the brightness of the background, right? Well, it turns out that the brightness of the colored text is also adjusted, but in intervals. The blue color becomes brighter to begin with, then falls back to the original color at about 10% on the slider. The same happens for the other colors, but at different points on the slider. For example the red color switches at about 20% and the magenta a bit after that.

 

 

 

 

 

 

What works best for me is setting the slider at about 9%, just before the blue color falls back.

It may be hard to see from the pictures above, but this makes a huge difference, at least on my monitor. Reading the colored text is no longer a strain on the eye.

Although I basically agree with the Pragmatic Programmers’ old advice about learning a new programming language each year, the time has come for me to slow down.

I have been programming for many years and I know a lot of different languages. Many of them are boring and similar (eg. Java, C#, C++), some are not boring but similar (Ruby, Python) and some are completely different (Clojure, Common Lisp, JavaScript).

I’m well aware that I could learn a lot by studying Haskell or diving deeper into Javascript, but I’m going to take this year off.

Why? Very simple. I still have so much to learn from Clojure. I could write at length about the virtues of functional programming or about how Clojure takes advantage of the JVM. I could go on and on about the REPL, Java libraries, infinite lazy sequences (list of all primes, anyone?), the exceptionally smart community members and so on. But others have already done this much better than I could. For a great introduction to the language itself, go watch the intro videos by Clojure creator Rich Hickey. For all the surrounding stuff, there are lots of interesting blogs to read.

Likewise, although I have a lot of experience with both Ruby and Rails,¬†I’m not done learning here either. Especially, I need to tune my Emacs to achieve better code navigation and debugging support.

Two languages that I really like.¬†This year, I’m going to focus, not diversify.

Git autopush

January 10, 2011

Some of my Git repos are very, very simple. The commits are all on master, no branches in play at all. And the workflow is just as simple as back in the bad old Subversion days: Pull from the repo, commit some stuff, push it.

A good example is the repo I use to store my Project Euler solutions. It is only used by myself and I always want to push after committing.

So I set out to create (and complete within 10 minutes) my least ambitious project so far: A bash script to add “git push” as a post-commit hook in the current Git repo. You can find it on Github, but the business part of it is right here:

#!/bin/sh

HOOKS_FOLDER=.git/hooks
POST_COMMIT=$HOOKS_FOLDER/post-commit

if [ -d $HOOKS_FOLDER ]; then
    if [ -f $POST_COMMIT ]; then
        echo "Post commit hook already exits, please add 'git push' manually in .git/hooks/post-commit"
        exit -1
    fi
    echo "git push" > $POST_COMMIT
    chmod 755 $POST_COMMIT
    exit 0
else
    echo "This command must be run in the root of a Git repository."
    exit -1
fi

Suggestions welcome for improving the script. I think this is the first multiline Bash script I ever wrote, so I expect it to be flawed.

Ah yes, and before you comment:¬†I know that this is not the shiniest of Git workflows,¬†I know that branches are cheap etc. I love all the cool features of Git but sometimes I just don’t need them.

However I do not know if Git already has this functionality built in via some configuration option?