Hacking

Hacking

Finding changes in a sorted list: a trick

Think of a phone directory listing with a lot of Browns followed by some Brownes, Brownings and Brownleys. Is there a simple way to identify the places in the sorted list where Brown changes to Browne, Browne to Browning and Browning to Brownley?

If you're a programmer, you've probably just thought of an 'if, then' test for items in the list. If you're an AWK-lover (like me!) you may have started thinking about the getline option.

There's another and more interesting way to do this job on the GNU/Linux command line, as explained below.

Save time with AWK print

Since discovering AWK last year I've been using it regularly with tables of data. It seems like everything I do with those tables is faster and easier with AWK on the command line than the same jobs would be with spreadsheet software.

Below are a couple of examples that demonstrate the handiness of the print command in AWK. If you've never used AWK before, see the links at the end of the article for a quick introduction to the basics.

Refactoring in a Multimedia Project with Inkscape, Blender, and Audacity

One of the special problems with managing a multimedia project (versus a text-based software project), is that there are often links to external data files which can get broken when you try to move the files around -- such as you might do when re-factoring the source code to make it more navigable. Three programs that we use extensively in the Lunatics project present this problem, and each requires slightly different handling. These are Inkscape, Blender, and Audacity. I have never found a compact guide to keeping the links straight in these programs, so I'm going to write one here.

CoPa: 2 scripts for LibreOffice Calc and 1 for the kid in you

In a previous article I introduced the idea of modifying text between copy and paste in Linux, using a 'CoPa' script based on the xclip utility. Please refer to that article for the basic ideas.

Here I demonstrate two handy CoPa scripts for spreadsheets, and a simple coder/decoder for (very!) low-level encryption of email text and other messages.

Split a spreadsheet into multiple files with the GNU/Linux command line

Have you ever wanted to split a spreadsheet into several spreadsheets according to the contents of a particular field? For example, you might have a music tracks spreadsheet with an 'artist name' field, and you want separate spreadsheets for each artist, with the usual field names along the top of each new spreadsheet.

You can split a spreadsheet by copying and pasting the different sections into new spreadsheets if there aren't many records. If there are lots of records, this manual approach can be pretty tiring. For splitting very large spreadsheets, most users turn to special stand-alone programs (in the Excel world) or fairly complicated macros (Excel, Open/LibreOffice Calc).

I split my spreadsheets using the GNU/Linux command line, as explained in this article. It's another of my trademark ugly hacks, but it works well and the command line steps can be combined into a script which runs fast and reliably.

Firefox and Iceweasel can 'mailto' with Sylpheed and Claws Mail

Some webpages contain email links. If you right-click on the link in most Web browsers, a menu appears that lets you copy the email address to the clipboard (first screenshot). You can then paste the address into the To field of a new email message.

In recent versions of Mozilla's Firefox browser, you can also left-click on the link and get some action. If Mozilla's Thunderbird is your default mail program, a Thunderbird 'compose' window may appear with the To field automatically filled in. This article explains how you can get the same automatic result under Linux with the excellent open-source mail programs Sylpheed and Claws Mail. The method also works with Iceweasel, which is the rebranded Firefox packaged with Debian GNU/Linux.

Build a scientific names dictionary for LibreOffice

LibreOffice only knows how to spell a few scientific names, and the more scientific names you use in a Writer document, the more your pages fill up with squiggly red underlining – indicating misspelled or unrecognised words (see main image). You can add scientific names to LibreOffice's spell checker using the application's spelling dialog box, but only one word at a time.

Is there an easier way? Yes. This article explains how you can save a lot of time and effort by adding hundreds of scientific names to the spell checker all at once.

Color picking made simple

If I see a color on my computer screen that I'd like to use somewhere else, I want to know that color's hexadecimal code. Conversely, if I see a color's hex code, I want to know what that coded color looks like on-screen.

Some time back, I wanted an application that does both those jobs simply in Linux. The best tool I found was gcolor2, described below. It's great for finding hex codes, but it doesn't display colors in a large enough 'swatch' to suit me. To do that job I wrote a simple script, also described below.

Convert XML to CSV the ugly way using Unix utilities

