Omphe.com

Sharing geekery just as fast as I learn it

OSX Gestures for Emacs Scrolling

I’m now working in a Ruby on Rails team, which means I’m collaborating with a lot of TextMate users on a daily basis. I’ve been an Emacs user for years, and have never really seen the benefit of TextMate.

I do occasionally envy the silky interactions of GUI editors, in all their pointy clicky glory. Despite loving the speed of navigating with keystrokes, there are times when zipping around the editor is easier done with a mouse, and I love using my Apple Magic Trackpad and Lion gestures for doing this.

Recently, I’ve been feeling the Ctrl-V / Meta-V keystrokes for paging up and down have been a bit clumsy and imprecise. What I’ve wanted is the lovely two-finger scroll that I’ve become accustomed to on all my other Lion apps. Well I’ve found a lovely .emacs customisation that provides two finger scrolling for console Emacs interaction.

To enable this, add the following to your ~/.emacs file:

OSX Emacs mouse scroll Stackoverflow source
1
2
3
4
5
6
7
8
9
10
11
12
13
;; Enable mouse support
(unless window-system
  (require 'mouse)
  (xterm-mouse-mode t)
  (global-set-key [mouse-4] '(lambda ()
                              (interactive)
                              (scroll-down 1)))
  (global-set-key [mouse-5] '(lambda ()
                              (interactive)
                              (scroll-up 1)))
  (defun track-mouse (e))
  (setq mouse-sel-mode t)
)

If your Emacs is ringing the terminal bell, or worse yet spraying Growl notifications, every time you scroll to the top or bottom of the buffer, you can disable this by adding the following to your ~/.emacs:

