All posts filed under “computing

Small teams and interruptions

It’s hard for non-programmers to understand just how bad interruptions are when it comes to being a productive coder. While most jobs suffer from the same problems of “getting back into the flow” after being interrupted, programming is especially difficult as normally programmers are trying to hold a number of structures in their head at any one time so as to solve whatever problem it is that they are working on.

In most small companies, the development team is might only consist of three or four people and in such a small team with a large backlog to deliver, it’s not normally the teams size that is the main factor in being able to deliver large amounts of work, but all the small interruptions that happen during daily business. Asking a developer that is sitting close by about when a feature will be ready or whether something can be fixed/changed is all too tempting and easy to do. Why IM or email when you can just shout across the room. It only takes a few 10-20 second interruptions to change a productive three to fours hours into just maybe one or two.

Once a company grows these sorts of problems can be smoothed out by having someone act as a barrier to the developers, shielding them from minor questions/requests and letting them continue with their work until free to discuss them. Small companies don’t have the luxury of assigning someone that role so need to find other means to minimising that contact. It’s important that someone sets some ground rules. It could be as simple as there is a set period of time every day that programmers should not be disturbed or communication should be limited to IM and email if possible. Just removing the constant stream of “Is X ready yet?”, “Did you get a chance to look at Y?” or “Would it be possible to do Z?” would mean a huge productivity boost for your programmers and overall deliverables for your company.

Rspec + Devise user and current_user different

If you follow the Devise Wiki on setting up Rspec and Devise you may end up wanting to set an expecatation on the currently signed in user.

Don’t fall into the trap of setting it on the original user model as your specs will still fail:

user.should_receive(:blah).once # Won't work

Rather, you should set it on the controller’s current_user:

subject.current_user.should_receive(:blah).once # Will work!

OSX Copy/Paste in tmux

One of the big things that took me a while to get right in tmux was copy/pasting. The gripes of trying to get it to work were enough to nearly make me forget using it all together.

Here’s what you need to know.

Install reattach-to-user-namespace

brew install reattach-to-user-namespace

and then in your .tmux.conf

set-option -g default-command "reattach-to-user-namespace -l zsh"

Assign a binding to copy the current buffer

In your .tmux.conf set a binding to copy the buffer

bind-key C-c run-shell "tmux save-buffer - | reattach-to-user-namespace pbcopy"

