Category Archives: Technology

Spellchecking in Vim

Here’s something I didn’t know.

I have used Vim to write text files in the past and, when I do so, I use aspell check to catch my multitude of typing errors. It turns out that Vim is also able to support spell checking, so I no longer need to keep dropping back to the command line.

Joe ‘Zonker’ Brockmeier goes into detail, but I am reposting the highlights here so that I can easily find them again.

:setlocal spell spelllang=en_gb turns on the spell checker.
:set nospell turns it off again.

]s and [s moves to the next and previous spelling errors respectively.
z= brings up a list of alternatives for the typo under the cursor.
zg adds the word to the dictionary.
zw allows you to mark a word as incorrect.

This post was entirely written in Vim.

flattr this!

Firefox 31 and the New Tab tab

Firefox 31 hit the Arch repos at some point today and now I have it. Since Mozilla moved to their 42 day release cycle, most of the changes from one release to the next have been incremental and not really worth noting. But I did notice something new when I opened a new tab.

That search bar immediately above my most recently used tabs is new. And handy.

And, for the borg-averse, you can change your default search engine by clicking on the logo. This gives you a drop-down showing your currently installed search engines and an option to manage the same.

flattr this!

Doudou Linux

Back in December, I acquired an old, old laptop with the intention of letting the twins use it. My eldest already has access to a laptop, which is running openSUSE and configured so that he is able to use it without (usually) needing any help from me. For the twins, though, I thought it would be worth giving Doudou Linux a try.

I have been very impressed indeed.

Doudou Linux is a Debian based-distribution aimed at 2 to 12 year olds. It achieves this by way of a heavily customised LXDE desktop which is very easy for a four-year-old to navigate. The terminal, and some of the settings, are tucked away somewhat – to the extent that I had to go to the online documentation in order to find them – but this makes sense in the context of a distribution aimed at young children. You really do not want a typical pre-schooler to find their way into any of the
settings, ever.

We have been using the live CD version for the past six months, but this weekend I finally found the time to actually install it. The installer is graphical, intuitive and familiar to anyone who has ever installed a Debian based distribution. The only quirk is that there is no icon – we’re back to keeping dangerous options away from little hands again – and you have to find the terminal in order to launch the installer.

The install itself is quick and painless and the laptop really is flying now. This is a very undemanding distro in terms of resource requirements:

To make DoudouLinux run, a PC or Macintosh computer with 256 MB of memory and an 800 MHz processor inside is required.

I have also been pleasantly surprised at the width of the software selection. The Childsplay and Gcompris suites are both included, as is Tux Paint. What has proved popular with the twins is Pysycache, which mainly aims to teach mouse control but comes with a collection of digital jigsaws that are surprisingly entertaining.

Also popular in our household is Raincat, a puzzle game in which you have to keep a cat dry as it travels from start to finish. The controls on this one can be a bit unforgiving and I have found that it works best if I sit with the twins, talk about how to solve the puzzle, and then handle the actions for them.

There are many more games and applications included and one of the many nice touches is that Doudou Linux groups these into age-appropriate categories (an initial menu, Mini Doudou Linux and Whole Doudou Linux) which means that the children can explore what’s available without being overwhelmed by inappropriate choices.

Overall, Doudou is a really well thought out, very nicely designed distribution that does look like it will grow with its target users. I can see us keeping this distro around for many years to come.

flattr this!

Keeping Qshell sessions alive

Not a lot of people realise this, but the IBM i has a POSIX compliant shell environment, known as Qshell. It’s relatively basic (compared to both BASH and the native i command line) but it can be quite handy when I need (for example) to grep a source file.

One thing that has always annoyed me about Qshell, however, is that it doesn’t retain any history between sessions. Given that my workflow will involve starting at the i command line, performing a task in Qshell, and then returning to the command line, the lack of a history lead either to unnecessary typing or copying and pasting commands into and out of a text editor.

Today I noticed that the F12 key can be used to disconnect a Qshell session without actually ending it. And when I next enter the QSH command, I find myself back in the same session with my history intact.

This isn’t going to help with finding commands I typed yesterday, but it will allow me to avoid unnecessary retyping within the same day.

Footnote

Why use grep to search a source file rather than the more usual FNDSTRPDM command?

Incompetent contractors is the short answer. Incompetent contractors who introduced an unknown number of divide by zero errors is the slightly longer answer.

In RPG, the division operator is / and the comment symbol is //. I could use FNDSTRPDM to search for all the slashes and then manually scroll past all the comment lines. Or I could shortcut this process with the following piped grep:

grep -in '/' /qsys.lib/sourcelib.lib/qrpglesrc.file/program.mbr | grep -iv '//'

I’m lazy. I grep.

flattr this!

First steps in programming

For those that don’t know, Big Trak is a programmable tank. It was popular (with me, at least) in the 1980s and reissued in all its retro glory a few years ago.

Big Trak, if you don’t remember, was an amazingly cool-looking 6-wheeled tank that you could program yourself to move around whilst firing its photon beam. Happily, not much has changed with this new version, which means you can not only relive the fun you had as a kid but, if you’ve got children of your own, pass it on through the family.

A few simple instructions can make your Big Trak go forward a certain number of lengths, fire, and then come back to you. The onboard memory will store up to 16 commands in one go, which means you can easily have your faithful tank-servant completing some complex manoeuvres in no time.

I have one and Alexandre is fascinated by it. So much so that he can now code up the basic manoeuvres himself…

Turning is still a challenge, but we’ll get there.

flattr this!

That Linux feeling… on Windows

I have been trying to get along with Windows Powershell at work for the past couple of months and, while it is a huge improvement on the more traditional Windows console, it is nowhere near as functional as the Bash terminal I spend most of my time in when at home. So I started poking around online and ended up on the Cygwin.

Cygwin is:

  • a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.

This does sound good, but it also sounds like potentially much more than I need. I am, after all, only looking for a terminal that I can use to edit and shunt text files without being driven to curse my keyboard.

Luckily, I do have a small Windows partition on my own laptop, so I thought it would be worth giving it a spin at home before screwing up my work laptop enough to attract the attention of the helpdesk.

Before I go on, I shall reiterate that much of the Cygwin functionality os of no interest to me. I really am just looking for a functional terminal environment that I can use while at work.

The install was easy enough. This being a Windows application, it’s just a case of downloading the setup.exe file and clicking on it. You do need to hang on to this file once the install is completed, though, as it also provides the package management functionality for Cygwin. As someone who frequently bins everything, this felt a tad odd to me – but it’s not a problem.

The install creates its own file structure under C:\cygwin64 which took me a moment to find. That said, it makes sense that the *nix environment isn’t mixed up with the rest of the Windows stuff. It’s easy to find and, once you are aware of this, the Cygwin terminal starts in the expected folder.

And onto Vim. This is installed by default, or appears to be. Even though the initial screen says Vi Improved, it does look like Cygwin is actually installing Vi by default.

So I added an alias (alias vim=vi) to my .bashrc and renamed my .vimrc to .virc and then things went a bit wrong as Vi is unable to support any of the functions in my default .vimrc. So, back to the setup.exe file I went where I found and installed vim-minimal.

This does not seem to have helped as I am still seeing a whole bunch of comman not available errors.

I was also rather unnerved when I tried the ftp command and saw my password being echoed back at me as I typed it.

At this point, one of the twins came in and wanted to play Cat and Mouse and I’d had enough of being in Windows, so tinkering was abandoned. But, based on first impressions, the Cygwin Terminal is going to struggle to meet my needs.

The search continues.

flattr this!

Spamtastic

The Akismet spam filter in WordPress really is very good indeed. It does an excellent – and endlessly improving – job of identifying and deleting comment spam that I can simply leave it running and forget about it.

Nothing is perfect, however, and the occasional comment does make it through to my moderation queue. Like this one:

I am John, how are you everybody? This paragraph posted at this network site is really fastidious.

And the post containing this comment worthily fastidious paragraph… Is here.

flattr this!

Using SQL to update one file from another

With a recent interface change, I was asked to go back and fix all of the affected historical data so that it matched the new requirements. Updating a field in one file with a value from a different file is something I have done several times in the past (far too many ah-hoc queries have been launched, if truth be told) and, while you do need to take a bit of care, the approach is pretty simple.

So here is an example (some names have been changed to protect the proprietary):

update target_file upd
set target_field = (select source_field from source_file
                    where source_key_1 = substr(upd.target_key, 1, 16)
                    and digits(source_key_2) = substr(upd.target_key, 17, 5) )
where exists (select source_field from source_file
              where source_key_1 = substr(upd.target_key, 1, 16)
              and digits(source_key_2) = substr(upd.target_key, 17, 5) )

The script is pretty simple. For each record in target_file for which an associated record can be found in source_file, populate target_field with the value in source_field. Obviously, the select clauses will need to reflect the relevant keys of whatever files you happen to be using.

Inevitably, there is a gotcha: for each record in target_file that you want to update, there must be exactly one record returned by the subquery. Handling this can be split into two parts.

The first part is handled by the where exists clause which ensures that the script will only attempt to update records in target_file if there is a record in source_file with which to update it. This ensures you don’t get caught out by subqueries that return zero records.

The second part involves that the subquery returns no more than one record for each record in target_file. This, unfortunately, cannot be solved generically – you just need to be a bit careful to ensure that the subquery selection is returning unique records. If in doubt, a variation on the below SQL can be used to validate.

select source_key_1, digits(source_key_2), count(*)
from source_file
group by source_key_1, digits(source_key_2)
having count(*) > 1

If you can’t find a unique selection criteria, the distinct clause may help and, if all else fails, try arbitarily using either max() or min().

flattr this!

Fat fingered discovery of the day

It’s amazing how much you can learn with a little clumsiness. In my case, all I wanted to do is power off the screen on my Fairphone and, instead, I took a screenshot.

A quick search reveals that this is because I (unintentionally) had my thumb on the volume down button when I pressed the power button.

So now I have a screenshot, so here it is.

flattr this!