Mar 052013

I’ve discovered the fantastic yearbox plugin for Dokuwiki, which is superb for my electronic lab notes.  However, implementing it neatly required me to change the filename of every log entry from the last few years.  In my old Dokuwiki system, each log had a filename like


I needed to keep the directory structure, but change each filename from two digits to the form “2013-01-07-ljr.txt”.

It turns out to be fairly straightforward with some clever bash tricks.  I changed into the log directory and used this command:

 for i in `find -name '??.txt'` ; do mv $i ${i%/*}/${i:2:4}-${i:7:2}-${i:10:2}-ljr.txt; done

Here the first part finds all files with names of the form “??.txt”.  Then each file is renamed with the “mv” command.  The ${i%/*} gives the file path with everything after the last “/” removed (ie it gives the subdirectory of the file).  Then the rest of the parentheses give extracted parts of the filepath string.

All files stayed in their own directories, and were renamed with additional information from their directory path.  Easy!  Well, not unless you know the details of string manipulation in bash – which I don’t.  I found enough information to do this after looking here and here.

Mar 052013

I often use the “-” symbol to separate parts of a long filename.  For example, my photos are systematically named things like “20130214-1123-34_some_event.jpg”.  For filename maintenance I regularly use the rename command, which allows me to do things like

rename some another *

which would replace the word “some” with the word “another” for every filename in the current directory.  When I need to replace a chunk of filename starting with the “-” character, the rename command thinks I’m passing it an option.  I’ve just found a helpful answer that shows how the “end-of-options” signal fixes this problem.  This signal is simply a double dash “–”.  For example, this command

rename — -11 -10 *

would change the timezone on a bunch of photo filenames.

Dec 092012

In the last few weeks I have both moved into a new house and constructed hexaflexagons in celebration of Martin Gardner’s birthday.  If you don’t know what I’m talking about then you must go and watch Vi Hart’s videos on the exciting topic.  This unusual combination of activities led me to discover a remarkable Ikea-hack: the flat-pack hexaflexagon.  Excitingly, this product is available at all Ikea stores completely free of charge!  It is cleverly disguised as an appallingly practical paper measuring tape, but a small amount of construction will transform the strip into an entertaining mathemagical toy.

Nov 232012
Partition scheme with Gentoo Linux and Windows 7

By making 100 MB available for Windows to create a primary partition with boot essentials, I was able to get it happily installed in a logical partition without even disturbing my Gentoo Linux installation.

Almost 10 years since I removed Windows from my computer and gave the whole hard drive to Gentoo Linux, I had a specific reason to put it back on. Naturally I’ve gone through a few computers in the last decade, but the flexibility of Gentoo has enabled me to transfer my Linux installation across numerous hard drive upgrades and computer changes. I have not been in the habit of leaving hard drive space for any secondary operating system.  At first I feared I would have to do a full backup and then restore my system to a new set of partitions, but found a much quicker solution where the hardest part was persuading Windows to install on a logical partition.

Continue reading »

Jul 042011
Baked pies

Tau Day is celebrated with two pi(e)s, and we couldn't let that expectation go unfulfilled.

Pi is wrong. This startling assertion became so abundantly clear to me last week that I was surprised it has taken this long for me to encounter the arguments. Of course, as the number of diameters in a circle’s circumference then pi = 3.141592 653589 793238 462643 383279 50288… is technically correct. But it is wrong conceptually! Mathematically it is the radius, not the diameter, which is the defining dimension of a circle.

And so a better circle constant is τ (tau) =2π. Happily I learnt of this just in time to celebrate Tau Day.

There are many excellent reasons why tau is better than pi, and I won’t bother presenting them all here. Michael Hartl makes the argument convincingly in The Tau Manifesto if you are looking for some reading, but this video presents the salient points in a thoroughly entertaining way.

If you’re strugging to catch on to tau as the new circle constant, then maybe this musical representation of the number will help.

We dutifully and cheerfully celebrated Tau Day with two pies, and it is a shame that next June 28 is a year away. I guess that is a full year in which to extol the virtues of Tau.

And there’s another job to do. The 36 digits of pi listed above were written from memory. I have them firmly lodged in my brain as a result of a friendly competition in grade 5. Now I’m going to have to memorise at least 37 digits of tau!

May 172010

When I first started using WordPress to construct this website, it had “categories” and not “tags”. Since then, I have tried to improve my use of categories and tags have come along to add another complication to the fray. I have now finally reached a system that I really like.

One of the difficulties of a personal website (as opposed to a blog on a specific topic) is that there is such a variety of post types. Sometimes the site becomes a little soap-box where essays can be delivered. Other times, it is a news feed to keep family and friends updated about exciting travel activities. It is also a valuable way to store and share helpful tricks and insights.

So I have now culled my category list down to six distinct topics, and a seventh “uncategorised” overflow pigeonhole. Within these broad categories, posts are further grouped by tags. It is possible to browse posts by category, or by tag. While I’m not claiming that this sort of organising strategy is anything new or unique, I think it is finally a functional way to hold this site together.

I have also revamped this site visually and under the bonnet. Here are some of the more technical details.
Continue reading »

Feb 022010

At ASA Convention, a number of us took many photographs.  Late on the last night, I helped compile the highlights into a souvenir data DVD.  Using the nifty little exiv2 utility, I was able to adjust the image timestamps and retrospectively synchronise the clocks in every camera.  This makes for very enjoyable photo browsing, as you can view chronologically regardless of which camera was used.

Unfortunately I was too rushed to place attribution in the filenames, and so it is not obvious who took each photo.  Luckily we all used different camera models, and that information is still present in the exif metadata.  I used this to split the photos into directories and embed the photographer in both metadata and filename.

I was shooting on my Nikon D200, and so was able to separate my photos by:

for ii in *.jpg; do if grep -q "NIKON D200" $ii ; then mv $ii lachlan/ ; fi ; done

This says: for each jpg file, check if it contains “NIKON D200″ in the exif metadata and if it does then move it to the subdirectory lachlan/

All you need to do is find the camera model string to search for (my friends with Canons had things like “Canon EOS 30D”).  Now I’m going to append photographer names to the filenames, and then return them to their original chronological directories.

[For Facebook Notes readers: this post is redirected from my personal website]

Nov 102009

I jotted this down a year ago when I needed to produce a set of handout notes for a 3rd year physics lecture I took. Just last week, after taking a similar set of lectures, I wanted to find it but couldn’t. Murphy’s Law has come into effect, and my jotted note has turned up now that my need for it has passed.

The Beamer class for LaTeX is a great way to produce very nice presentation slides with useful features such as automatic progress markers and internal hyperlinks. Being LaTeX, it is also possible to completely change the output formatting by simply altering certain document settings. This allows me to produce slides that have black backgrounds for better projection onto a screen, and then change a single line (specifying the colour theme) to get a white-background version optimised for printing on paper.

To make it even more efficient to print, I used the following command to fit 3 slides to an A4 page:

pdfnup --frame false --nup 1x3 --paper a4paper --orient auto --pages all --trim "0 0 0 0" --delta "1cm 1cm" --offset "0 0" --scale 0.91 --turn true --noautoscale false --openright false --column false --columnstrict false --tidy true --outfile main3up.pdf main.pdf

Sep 242009

A few months ago I purchased a “Google Phone”: a HTC Magic running the Linux-based Android operating system. I am incredibly pleased with this device.

Today I wanted to convert some video that I recorded on a Nikon Coolpix camera into a format that would play nicely on my Android phone. The resolution needed to be scaled down for the small screen, and I knew that h264 was the best video codec. After some searching online, and a bit of experimenting, I found that this worked wonderfully:

ffmpeg -i input.avi -aspect 3:2 -s 400x300 -vcodec libx264 -b 480k -r 30 -acodec libfaac -ac 1 -ab 32k -padtop 10 -padbottom 10 -padleft 40 -padright 40 -sameq -pass 1 output.mp4

Continue reading »

Jun 162009

Even when shooting images in raw format, it is typically easier to do simple sorting and sharing with jpg files. With Nikon *.nef raw files, it is possible to extract a full-resolution jpg image using the nefextract script. However, exif metadata is not automatically copied to this extracted jpg.

The tool that I use to manipulate my images according to their exif metadata is exiv2, and I can quite simply copy metadata from raw files to their corresponding jpgs (matching filenames, and all in the one working directory) with:

exiv2 insert -l./ -S.nef *.jpg

After sorting through the jpgs and deleting all but those worth keeping, I wanted to automatically remove the raw files of those deleted images. Sure enough, this is easily done with some bash shell magic:

for file in *??.jpg; do mv raw/${file%%.jpg}.nef 2> /dev/null rawKeep/ ; done

This command says “for each jpg file you find here, move the matching nef file from the subdirectory raw/ to the subdirectory rawKeep/”. I can then delete any files left in the raw/ subdirectory, as they mustn’t have a matching jpg.

People often ask my why I persevere with the “command line” (more technically the “shell”). It seems that they assume tools with graphical interfaces are more powerful and faster. These two routine tasks demonstrate yet again that the shell really is the most efficient way to do many common jobs.