Now it actually took me ages to work out how to use this properly. Once you have created the buffer, either through selecting it with the mouse or by using PREFIX – [ and SPACE/ENTER, press PREFIX – C-c and it will be copied to your system clipboard.

Use the option key

If you hold down the option key while in the terminal, you can create a selection just as if you’re weren’t in tmux.

Switching to tmux

Not being one to jump on bandwagons, I just had to try tmux after hearing so many people talk about it. tmux is a terminal multiplexer allowing you to run a number of terminals within a single screen as well as allowing you to detach and reattach to the same session as you please.

So what? I can just run multiple tabs and get the same effect!

Yes and no. I had been running multiple tabs, with vim in one window, a console session in another and tailing output in another, but the real revelation with tmux came when I tried out the tmuxinator gem. tmuxinator allows you to easily manage tmux sessions. With a simple yaml file you can create and start a tmux session with your editor, console and logging all setup, laid out and ready to go. This is incredibly useful with you work across multiple projects as quite frequently I would find myself in tab hell when having to switch from one project to another. Once you get past having more than four or five tabs open it become increasingly difficult to know which is which. tmux sessions mean I can keep everything related to a single “context” within one terminal session.

Getting up and running wasn’t 100% smooth sailing. Brian P. Hogan’s tmux: Productive Mouse-Free Development was invaluable. Even with less than a full days use, I’m pretty comfortable and have gotten over the initial slowdown that comes with switching to a new tool.

The only thing I miss is that I can no-longer use CMD-S for saving like in MacVim, but to be honest that’s a bad habit I need to break, as well as colour schemes aren’t quite as pretty in command line Vim compared to MacVim.

A few gotchas I encountered:

  • When using Vim and the Command-T plugin, up/down arrows wont work for selecting a file to open, you will have to use CTRL-J/K to move up and down and CTRL-C to close the pane.
  • When adding reattach-to-user-namespace to enable copy/paste to your tmux.conf, you must kill your tmux session for the change to take place, it’s not enough to just quit and restart tmux.
  • If you’re using rvm, opening a new pane/window into a directory with an .rvmrc wont properly load in the selected ruby. If you’re on bash then adding “cmd .” to your .bashrc should work (I haven’t tried it), but for me I had to add “source .rvmrc” to my .zshrc for it load in properly.

A day with Ubuntu Oneiric Ocelot (11.10)

I just started a short term contract doing some RoR and was given a PC to work with. While developing on RoR on Windows is possible, it’s not what I’m used to or best at. As there were no Macs I could use, I thought I would give Linux a go. Seeing as I use Vim as my editor of choice, switching over should have been relatively painless.

I’ll just get to the point, that for many years now I’ve always said that I don’t think Linux as a desktop OS really cuts it compared to Windows or OSX, and having used it for a day and a half I still think that’s true. Off the bat the install seemed plagued with things I just wouldn’t expect from a “modern” OS.

The first major blunder came during the installation process. I booted off the CD and was told that a hard drive with Windows had been detected and would I like to install Ubuntu along side it. I chose yes and was shown a screen with a dropdown with HDs and a slider to allow you to resize the partition of the drive. I split it in half and set it going. Then only when half way through did I actually look at what drive had been selected by default, it had chosen an external drive as the one to get to work on. I totally accept that I should have checked it first, but I don’t understand why I was asked if I wanted to install it beside Windows for it to then choose a drive that Windows wasn’t even on as the one to set as the selected on.

The pain didn’t end there. Once finally up and running, my dual monitor setup was being mirrored which was easily remedied in the display settings control panel, but then it was apparent hardware acceleration wasn’t working. You couldn’t move windows without them struggling to keep up with the pointer. Trying to enable the proprietary ATI drivers didn’t work. Do I chose the normal or the post-release drivers offered? The normal drivers installed, but the displays would only mirror each other and the post-release ones wouldn’t even install. So I took a chance with some commands I found on a wiki which involved stripping away all the default ATI stuff and compiling my own drivers from scratch, which eventually got it running with hardware acceleration and with both screens working independently. I had no idea what the collection of commands I had run did to the system, which left me with the un-nerving feeling that the system was sort of hanging together by a thread. I was too scared to restart incase it came back with no display at all.

A few people advised me to ditch the Unity manager in favour of Gnome Shell, but that just made life even worse. I couldn’t even move windows without them crawling across the screen. It just felt like a total disaster and I had absolutely no faith in the install at all.

I remember in 1998 hearing about Linux Mandrake and traveling all the way to some dodgy warehouse in North London to buy a copy. My experience back then was actually a good one. Everything worked as it should of and using it day to day was fine. I don’t remember having any display or driver problems. It was only gaming that made me return to Windows back then. What has actually been achieved in 14 years? Some transparent UI elements? To me Linux still seems plagued by constant lack of driver support. Perhaps someone can explain even why just browsing the net on Linux looks bad? Why are no good fonts distributed? If you know exactly what you’re doing then you can make do. Plenty get by, perhaps I just don’t have the patience for it.

I just want something that works, and after some begging I convinced the place I’m at to let me use a Mac. Setting up took a fraction of the time, admittedly I’m used to it so it’ll be quicker to get up and running, but I didn’t have to worry about any drivers, display issues or whether or not my machine would survive a reboot.

Accessing values in your plist file from your iPhone/iPad app

Recently I’ve been coding some iPhone and iPad apps with multiple targets, all sharing the same codebase. Previously I had been using Preprocessor Macros to get the job done, but that soon turns messy and hard to maintain. I’ve since moved to just storing target specific values in each apps related plist file. Retrieving a value is as simple as:

nginx SSL PEM_read_bio:bad end line

Installing the intermediate certificates on our server gave me the following error while trying to start up nginx again:

The end of the file looked fine, but the problem was half way through it. Somehow the concatenation had joined two lines together:

This just needed a line break to fix:

Ubuntu: Curl development headers with SSL support

Just been trying to install Passenger on a new Ubuntu EC2 instance and passenger is giving me the error:

Took some digging around but turns out I was just missing the libcurl4-openssl-dev package:

SSH Tunnels with Postgres & pgAdmin

One of my previous posts showed how to use an SSH Tunnel to connect to a remote MySQL server. Since moving to Postgres I’ve been wanting to do the same thing with pgAdmin, which sadly isn’t as simple. There’s no way of creating the tunnel automatically in the app so we need to resort to the terminal.

The first step is as before, we create the SSH tunnel to our server:

Here I’m mapping the remote Postgres post 5432 to the local post 5555. Now this is where things start to differ. I had been trying to connect as the local ‘postgres’ user but continually received authentication errors. You need to create a user on the server that relates to your machine’s local user. So if your local username is “foo” you need to create a user in Postgres with the same name. First log into the psql console:

Then issue the commands:

Then in pgAdmin, simply connect with user foo and you’re good to go.

UPDATE: I’ve since discovered this is related to IDENT authentication. Switching to PASSWORD authentication allows you to use any username/password combination.

Tagging in Notational Velocity

Recently I switched from Evernote to Notational Velocity. I was so sick of the Evernote iPhone app and saw that Notational Velocity synced with Simplenote. Since trying them both out I haven’t looked back. Now, Notational Velocity supports tagging but Simplenote doesn’t, and as I like to search by tag, this was a bit of a problem. So taking the Twitter approach, I simply hashtag my notes, which makes them incredibly easy to find in both Notational Velocity and Simplenote. I don’t put the hashtag in the name of the note but just as the first line. I found that putting the tag in the name looked a bit untidy in SimpleNote. A nice side effect is that in Simplenote, the tags appear as the preview line. Problem solved. #notationalvelocity #simplenote

Missing menubar icons in OSX 10.6.2

A whole load of menubar icons disappeared after installing 10.6.2. Seems it’s a problem related to me doing a small hack in the past to disable Spotlight. Steven Seeger’s fix restored the menubar to it’s full glory.

Essential reading for developers

I’ve been meaning to write up a list of what books I think every developer, aspiring or seasoned should read. So let’s cut to the chase, and in no particular order:

Code Complete
If there was ever a bible for coding, this is it. It’s even Bible sized. A nice size to chuck at those annoying developers who just have no clue.

Clean Code
I would consider this book the “Ten Commandments” of coding and compliments Code Complete very very very well. If Code Complete teaches you how to be a Christian, then Clean Code teaches you how to be Jesus.

Refactoring to Patterns
What I love about this book is that it you learn the fundamentals of refactoring at the same time as design patterns. The GoF Design Patterns book is quite heavy going. The examples aren’t well laid out and can be confusing especially if you’re not familiar with SmallTalk The examples in refactoring to patterns all take pretty familiar real world bits of code and walk you through the process of refactoring them into sensible patterns.

Three books? Is that it? Yup. In my mind those are the only three books that are essential reading, no matter what form of development you do. If you even remotely care about coding, then go to Amazon now and buy these books. Read them and take a good long hard look at your own code. If on the other hand you feel “You can’t be bothered” to read, learn and improve, then why are you doing something you don’t love or care about? You’re in the wrong industry if you’re not prepared to take time, all the time, to learn new things. Once you’ve read those, then you’re ready to move onto more specialised books. Here are some of my other favourite development books from over the years:

The Productive Programmer
The Art of Agile Development
Practices of an Agile Developer
Joel on Software
Unix Power Tools
Programming Perl
Essential Java
Well Grounded Rubyist
Design Patterns in Ruby
CSS Mastery
Prioritizing Web Usability