Working with lists of items in the Shell

Another useful idiom for command-line junkies to learn is

list-of-something | do-something-with-each-item

This can be expressed in a number of different ways. My go-to way is the following:

list-of-something | while read f;do do-something-with-each-item $f;done;

The real beauty is this can be built up incrementally, testing out the commands until one has got it right.

For example, to confirm the syntax of a the do-something-with-each-item, I prefix it with an echo to see what command is going to be run i.e.

list-of-something | while read f;do echo do-something-with-each-item $f;done;

If the list-of-something is very large or to confirm that I have the right subset of the list, I add some filters i.e.

list-of-something | grep something | head | while read f;do echo do-something-with-each-item $f;done;

The benefit of this incremental/iterative way of building up a command is that it is quick – up-arrow, edit the command and enter to try again.

The keystrokes to master and memorise are

while read f;do $f;done;

These are then embellished by adding a list-of-something | before the while, and an echo do-something-with-item before the $f.

Frequency counts in a Shell

For command-line junkies, a useful idiom to learn is

  list-of-something | sort | uniq -c | sort -nr

which will give a frequency count of list-of-something sorted in descending order.

e.g. to show the frequency count of the 4-starting-letters of words

  cat /usr/share/dict/words |\
     cut -c 1-4 |\
     sort | uniq -c | sort -nr |\
     head

which will show something like

  2043 over
  1334 unde
  1323 inte
  1078 anti
  1000 supe
   951 semi
   731 unco
   700 poly
   648 para
   618 peri

The classic story about this relates to Doug McIlroy and Donald Knuth More Shell, Less Egg

Vim – Capturing Output from Commands

One of the most useful things about Vim is its command-line mode. Using comamnd-line mode one can run external commands and capture the output and apply it to the buffer.

The external command is able to take text from the buffer, process it and replace the text.

Find checksum of lines of text

  :1,4 ! md5
  :% ! md5

Reformat JSON using jq

  :% ! jq .

One can also run an external command and have its output added to the current buffer.

Get list of files and insert into current buffer

  :. ! ls -latr

Capture output of a `curl` command and insert it into the current buffer

For example if one wants to insert the output from a curl command at the current line, one can do something like the following

  :. ! curl -s https://codeismandatory.com/about.html
  :. ! curl -s https://loripsum.net/api/1/plaintext

For more information, see the Vim help :he filter and :he :.

Back Again in 2019…

Time to get this show on the road again.

The to-write list is brimming with ideas. And I have a process that should work. But it is a matter of finding the time and commitment to put pen to paper and see what happens.

Reading the following two posts got me motivated again.

And of course then is Brian Harmer’s “Wysiwygpurple’s Blog” where he talks about putting your hands on the keyboard and doing something. If I could do the something similar with my photography, that would be unreal.

But let’s get technology on the way first…

Good Teaching

Over the years I have come to appreciate the difference a good teacher makes. A good teacher is someone whose teaching affects the way you think and one you remember for life.

Recently, I had to create a mashup of photos and video. Previously for this type of task I used iMovie 9.0.9 (or was it iMovie ’11). Anyway I fired up the latest version of iMovie and, ughh, the interface had changed once again and become super simple, hiding or removing some useful functionality. I was too hassled to try and ‘discover’ it.

So I went and bought big brother Final Cut Pro X. Mainly because I already had bought some books on special and had a premium subscription to lynda.com

So I did the right thing and started working through the Final Cut Pro X 10.2 Essential Training with Ashley Kennedy. And this is the course that has inspired me to write about “Good Teaching”.

The thing about teaching a complex course is

  • the teacher has to have a thorough understanding of the material so that they can provide context, then drill down into the detail and then jump back out to an overview to provide context.

  • the course has be presented in a structured manner so that we can see over the overview and get to the actual detail quickly.

Not only does this course cover the details of Final Cut Pro X, but the way that Ashley does it is amazing. She works on two different video presentations, Chocolat and Letterpress. The primary aim of the course is to teach you how to use Final Cut Pro X. However the way she works on these two videos not only shows you how to use Final Cut Pro X, but also gives some insights in how to produce a video.

From coming up with a storyline, organising supporting material and then assembling the pieces together to provide final impact.

To cap it off, the actual video of the course is also fantastically done. If you want to get going quickly, Chapter 2: FCP X QuickStart provides this quick overview showing how one can get a video produced.

As a keyboard junkie, another hightlight for me was the extensive emphasis on keyboard shortcuts. Whenever, an action was done, the keyboard shortcut was mentioned and a flyout would show what key was being used.

The course is well structured and the transcript is also provided in the web version.

Vim – Running Commands on Matching Lines

Over the years I have used many editors. There was VM/CMS Xedit, Burroughs CANDE, ISPF/PDF editor, the IBM E, E2, E3 series of editors which influenced SlickEdit somewhat. There was a brief foray into PC editors including MultiEdit and the Borland C IDE. On OS X, I have used TextMate, SlickEdit, Sublime and now Vim.