I recently wanted to export my email address book from Sylpheed email client and import it into my Gmail account. Unfortunately, Gmail wants to import contact lists as CSV files, and there isn't an export-address-book-to-csv feature in the otherwise wonderful Sylpheed. Worse, the Sylpheed address book is in XML format, and XML-to-CSV conversion isn't straightforward.

Warning: What follows contains code that may offend real programmers. The code works but it's pretty simple-minded, and if you're a real programmer and not a hobbyist hacker like me, you may not want to read any further.

Checking a website for incorrect links

When you build or update a website, it's a good idea to check that all the links on your webpages are OK. An excellent tool for doing this under Linux is the aptly named linkchecker, a GPL-licensed, command-line program.

However, 'OK' has more than one meaning. While linkchecker can check the URL you specify to see if it's properly formed and not broken, it can't tell you if the link points to the wrong URL.

A spreadsheet jukebox

My wife has a huge collection of Scottish country dancing music on her Linux laptop – more than 2000 dance tracks. Details of all tracks are recorded in an OpenOffice Calc spreadsheet.

She asked me, "Could you make the spreadsheet into a jukebox, so that I could do a filtered search for a suitable track, then just click on the track to have it play?" The answer was yes, but it took a while to get there!

Lib-Ray Video Standard: Handling Languages and Localization

I'm used to thinking of region codes as an unmitigated evil, but they do serve one useful purpose: they divide DVD editions up so that any given regional edition has fewer languages to support. It's uncommon to find a DVD with more than just three or four languages in subtitles or audio tracks. Early on in the concept for Lib-Ray, though, I decided to do away with region-coding, and instead allow for broader localization in the design. This means there's just one edition worldwide, which is very helpful, but it does also mean that the subtitle menu in particular can become very cumbersome to navigate. How will we solve this user interface design problem?

Write a simple launcher using Zenity

Nowadays, we mostly interact with our computers using a Graphical User Interface. The operating system as a whole uses several elements of the GUI to make the user experience more human-like. Can users get to unleash some of the GUI's power? The answer is yes: welcome to Zenity, a GTK+ application that works in GNU/Linux, BSD and Windows. In this short article I will show you how to create a simple script that interacts with the user using the GUI.

File Thingie: A No-Nonsense Web-Based File Manager

File Thingie is not the sleekest or feature-richest web-based file manager out there, but it's a perfect fit for those who need a no-frills solution that is easy to deploy and use. This is not to say that File Thingie skimps on features. All the essential functionality is there, including the ability to upload multiple files in one go, support for users and groups, file access control based on black and white lists, and more.

Lib-Ray Video Standard: Assembling the Matroska MKV container file with mkvtoolnix-gtk

In my previous installments, I described the success I've been having with compressing "Sita Sings the Blues" with the VP8 video codec, and at the end I had a video file. Then I converted the audio to get a FLAC copy of the soundtrack (opting to retain this rather than compress into Vorbis format). Now in this installment, I'll show how I used mkvtoolnix-gtk to build a complete MKV file with VP8 video, FLAC audio, and named chapters. The result is the complete "main feature" multimedia file that will form the core of the Lib-Ray prototype.

Lib-Ray Video Standard: FLAC and Vorbis codecs for Sound

In my previous column, I described the success I've had with using VP8 for compressing the video for the Lib-Ray main feature multimedia file. At the end of that process, though, I still have a silent film. We also need to get the audio, and make a decision about the format. WebM calls for Vorbis sound, which probably makes sense for internet downloads, but this is where we part ways -- for my application, bit-perfect audio with FLAC seems to make more sense, at least for the main audio tracks (Vorbis is still in the picture for things like commentaries).

Programming effective reminders in GNU/Linux

There are some nice sticky-note applications for Linux, and they're good places to write down reminders, like Ring Fred or Pick up a litre of milk.

Unfortunately, sticky-notes are no help to me at all. I'm often forgetful, and I'm more than likely to shut down my computer without checking to see if I've written a note to myself. To get around this problem, I wrote a couple of very simple scripts, each launched by an icon on my Xfce panel.

Pages

Subscribe to RSS - Hacking