Stop that ringing Emacs bell Original source
1
2
;; disable bell function
(setq ring-bell-function 'ignore)

Help Me Upcycle My Old Technology

As an old and seasoned geek, I’ve accumulated my fair share of outdated technology over the years. You know the stuff: old laptops, giant mobile phones and thousands of ethernet cables and kettle plugs.

Given the fact that I’ve moved 25 times in 21 years, you’d think that I’d have jettisoned more of this stuff along the way. But in my last few moves, I was so sick of sorting and packing, that it all ended up coming with me.

Two years ago I moved into my countryside home, the cruft found a cupboard, and has been there since. New Years 2012 is only 24 hours away and I’m determined to be shut of this clutter by then.

Help me to free my life of this stuff, while providing yourself with opportunities to upcycle some of this stuff into cool hack projects. Let’s keep as much of this copper out of the landfill as possible.

Please help me to find homes for the following:

  • Black Epson Stylus C42UX/C42+/C44UX print cartridge
  • Color Epson Stylus C42UX/C42+/C44UX print cartridge
  • 512 MB PC133 Laptop RAM
  • 128 MB PC133 Laptop RAM
  • Morphy Richards White “Digital Messenger” answerphone
  • Belkin N1 USB Wireless Adaptor
  • Dell Inspiron 1150 Laptop: No HDD, Screen in good order, MOBO overheats
  • Aiwa MniDisc Recorder: AM-F80 includes battery pack
  • 2 x Parallel cable
  • USB power source from wall adapter to two USB sockets
  • 6 pin to keyboard and mouse splitter cable
  • 4 x RCA cable
  • 1 metre 6 pin extension cable for mice/keyboards/etc
  • Bag of assorted server rack nuts
  • Parallel cable male-to-male adapter
  • 2 x UK telephone to modem RJ45 cable
  • Microsoft PS/2 mouse
  • Digital camera adapter for Sony Ericsson mobile (Communicam MCA-25)
  • Modem to Modem (US style RJ45 cable)
  • 3 x 2 metre parallel printer cable
  • PS/2 to Serial Mouse adapter
  • Uniross X-Press 1000 battery charger
  • Linksys Bluetooth USB dongle w/ integrated antenna
  • 4 x Walkman
  • PS/2 to USB mouse adapter
  • Garmin Etrex GPS handheld: Sadly cracked/leaky LCD, but unit in perfect working order
  • ATI AGP Graphics card
  • BT R70 Answerphone
  • Blackberry mini-USB wall charger
  • QuickCD PCMCIA External CD drive
  • 2 x iomega ZIP Drives
  • Netgear MA401 802.11b PCMCIA wireless card
  • 4 x 2 pin plugs
  • AT to PS/2 keyboard adapter
  • 2 x Parallel to 9 pin serial adapter
  • US to Australian Phone adapter
  • Thinkpad 365X Laptop: No HDD, screen in working order
  • LinkSys WPC11 PCMCIA 802.11b wireless adapter
  • Altec Lansing PC speaker set with Subwoofer and 2 desktop speakers. Beige and ugly but lend tunes to a busy workshop
  • 6 x Kettle plugs
  • Solwise SAR110 ADSL router

NB - Anything that can’t be upcycled by a hackspace, will be offered on Freecycle. As a last resort I’ll take it all to a decent recycling centre in my bicycle trailer. At least the last mile of this junk’s life will be low-carbon.

An Emacs Helper Function for Theming Drupal Views

Theming Drupal Views can be a long and tedious process. Every friendly configuration click that the CMS user is given, comes at the cost of grey hairs and expletives for the hapless Drupal themer or developer.

Getting the themes to behave as your designers intend them, requires searching through the views interface, creating the appropriate theme files, flushing the cache and then coercing the markup so that it (just about) matches the designs. To be on the safe side, it might help to cast a virgin into a volcano or sacrifice small barnyard animals if you want quick results.

But Drupal’s gods favour the tenacious and persistent, so these skills will become second nature to any experienced and determined themer. Regardless of the journey you took to get to your desired theme file, you’re bound to do a lot of typing once you’ve arrived, as the Views fields are buried in a Russian doll of objects, arrays, hashes, lists and more.

To ease the RSI for any of you emacs users out there, I’ve pulled together a quick helper function for Emacs that will output your field. Here’s the code:

Drupal Views Field helper
1
2
3
4
5
6
7
8
9
10
11
(defun drupal-view-field (field_name conditional)
  "Build the markup for outputting a Drupal views field"
  (interactive
   (list (read-string "Field Name: ")
   (y-or-n-p "Wrap in a conditional?")))
  (if conditional
      (progn (insert "<?php if($fields['" field_name "']->content): ?>\n")
       (insert-tab)))
  (insert "<?php print $fields['" field_name "']->content; ?>")
  (if conditional
      (insert "\n<?php endif; ?>\n")))

The function will prompt you for the field name you want to insert and ask you whether you want it wrapped in a conditional.

To use this helper add it to your .emacs file and call it from within a buffer by entering M-x drupal-view-field

Outlook Web Access InboxZero Smackdown

Playing nice with email

Anyone who works with clients or full-time employers, will sooner or later, find themselves faced with the supposed convenience of using web-based Exchange email. Almost without exception, you will be provided with a login to an Outlook WebAccess account where you can, allegedly, get the full functionality of the desktop version. Outlook Web Access

Quite enough vitriol and bile can be found online, concerning the value and quality of Microsoft tools. Microsoft try to do quite a lot, and some of it they do very well (Excel) and quite naturally there are places where they fail. But, in the case of Outlook WebAccess, the product is truly painful to use.

GTD

Anyone following the GTD method (David Allen’s Getting Things Done), will be a big fan of the Inbox Zero approach, where you keep your email inbox clear by processing, filing or deleting incoming messages with relentless kung-fu precision. GTD intends for us to “Do, Delegate, or Defer” everything using the appropriate system. Whether a GTD fanatic or not, any knowledge worker will tell you that a full email inbox is only appropriate for generating stress.

Frustration runs highest in people who like, and have become used to, Gmail. It basically comes down to the ability to search, quickly and effectively. Outlook WebAccess, despite its calendaring and groupware integration, has dreadful search capabilities. Since we all receive such high volumes of email and constantly need to recall information, search is no longer a nice to have.

Outlook and GTD in harmony

An enlightened colleague (@LordCope) recently shared with me, his three step plan to email nirvana. Like me, he hates email and feels an Inbox Zero, is the only liberation. Here’s how his Outlook WebAccess workflow runs:

  1. Starting from the top, open your first message.
  2. If the message needs a reply, do so immediately and then delete the message.
  3. If the message needs action from you, record this in another system like Things, Tracks, or a HipsterPDA
  4. If the message is a reference document you might need later, forward it to your search enabled webmail account of choice, and immediately delete the email.

With this method you get all the information pack-rattery that you could want, while maintaining the inner-calm and serenity of an empty inbox. Get forwarding!!!

Fabric First Steps - Directory Creation

Fabric is a tidy tool for deployment that neatly wraps up fussy, manual tasks into a tidy Python syntax. The simple API wraps up most of your common deployment tasks into contexts which allow you to perform tasks either locally or sequentially on remote servers, using a transparent SSH mechanism.  Magic.

Because its all Python syntax, my temptation was to perform local tasks like directory creation using native Python. To initiate a local ‘build’ directory, I tried:

1
2
3
4
5
6
7
8
9
from fabric.api import *
import os

def init():
    build_directory = "./build"
    dir = os.path.dirname(build_directory)

    if not os.path.exists(dir):
        output = os.mkdir(dir)

For reasons that are not immediately apparent to me, this process fails rather silently. But reading the Fabric manual, it does specify that Fabric is:

  • A tool that lets you execute arbitrary Python functions via the command line
  • A library of subroutines (built on top of a lower-level library) to make executing shell commands over SSH easy and Pythonic.

As it turns out, the preferred way of doing this, is to use a local() task to drive the command line tools more directly. So instead, our fabfile looks like:

1
2
3
4
from fabric.api import *

def init():
    local('mkdir ./build')

Simple, straightforward and pretty intuitive.

Fabric - Installation

In this article from our Fabric series, I’m going to show you how to get set up with Fabric on your development environment. We’ll get down to installing the fab commands and preparing you for writing your first fabfile. But, as ever, there are Yaks to shave.

Installing the installers

Before we can get down to actually installing Fabric, we need to install some Python libraries that will help us get everything that we need. For this article, I’ll be installing on OSX 10.5 Leopard, but the steps should be roughly similar for any *nix like operating system. Best of all, we’ll stay well clear of my arch enemy, the infuriating macports.

First, let’s install pip, a clever packaging tool replacement for easy_install. I’m not overly familiar with easy_install, but James Bennett’s article Why I like pip, has me convinced its the way to go.

To get pip, we’ll use easy_install. Open your terminal of choice and type:

1
# sudo easy_install pip

Once pip has installed, let’s use it to install Fabric:

1
# sudo pip install fabric

On my machine this grabbed a dependency, pycrypto, and set about downloading and compiling all the needed libraries.

Wrapup

Like most Python endeavours, it almost feels too easy to get the tools set up and ready to go. In the next article, we’ll set up our first fabfile and shift some code to our target server.

ANT vs Fabric - Evolving Tools for Website Deployment

In my development work for Clockwork Robot, I have always used the ANT build tool for packaging and deploying client sites. I chose ANT for its platform independence and its XML syntax, which cleanly decoupled build and deployment from the language that the websites were built in, usually PHP.

While ANT was developed for Java development, it works equally well for the deployment of applications written in any language. I reasoned that the limitations of ANT scripts would provide useful constraints for any developer/release manager trying to bend the build and deployment process to do inappropriate things.

Furthermore, at the time that I adopted ANT, it was far superior to the current alternatives, which were usually cryptic and brittle GNU Make files or, worse yet, Perl scripts that guaranteed employment for an incorrigible and obstreperous sysadmin. Plus, XML promised to be a lingua franca, a sort of utopian language that would solve all our problems and serve umbrella cocktails poolside.

New Tools

Well, Esperanto was supposed to be a problem solving universal language, but it is only dear to tenacious eccentrics who find its constraints useful, and harbour delusions of semantic elegance. Which, as it has recently and painfully been pointed out to me, is how I have been behaving about ANT.

The problem is that while ANT is independent of the language du jour of your current web app, that usually means that the skillset to develop and maintain the build and deployment scripts, is also independent of the experience or ambition of your developers.

Increasingly, Clockwork Robot clients are using PHP applications written in popular frameworks like Symfony, or CMS like Drupal or Joomla. These frameworks may provide their own deployment tools, otherwise PHP projects like Phing provide ANT-like alternatives.

Meanwhile, for server administration and heavy lifting on the command line, Python has become the language of choice. Since it reads like executable pseudo-code, PHP developers are generally comfortable with picking up Python skills, and since Google and NASA use Python, it must be cool.

Move over ANT

Enter Fabric, a build and deployment tool written in Python. While the syntax is just bog-standard Python, it carries a lightweight API that gives just enough useful functionality without getting in the way. The syntax is less verbose than ANT, given there’s no need to open and close tags, and execution of the commands on the command line are just as easy in Fabric.

Since Python has become a commodity skill for developers and sysadmins alike, I’m now considering a move from ANT to Fabric. It makes more sense for project resourcing, that the scripts can be built and maintained by whomever is closest to the deployment coalface at the time; developers or sysadmins.

In upcoming posts, I’ll be demonstrating the installation and use of Fabric, and running a closer comparison of the two tools.

ANT Fabric
Advantages
  • Excellent documentation
  • Wide availability of extension tasks and libraries
  • Widespread integration with popular continuous integration and deployment tools such as Hudson
  • Simple Python syntax
  • Superior SSH integration built in
Disadvantages
  • Complicated or custom tasks require Java coding
  • Verbose syntax
  • Java implementation makes it inaccessible and unwieldy for systems administrators
  • Relatively new project
  • Scant documentation

Highs and Lows - DrupalCon Paris 2009

Festival Atmosphere

The presentations and coding sessions have been going strong for four days now, and the atmosphere was buoyant as the crowd gathered for the big group photo.

Drupal crash

But no party is without its casualties and some of the Drupalnauts were showing signs of wear this morning.

Drupal Crowd

Whether its stickers, MacBooks full of code or DrupalCon tshirts, no one needs a reminder that Drupal is at the centre of it all.

Drupal an Enterprise Ready Solution

Amid all the hype and momentum that is building around adoption of Drupal for sites of all sizes, there remains a bitter skepticism that Drupal is, or ever will be appropriate for large deployments in Enterprise environments. This year’s attendance and presentations at DrupalCon Paris 2009 should put many of those doubts to rest, as flagship publishers like Economist.com and consultancies with Enterprise clients, open up about what they’ve achieved with Drupal.

The presentation schedule has interleaved content for newcomers to Drupal as well as seasoned coders, with business focussed discussions on introducing and managing Drupal within the productive flow of large organisations. There has been a significant emphasis on the use of Agile techniques, specifically with Scrum.

Within Drupal 7 there are a number of new features and tools that are aimed specifically for larger sites with performance challenges. New deployment APIs, extended debugging and unit testing tools and exciting changes to caching and database replication tools are all part of the new bag of tricks for Enterprise developers.

In talking to some of the teams from larger sites, a common toolkit is emerging for supporting rigorous development processes. Most of these tools focus on an Agile approach to development, emphasizing constant quality review and a frequent need to integrate and deploy. Recipes for success include:

  1. Hudson for Continuous Integration
  2. ANT for deployment scripting
  3. JMeter for performance testing
  4. Selenium and Selenium Grid for functional testing