One of the most amazing features in Vim is its command-line mode and bears similarity to that found in ISPF/PDF Editor, Xedit, SlickEdit and E series of editors. Instead of manipulating the content directly, one can issue commands to do the dirty work.

In particular the global command is really useful.

For example. given the poem below, assume that one wants to apply a change on all lines containing the word ‘was’, say uppercase the entire line

   Mary had a little lamb,
   His fleece was white as snow,
   And everywhere that Mary went,
   The lamb was sure to go.

   He followed her to school one day,
   Which was against the rule,
   It made the children laugh and play
   To see a lamb at school.

One could enter the following

  :g/\<was\>/ norm 0gU$

and end up with the following.

   Mary had a little lamb,
   HIS FLEECE WAS WHITE AS SNOW,
   And everywhere that Mary went,
   THE LAMB WAS SURE TO GO.

   He followed her to school one day,
   WHICH WAS AGAINST THE RULE,
   It made the children laugh and play
   To see a lamb at school.

Basically this can be read as “For every line that contains the word was (g:/<was>/, execute a series of normal mode commans (norm) i.e. go to the beginning of the line (0) and then upper case to the end of the line (gU$)”.

Beyond Compare – It really Is…

Back in the day, I was a big fan of SlickEdit and have bemoaned the fact that it was not available on OS X.

One of its great features was the file and directory compare facility. Until last year or so, I thought it was the best.

Colleagues raved about this Windows app called Beyond Compare and how good it was. Windows only, so I didn’t pay much attention. Then there was a beta for OS X and I tried it out.

And boy does it rock.

  • Comparing directories or files, no problem at all.
  • Comparing log files and getting it to ignore differences such as log times.
  • Comparing zip, jar or war files to find differences without having to first unpack them.
  • Comparing tar files that have been gzipped and have different checksum due to gzip timestamp.

It has stopped my pining for SlickEdit.

The States of Git

One of the things I like about git, is the concept of working directory, index and repository. The index, or staging area, is really useful for gathering related changes before committing to the repostitory.

The GitGuys have a good description of the difference between these three.

Sometimes we will have changes in the working directory and/or the index. To compare differences between these different states:

Command Useful Alias Working
Directory
Index Repo (HEAD)
git diff gd
git diff –cached gdc
git diff HEAD gdh

If you want to diff a particular file, add -- filename to end of command e.g.

  git diff -- src/sql/update_20140125a.sql
  git diff --cached -- src/sql/update_20140125a.sql

To see contents of a file in a particular state

State Command
Working Directory cat filename
Index git show :filename
Repo (HEAD) git show HEAD:filename

And to get a good understanding of how git works, take a look at Git from the inside out

Why I like Groovy – Part 1

Over the years I have worked with many programming languages.

For me, it is important that the language be ‘simple’ enough for me to keep thinking about the problem that I am trying to solve.

Note that I did not say solution! If one has to think too much on the mechanics of trying to get the proposed solution to work, we often lose sight of identifying what the real problem is.

However, the language also has to be able to be handle the difficult tasks. To quote Larry Wall, Tom Christiansen and Randal L. Schwartz about Perl:

Perl is designed to make the easy jobs easy, without making the hard jobs impossible.

This is where Groovy is for me. It can be used to do one off scripts and basic data munging to coding in full stack frameworks such as Grails or to an Enterprise build automation system like Gradle.

When trying to solve a problem, I want to be thinking close to the problem domain.

For example, reading a file in groovy is as simple as the following:

  def fileText = new File('path_to_file').text

Variable fileText now has the content that I am interested in.

Another example if we want to find all the h4 headings on web page, one quick texty way could be to use

  new URL('http://www.radionz.co.nz/about').text.eachLine {
    if (it.contains('h4')) {
      println  it
    }
  }

The following provide useful information on learning about the Groovy Language:

I’m Back, I’m Back…

I am back, yes I am.

Not sure what prompted the restart for the fourth time. No I am not doing another university course. Maybe the ruptured achilles gave some pause tor thought.

Actually it was the What is Code article by Paul Ford that got me thinking.

Putting a site together takes a bit of understanding and effort. Because I have been working with technology for 30+ years, it is second nature. I understand what technology can and can’t do. So it is easy to quickly cut to the chase and help work out the problem we are trying to solve and what the requirements for the piece of work are.

But I sometimes forget that, when trying to discuss with people in the business.

Transluscent Menu Bar is Great - Yeah Right!

There has been a bit of a furore about the translucent menu bar.

The latest item is a flickr photo showing the ITunes menu-bar with a white spot in the second “o” of control. The comments make interesting reading – obviously a lot of “ornirary” folk are starting to use Mac OS X.

As shipped with Leopard the translucent menu-bar and the default desktop image don’t work well together. It is an unnecessary distraction when trying to work with itemss on the menu bar.

A simple bit of QA would have picked this up. One solution is to remove the distracting highlights from the ghastly default desktop image. Or even better remove, the default image altogether.

One school of thought says that by providing a translucent menu bar, punters can subtly change the way the menu-bar looks. This done by providing a customised desktop with the top 22 pixels tweaked to subtly change the effect of the menu-bar. All I say is “Yeah Right!”

Why bother providing such a convoluted work around to solve a perceived problem? And why force people to take an unecessary action to get a usable default desktop? Yes it is trivial to change desktop backgrounds. But just because we can change the desktop background, doesn’t mean that we should have to!

The workaround I chose, uses the ImageMagick mogrify command. Quite slick.

Leopard Firewall

I am not a security jock, but was concerned that after the initial install the firewall preference pane was configured to “Allow all incoming connections”. Since that Day 1 encounter with the firewall, I have been trying to get some more information on the changes.

The heise security blog, made interesting reading. Particularly the way he detailed some of his methods.

At securosis.com, the comment by Nick gives details about the application firewall (appfirewall) being used in Leopard.

John Sawyer at darkreading, blogged about the shortcomings. He mentions managing the firewall using ipfw and points to WaterRoof as a GUI frontend for ipfw.

There is a description of configuring ipfw at ibiblio. Reference is made there to an application called Flying Buttress – it was formerly callled BrickHouse but was renamed as that trademark was owned by someone else. Looks interesting, and I would probably use it if had been updated more recently.

What am I going to do?

  • Try and get ipfw configured, but using a shell script.
  • Only connect to the net from behind a separate router/firewall.

Welcome to Darwin!

Opening a new terminal window on Tiger displayed a message saying

Welcome to Darwin!

On Leopard this doesn’t happen. This is because the Message of the Day file is not automatically created under Leopard.

To have something displayed, simply put some text into /etc/motd. This will be displayed each time you start a terminal session.

Apache and PHP on Leopard

Out of the box, personal websites weren’t working. Mainly because Leopard ships with Apache2 compared to Tiger’s 1.3.

The following helped solve the problem for me.

  • Enable php5 by updating /etc/apache2/httpd.conf and uncomment the line
    LoadModule php5.module...
  • Turn on personal web sharing via System Preferences.
  • Users configuration is done in /etc/apache2/users. Ensure that you have a
    youruserid.conf
    file with appropriate directives. Mine contains
      <Directory "/Users/youruserid/Sites/">
          Options Indexes MultiViews
          AllowOverride All
          Order allow,deny
          Allow from all
      </Directory>
    
  • Logs are written to /var/log/apache2 rather than /var/log/httpd.

Leopard - First Impressions

Well first impressions. In a nutshell - unbelievably shite!

  • The default desktop has to go - far too distracting - too many bright white lights.
  • Then there is the transparency of the menu bar at the top of the screen. Blech.
  • When you alt-tab away from Safari, the chrome on Safari actually gets lighter. When you alt-tab back into it, it gets so dark that it is barely legible.
  • Stripes in Finder
  • No Java 6.
  • Firewall settings were rooted.
  • One good thing - when you use apple-shift-4 to indicate area of screen you want to copy, you get size indicators.

Maybe I have just been using Mac too long now and am getting set in my ways.

Anyway, it is too bleeding edge for me. I reverted back to Tiger from the full SuperDuper! clone I made just before I did the upgrade.

Wireless Apple Keyboard

Looks cute. But how will it function over the course of a day. Beautiful tactile feedback. However, it almost feels as if the board is a little small.

Great size though. Feels really portable. Responsive. Which is good. Keys don’t travel that far. Also good.

Form factor is different to normal keyboard. Similar to MacBook Pro keyboard. Except that a right ‘option/alt’ key is used instead of an ‘enter’ key.

It is fine, provided you use it all the time – Switching between a normal keyboard and this one is a tad difficult.

The Clipboard and the Command Line

Two of the most useful features on Mac OS X are the clipboard and the command line.

I am forever copying and pasting between applications using the clipboard. Select text in one application, press ⌘C, switch to the other application and then press ⌘V and the selected item appears in the application.

The beauty of the Unix command line is worthy of whole blog by itself. Utilities such as grep, find, sort, uniq, less, tail, head, cut are great.

Imagine being able to use these with the clipboard. You can! That is what the commands pbcopy and pbpaste do

Want to include disk space usage in an email? Open a terminal window and enter the df -H | pbcopy, switch to the email and press ⌘V to paste it in.

Want to take a list of names in an email and sort them? Select the lines, press ⌘C to copy to the clipboard, switch to the terminal window and enter pbpaste | sort | pbcopy. Then switch back to the email and pres ⌘V to paste in the sorted lines from the clipboard into the document.

Windows users need not fear. Install Cygwin and the putclip and getclip commands, part of utilities, and you can achieve the same effect.

First Week Gone

Well the first week has gone. One one hour lecture, two three hour labs and some extra curricular sweat to get things in hand.

One learning objective is to expose students to 3D space using a computer. Two teaching tools which we are using and which I find quite amazing are UnrealEd, the game editor for Unreal 2004 Tournament, and screencasting.

Much has been written about UnrealEd. Briefly, it lets you create a three dimensional space (i.e. rooms with objects in them) and then by clicking a button, you start the UT2004 game where you can explore and interact with this space you have just created.

Now how do 144 students learn to use this tool? Why they use the Video Training Modules (VTMs) from 3dbuzz.com. To quote directly from the site,

So, what are Video Training Modules? A VTM is a series of video training lessons that focus on specific topics. VTMs usually have 8 to 12 lessons and range anywhere from two to eight hours in total running time. They are not like your “standard” training videos; they are both entertaining and educational. Our VTMs offer some of the highest quality training available anywhere in the world, and most amazingly – they are FREE!

Basically the VTM or screencast of the UnrealEd that I have been using is a close up video of a computer screen showing the Unreal Editor being put through its paces with an ongoing, informative, commentry by a couple of dudes who really know their stuff. The following is a snapshot of the lessons for Module One for UnrealEd.

3dbuzz_uted_1.jpg

The beauty of the whole thing is that you can be running through the tutorial at the same time as working in UnrealEd. If you don’t understand a point in the commentary, simply rewind to play it again. Or you can pause the action, try it yourself, and then when you are ready, resume with the lecture. Bored with a particular topic? Fast forward over it.

One little gotcha with this approach? If you have thirty six students in a lab all trying to listen to their VTM’s at the same time, make sure that they all have headphones!!

A Student Again

Orientation. The last time I participated in a first year orientation was way back in 1977. This year, I am doing a couple of design papers at the design school at Victoria University. So I took a couple of hours today to attend orientation.

Some first impressions. Obviously everyone is young. As a work colleague said, it is possible that some of the students could be children of the students I taught back in 1982!! A sheet passed around requiring students to fill in their names and birth dates confirmed this. All were born around 1986 with one born in 1981.

Lots of computers, but all running Windows 2000. The Website seems to be serving ASP pages. No sign of any Apple computers. Maybe I am not looking hard enough <grin>

Back again…

It has been a while. Most blogs go though this hiatus, don’t they? But let’s get this pony back on track.

Since I last blogged, Visual SlickEdit for Mac OS X has been released. Being a long time user and fan of VSlick, I nearly wet my pants. At long last a real editor was being shipped for Mac OS X. No I don’t regard BBEdit, cute as it is, as a programmer’s editor.

Alas, my joy was short lived when the Out of the Box experience was anything but Apple like (or for that matter BBEdit like). The app was a frigging X Windows app and required X to be installed. Okay, installed X and then got VSlick up and running.

Next the key bindings out of the box were a bit of a pain. You know the usual fight between the ctrl and ⌘ keys. And the mnemonics.

slickedit-menu.jpg

They tease you by showing the underlined menu items, but there is no way to invoke the corresponding items. You have to go through and reassign the keys that are assigned to the menu items. Only then can you use the ⌘ key and the underlined letter.

The final pain in the ass is that although the VisualSlickEdit icon displays in the ⌘-tab task list, you can’t activate the application using it. Instead you have to pick the X application icon.

task list showing visualslickedit and X icons

Now realise, that even after all this hassle, I still find VSlick a pleasure to use. When it comes to loading and parsing a large XML file (tens of thousands of lines), this baby manages it with no sweat. The selective display still rocks. As does code completion and jump-to-definition.

Virtual Machines

One of my must have tools when developing software is VMWare. This great product lets you run a PC within another PC. It gives you an emulated PC on which you can do almost anything that you can do on a normal PC. You can boot it, install software on it, configure it to have network access, and when you have finished, you can shut it down.

However there are a few advantages that it has over a real PC. With a real PC, if you botch a software install, it is often a case of starting again by re-installing the operating system. However with a virtual PC, there are other options. When you shutdown a virtual PC, VMWare gives you the option of committing or discarding changes that have happened since you booted the virtual PC. So if you botched a software install and want to revert the system to the state that it was at before you started the install, just discard the changes.

Another advantage is that the virtual PC is persisted as a normal operating system file. This means that you can do normal file operations on it. Actions such as zipping it up, burning it to CD, moving it to a faster host machine or even sending it by email - only kidding - these persisted files can be hundreds of megabytes even when zipped.

Okay, so let me list the ways that I have used this animal over the last couple of years.

The first use was when we had to develop for and configure a Websphere Application Server to talk to an Apache Web Server. Because we needed separate servers to evaluate the configuration options and because there was a shortage of hardware, we used one PC running two instances of VMWare - one for the Apache Web Server and the other for the Websphere Application Server. With enough RAM, the performance was adequate.

The project also required us to support a variety of Browser and Operating system combinations. Rather than have a battery of PC's lined up taking up desk space, we opted to use VMWare. We configured a clean VM for each required operating system browser combination. When we needed to test a particular combination, all we had to do was boot a particular VM. Once testing was done, we could shutdown the VM, discarding any changes. We could always start with a known clean configuration.

More recently, I was investigating Active Directory. Rather than interfering with the existing site configuration or stuff around trying to set up a separate physical LAN and PCs, I used VMWare. By creating two VMWare instances, one with Windows 2003 Server, the other with Windows XP and setting them up so that they were on the same private host only network, did the trick.

One place that it shines is with training. We had to do a half day course on the Microsoft Sharepoint Portal Server. Rather than going through the hassle of trying to get the software installed and configured beforehand on our PCs, the instructor waltzed in on the day, pulled out a couple of DVDs with preconfigured VMWare saved files and we were ready to go. The added benefit was that we did not have to worry about installing and removing the software from our PCs.

On Mac OS X, Virtual PC provides a similar facility. The main purpose here seems to be to provide access to Windows only applications. I have used it, but don't find it as snappy as VMWare. Possibly because I was running it on a iMac 800 with 768MB.

Microsoft also provides a version of Virtual PC for Windows, which I haven't tried yet.

Sweet Spot

Moving between different screens of a small 12" iBook (1024x768), a 17" iMac (1440x900) and a 19" Windows 2000 (1280x1024) Desktop PC got me thinking about how I use screen real estate. My initial reaction was that the larger the screen size and the higher the resolution, the better I work.

I mean, with a large screen and high resolution, I can show more columns and rows in an Excel spreadsheet, fit more lines in a terminal window or see more of the code when editing a file. Or sometimes I have my program editor open on one half of the screen and the running version of the program on the other half.

However, I am starting to think that maybe bigger is not always better. I think I am using the 12" iBook reasonably effectively and for some tasks, I actually prefer using it instead of the 17" iMac. And that is what started me thinking.

Basically, there is a part of the screen that I am comfortable focusing on. Whatever I am currently doing, has to be done in this sweet spot. For me this is about 600x600 in the centre of the screen. Whatever application I am currently working on has to be positioned there. And whatever bit of text or thing I am working on has to be near to the centre of this sweet spot.

For example, Vim provides a way of showing multiple documents in separate windows within the main application window. However, I find that there is always one area of the window that I prefer working with. If there is something in the top right window, then I feel more comfortable moving that window into the sweet spot rather than looking at and typing into the window in the top right corner.

I prefer only focusing on one task at a time. If I am coding, then the entire screen should be devoted to coding. However, It doesn't mean that the whole screen should be one code editor. I am comfortable with supporting information panels surrounding a central working area. For example in Photoshop and Photoshop Elements, the information palette is very useful for showing, in real time, the size of objects when they are being resized and/or the RGB values of the pixel under the mouse pointer.

But I still like the area I am working on to be in the centre of the screen. And I don't like these additional information panels encroaching on the sweet spot.

Launchbar for Windows?

We all know how much I rave about Launchbar. Well, there is a Windows equivalent, called AppRocket. Well, a sort of equivalent. It has a similar idea of learning and remembering shortcuts that run commands. But, it currently has some shortcomings.

  • It requires the Dot Net Framework to be installed.
  • It is useful for launching apps. However it is not that great at finding running instances of existing apps. So for example, if you launch FireBird by pressing alt-space and then keying in Fire, Firebird will launch. That's dandy. However, switch to another app and then try getting back to Firebird using the same method. You end up with another instance of Firebird. Bah!

    Generally speaking Windows Apps don't seem to return you to the currently running app if you launch it again. Exceptions to this are Photoshop and VSlick (which has the +new command line switch if you want to launch a new instance).
  • It does not show a list of running apps as you can do in Launchbar.

However, it is still only Public Beta Two. So it could still be early days.

The Lack of Mnemonics in Mac OS X

One of the major differences between Mac OS X and Windows is the lack of mnenomics in the Mac OS X menuing system. There is an explanation at Java 1.4.1 Development for Mac OS X: Making User Interface Decisions, about the lack of mnemonics:

This does not fit in with the Aqua guidelines for multiple reasons. Among them:

  • It is extraneous information. The shortcut is already defined to the right of the menu item.
  • It is imprecise. Note in this example that Save and Save As both have the letter S underlined.
  • It clutters the interface.

However, one point that is missed is that mnemonics are in fact an alternate way of accessing menu items quickly. They are not intended as a replacement for shortcut keys. They are there to help people use an application quickly more quickly.

As I start using an application, there is no way that I can remember the shortcut key of every item. I have a good idea which menu the item is on. So if I can take a quick look at a menu, I can see whether an item is on the menu. if it is there, I invoke it.

Mnemonics help reinforce this pattern. Using mnemonics, I can cause the menu to appear quickly. If the item appears on the menu, pressing its mnemnonic invokes the item.

Eventually, I get to remember the sequence of mnemonics required to invoke an item and I don't have to search the items on the menu. If I find I am using the same item frequently, and it has a shortcut key assigned, I will start using the shortcut key.

Link Blogs

What a neat idea Richard has!

Using Mac OS X and a .Mac account, it is possible to organise your bookmarks and synchronise them between different Macs running Safari. However, as far as I know, you need to do this with Safari and you need a .Mac account.

Creating a link blog like Richard has done, suits those who browse at different places with different operating systems and browsers. From any box with a browser that is connected to the net, you can now persist your links so they are accessible elsewhere.

Lastly, separating the content and link blogs, gives better focus to each. I can now subscribe to the content blog to get the juice without having to trawl through zillions of short one liner links.

Outside In

I couldn’t agree more with /ndy’s Weblog about people finding workarounds to cumbersome, bureaucratic systems. As he concludes

The solution, of course, is to align the “official” system more closely with the needs of the people.

I like to Think Outside In. What is customer’s real problem and how can you help solve it? How can we do it without forcing our systems, processes or inefficiencies on them?

Launchbar again.

I mentioned previously how useful Launchbar is for keyboard junkies. Another neat feature is the way it can jump to a particular pane of the System Preferences.

For example, to get to the Network Pane from whatever application I am working in, I key the following

alt-spacebar network<enter> and the System Preferences Application is displayed (or started if it is not currently running) with focus on the Network Preference Pane.

iBooked…

I purchased a low end G4 iBook with an AirPort card and an AirPort Extreme base station. What prompted this madness, I hear the family and other sane members of the public asking?

A number of things, I suppose, and in no particular order.

  • I thought it was time to learn more about wireless, particularly as the local council intends establishing a continuous WiFi (wireless fidelity) zone along the length of Lambton Quay, the main retail street in Wellington.
  • I wanted to be online without having to be seated at the desk.
  • Wanted better OmniGraffle performance. A G3 500 iBook I was using, just could not hack the zooming in and out of simple diagrams.
  • I need a way to manage digital photos when travelling. You can only fit so many onto a compact flash card. And I like to review and cull photos on a computer rather than on camera.
  • I went cheap rather than top of the range. I don't think I am ready to make a laptop my primary machine yet. And I did not want to pay a premium to find out.

And I am impressed. Working sans wires is fantastic. It means that I can read the news, blogs without being tied down to one place. Zooming in OmniGraffle is improved. Will have to wait till I travel to see how it handles photos.

Fantastic IDEA!

I have been using editors in one form or another for about 23 years. And now I am using IntelliJ IDEA. Man, is it impressive or is it impressive. As Photoshop is to doing graphics, IntelliJ IDEA is to cutting Java code.

The most impressive thing is the overall usability. It has been designed and built with the developer in mind. Attention to detail is unreal. It is feature rich, but not bloated. I reckon that one could run an entire course on usability using this product as the case study.

As Alex Moffat comments about the product

I would imagine that IntelliJ is written using IntelliJ, and I think this must account for some of its success. Whatever is an annoyance to IntelliJ's users will be an annoyance to its developers first, whatever makes developing the product hard or slow will make using the product hard or slow, and conversely whatever makes development easier and faster will make use easier and faster. If you can arrange it so that your software developers are also your first software users it can certainly help your product.

The keyboard customisation is fantastic. You can assign a keystroke to almost any action. The best bit is being able to assign keystrokes to a particular Ant task. So with one keystroke you can build your classes and deploy to the web container. What I thought was really useful is the way you assign an Ant task to a hotkey. Simply right click the Ant task and select the assign short key button, and Bob's your uncle.

The refactoring, which I have only started to use, is impressive.

Paste in a snippet of code that refers to an package/class that you don't have an import statement for yet, and it will prompt you to add the import statement and then do it.

Favourite features? The tight integration of Ant. The built in change control which tracks any changes you have made. The diff facility reminds me of the Apple Developer Tools difference utility. The ability to run on Win and Mac. The way it highlights variables that have been declared but not used. The ability to close all edit windows except for the one that you are currently working in.

A concept also implemented in Eclipse is the vertical bar (next to the scroll bar) that is a visual representation of the total file size. Any errors or warnings are highlighted on it showing the relative position of the error or warning in the file.

Cruft Happens

Heh, heh. A pretty good chuckle on the “pleasures” of installing an operating system at How to install Windows XP in 5 hours or less [dive into mark]

A Verity Stobb article on Cruft in Dr Dobbs Journal, is similar in spirit. Rather than detailing the installation steps, she talks about the steps a computer goes through to require a reinstall.

One interesting allusion she makes is that cruft applies to all operating systems. I must say, for all the operating systems I have worked with ranging from DOS, VM, OS/VS, MVS, OS/2, all incantantations of Win, Linux and most recently Mac OS X, cruft happens. And it eventually requires a reinstall.

However, thinking further, it could be argued that cruft is not a state of the computer, but rather those who use it. I must admit, that my clothes drawers are not neatly laid out and that there is clutter around the house. I wonder if there is a correlation between those who are fastidious by nature and the cruftidity index of there computers?

Knight’s Lives

An interesting problem sent by a colleague.

King Arthur wishes to marry off his daughter to one of the knights of his land. Being mathematical of mind she set a problem for the knights...

"I invite all the Knights of the land
Place the seats in a circle numbering them from one
Lets the knights choose their seat
Say to the first "You live"
To the second "Off with your head"
To the third "You live"
To the forth "Off with your head"
And so on until one knight remains
This will be the knight I marry"

Which seat would you choose if you were a knight wishing to marry the princess?

I couldn't visualise the answer. So I tried mapping out the solution manually and after a couple of goes knocked up a Perl script to print out the sequences.

#!/usr/bin/perl
use strict;

my ($rounds) = $ARGV[0] || 17;

foreach my $size (1..$rounds) { my @list = (1..$size); my $knights = $#list+1; my $finis = 0; my $i = 0;

while (!$finis) { push @list, $list[$i] if ($i+1) % 2 != 0; $i++; $finis = 1 if $#list+1 == $i; } print "For $knights knights, choose position " . $list[$#list] . “n”; }

The position for each group of knights up to group size 35 follows:

For 1 knights, choose position 1
For 2 knights, choose position 1
For 3 knights, choose position 3
For 4 knights, choose position 1
For 5 knights, choose position 3
For 6 knights, choose position 5
For 7 knights, choose position 7
For 8 knights, choose position 1
For 9 knights, choose position 3
For 10 knights, choose position 5
For 11 knights, choose position 7
For 12 knights, choose position 9
For 13 knights, choose position 11
For 14 knights, choose position 13
For 15 knights, choose position 15
For 16 knights, choose position 1
For 17 knights, choose position 3
For 18 knights, choose position 5
For 19 knights, choose position 7
For 20 knights, choose position 9
For 21 knights, choose position 11
For 22 knights, choose position 13
For 23 knights, choose position 15
For 24 knights, choose position 17
For 25 knights, choose position 19
For 26 knights, choose position 21
For 27 knights, choose position 23
For 28 knights, choose position 25
For 29 knights, choose position 27
For 30 knights, choose position 29
For 31 knights, choose position 31
For 32 knights, choose position 1
For 33 knights, choose position 3
For 34 knights, choose position 5
For 35 knights, choose position 7

From this output I deduced the following:

given a number n (the number of knights sitting around the table), find the largest number m less than n that is a power of 2. Then find the n-m+1th odd number and that is the position you should be sitting in.

So for 21 knights, the largest power of 2 less than 21 is 16. 21-16+1 = 6. The 6th odd number is 11 (1, 3, 5, 7, 9, 11). So if there are 21 knights choose position 11.

Generating Code

There is an excellent article on code generation at Frans Bouma’s blog

One potential disadvantage he mentions is that the generated code is not up to par with the functionality requirements you have.

I have a similar concern. That is, they can get big, complicated and become the centre of attention. This can detract from the application being built. At the end of the day, we are building a system or application for a client. It is those requirements and that application which should have our primary focus.

Finally, for me the ultimate code generator is a powerful scripting language such as Perl, Python or Ruby. Using these, you can build and maintain custom code generators quickly.

Code Completion

Code completion comes in a number of flavours. One way is syntax expansion. Another way is recognizing code symbols (such as procedure and variable names). A third is to match strings in the current file.

Syntax expansion is like providing a template and you fill in the blanks. For example, while coding Perl, if you type if, the editor will recognize if as a keyword and then expand it to if (){ } to suit your favourite brace style.

The second way is by understanding the program code. By recognizing the procedure names as you key them in, the editor can supply parameter information and prompt for parameter values. This is a real boon. But, the real kicker is when it starts recognizing procedure names from other project files or even standard code libraries.

The third category of code completion, works with arbitrary strings. Instead of retyping long strings, you type the first few characters and then get the editor to look for a matching string. Sort of like an incremental search. Except that you have the option of using the string that is found.

For example in Visual Slickedit, as you key in some text, you hit ctrl-shift-< and the editor will search backwards in the file to find the first matching text. If this is not the text you are looking for, hit ctrl-shift-< again to find the next match. Once you have found the right piece of text, you can either hit enter to use it or you can pick up more of the surrounding text by pressing ctrl-spacebar.

All three of these techniques are provided by Visual Slickedit and VIM.

Jump to Definition (and back)

Another feature that I can’t live without in an editor is “Go to Definition”. Basically, if you are examining a variable or procedure and you want to get to the definition, just press a hotkey and the editor will position you at the definition. If the definition is in another file, the editor will open and load the file and position you at the right place. You can get back to the place you came from by pressing another hotkey.

This feature is reasonably common and is found in Visual Slickedit, VIM, the Visual Basic Application editors (Excel, Word and Access) and even the Visual Studio .Net IDE (although this took some digging to find). Again, I haven’t found a way of doing this in BBEdit.

Selective Display (aka folding)

I am a simple guy. I can’t keep reams of detail in my head at one time. I like to see an overview of what is happening and when I need the detail, I want to get to the relevant bit quickly. When finished dealing with the detail, I want to return to the overview.

And I want to do this fast!

Any editor that supports this is a real saviour. Of the editors I currently use, Visual SlickEdit provides Selective Display and VIM provides Folding. Unfortunately I have not discovered this feature in the doyen of Mac editors BBEdit

I use it in a couple of ways. The first is to see the structure of the code i.e. what can be called and what calls it. The second is to place the cursor on word, hit a hotkey and have all occurrences of the word displayed. Hit another hotkey and the entire file is displayed again.

So what you say. A grep or find all occurrences does this already. But the difference is that selective display shows the results in the same window. From a coder’s perspective, it looks as though all lines that don’t contain the word have been hidden and the ones that do remain visible. You can now use normal cursor navigation to get to the line you want. Once there you can edit or even make changes.

To try out selective display in Visual Slickedit, look at the View Menu and bring up the selective display dialog. To learn about folding in VIM take a look at the VIM online documentation.

Starting Again

Finally got around to setting up a blog using movabletype on a Linux hosting service.

Decided on movabletype because it is relatively open, it is done in Perl (with which I am familiar) and it also sits on top of a database. The real clincher was the user interface and the way that it handles mulitple weblogs and authors.

For the hosting services, I settled on mtvhosting to do the hosting as they offer great facilities at a reasonable price.

Why I won’t buy Apple

This is the only guest post, by John.

My only Apple purchase was a MessagePad 2000, which I bought in late 1997. A bit after buying it, I had occasion to send the following email to Apple (webmaster@newton.apple.com):

Hi Folks,

I bought my MessagePad 2000 in September. You can imagine
that I was dismayed to see it become superceded in October,
then delighted to find the offer of an upgrade. I understand
that the demand for upgrades has been high -- it took me
weeks before I was able to get through to an operator.

Then I was told that the upgrade kits are out of stock, and
will not be available until February, but that you would be
happy to take my order and bill my card now.

The idea of billing me now for a technology item which may
or may not become available in February is outrageous, but
that’s up to you. What I really would appreciate is if you
could try to put accurate information on your web page,
though. Currently, it has statements like:

* The upgrade can be ordered starting after November 10,
  1997.  The upgrade program ends April 30, 1998 or until
  supplies last, so be sure to order early.
* ...you may hear a recording stating that the system is
  busy and to try your call later. You may also experience a
  long holding period for an available operator to take your
  order. We do not anticipate this to be an ongoing problem
  as the program progresses. If you have encountered any of
  the above problems, we encourage you to please try calling
  at a later date when the call volume will be lower.

which do not describe the situation properly, and are
eroding my satisfaction. There’s not much point in holding
for fifteen minutes to be told that you can’t get something
until February.

On the positive side, thanks for a great product in the
MessagePad 2000.  I only hope that the demand seen for this
upgrade indicates that the Newton line is very much alive
and well, and that we can look forward to many more years of
great products in it.

Regards,

John Hurst

They didn’t even answer my note, nor (I think) did they correct their misleading web site. Instead, they dumped the whole Newton line in early 1998. Great move for customer loyalty.

I got a couple of years of partly-satisfactory use out of the gadget, but ended up putting it in the closet, since it could not be made to interoperate with anything else. A fate which should be of concern to any potential customer of theirs.

Keyboard Heaven

Wow! Does Launchbar let keyboard junkies rock or what!!. This utility is like a combination of the VSlick alias facility, the Windows run command and the Mac OS X dock all rolled into one.

The VSlick alias facility lets you get at files or directories quickly using your specified aliases. The run command lets you quickly start applications, open directories or files. The dock shows you what’s running and acts as a sort of a repository for favourite applications.

Launchbar lets you get at files, folders, urls and applications with the keyboard using easy to remember aliases or mnemonics. Now, using the keyboard I can quickly get to the application I want without having to watch how I get there.