Home » Archive by category "Uncategorized"

The Power of #!/bin/bash


Escaping the subshell

The pictured snippet is probably one of the dirtier pieces of code I have had the misfortune of needing – and not being able to refactor to anything cleaner.

I am trying to make bash my main programming language, and to this goal I have created a number of tools to aid me on my way: a library of code snippets that anybody can re-use, a packing tool to create executables, a pre-compilation tool to add compiler directives to bash, a build tool to pull all these together, and a make/release tool to manage versions. And I’m not yet done.

Of the main efforts here is the library of scriptlets.

Once of the main attractions of one language over the other is the availability of a large amount of re-usable code released as libraries and which are, pretty much, taken for granted.

Python can get modules from pip, there are Java libraries in JAR files around the web and even JavaScript has such libraries as jQuery to help to write terser, more manageable code more easily.

bash has none of this. And quite a few quirks. You have to contend with the very string-y way of passing data around (arrays are a bit of a nightmare until you get used to the arcane notations), and nearly every non-trivial operation you want to do is a command, an external process.

The inset image depicts some code I wrote so that assigning variables

But that is also exactly what makes so appealing – any language, and its associated libraries, can become your library!

For starters, python, perl and PHP can all be leveraged for their respective strengths in specific situations, and it is possible to write and store additional scripts such as long MySQL tasks in their own files. Use a perl script to write change on the fly, and pipe to MySQL.

Consider the following silly example:

controlapp -getusers |
    perl alter_sql.pl "$SCENARIO/mysqltemplate.sql" |
    mysql -u "$sqluser" -p"$sqlpass" "$mydb" |
    php to_xml.php |
    controlapp -dostuff

It looks quite awful at first glance, but consider the power of perl to perform text processing, keeping your mysql files ordered in a directory-based hierarchy, and passing the result to PHP which will handle outputting XML much more ergonomically than PHP.

So whilst bash does have its odd and at times even infuriating quirks, I am learning to love it.

It is now after all the de facto language of DevOps. It seems even Windows can no longer do without it :-)

About that: the Internet narrows minds, however open they start out

A commentator on a Slahsdot article reminds that the Internet is a double-edged sword for politics, and for information spread in general:

Rather than a world-wide network enabling us to reach and appreciate a far wider range of topics and beliefs, we’ve instead been largely enabled to find the most comfortable echo chamber to reinforce all of our crazy without having to listen to neighbors who might not agree with our increasingly detached beliefs.

Not that that’s always a bad thing, if you’re a persecuted minority, for example. But I think the edge facing us does more cutting than the other side of the sword most of the time. Just look at how partisan things have gotten.

Read more

Installing Lubuntu

This post is part of a series about getting started with GNU/Linux in virtual machines using VirtualBox. If you don’t already know how to use VirtualBox or virtual machines, please read Introduction to Virtual Machines Using VirtualBox.

You can also follow along if you’re actually installing on a real machine – but you’ll have to troubleshoot machine-specific issues on your own. I can point you to a primer on “Linux distros” if you haven’t gotten totally to grips with it yet.

Section 2 can serve as the template for installing Ubuntu derivatives, including Bodhi Linux and elementary OS, which share the same installer. Read more

Introduction to Virtual Machines Using VirtualBox

This post is part of a series on setting up GNU/Linux distros on your own computer, without reinstalling your computer’s operating system. It is intended for persons completely new to computing who want to discover VMs and GNU/Linux. I list some technical how-tos for Windows and Mac users; I’ll assume native GNU/Linux users won’t have need for such details… If you’re not familiar with GNU/Linux, I’ve written an introduction to help clear up some confusions about it.

This specific tutorial will simply cover recommended system requirements, a brief overview of VMs, and how to setup VirtualBox for the first time. Installing specific distros will be covered in subsequent tutorials. Read more

Of captive orcas, and ineffective preaching

I post below my response to an article detailing “reasons” to stop keeping captive orcas. Whilst there are indeed reasons for not keeping them captive, the article does a poor show in making valid points. I responded to each or the article’s points, and then expounded on what I think the issues are.

For those who think the text bellow is too long:

I think the most pertinent arguments become that
– shows and tricks are unnecessary conditioning, and point to a deeper problem on the human side of the fence
– SeaWorld is guilty of malpractices, the which must be addressed
– unlike other species, orcas have higher mortality in captivity than in the wild (information pending), and are more susceptible to mosquito-borne diseases in captivity.


The article comes from good sentiment but is fundamentally flawed on 6 of their points. Additionally, they miss the true issues. I would like to respond to each point, and then add my own.

1) What is the higher mortality rates due to? Are there steps to prevent this? Have these steps been taken? A battle is mentioned at the start of the paragraph, but no causal links are discussed beyond the passing mention, nor remedies to the issue.

2) Are the medical treatments wrongly prescribed/administered? I see no issues here, apart from decrying the administration of medication itself. On the subject of the Jello – if there is lying, it is a problem with SeaWorld’s practises. Captivity in general is not yet under fire. Better care can be given. Sounds like it is, unless someone can actually point out what care described is not actually being carried out properly.

3) This is a good argument. The further question though is, is it treatable, but it indicates that infection is nearly inevitable, with the only method of prevention being non-captivity, as far as we know it.

4) Nobody likes having their teeth done. We teach human children that they’ll get treats for good behaviour at the dentists. Some adults would rather let their teeth rot than have the corrective drilling done. Braces are a pain, tooth removal even more so – I know this personally. More pertinent question is: is this general captivity practice, or is it SeaWorld’s technique alone? Would changing the type of separation prevent any need for tooth alteration?

5) In the wild, her deformed calf would have been killed and her second would have still killed her by internally decaying, no? Or do I misunderstand the mechanisms at play? It is tragic, but I have yet to see a causal link to captivity causing this.

6) Violence between animals happens in the wild as in captivity. No surprise there. Granted, there is sever fault from the establishment where the gate fell on Kotar, where the gate should have been properly secured. Accidents happen in buildings, I don’t see buildings being banned. Not making the buildings safer is the irresponsible part.

7) This is how captive breeding works. I understand that the same is done for rhinos and pigs, and other large mammals. If you do not feel you can do that part of the job, yes it should be your right to refuse to do it, but it’s not a professional fault, and with reticent non-breeding individuals, this is the only way to collect semen.

The article as a whole I think is preaching to the choir. Those who already want the animals to be free will feel their opinions reinforced, but it offers no real information to the rest of us. Here are my points:

a) I see no merit in having “shows” and killer whales doing “tricks” – there is a fundamental issue with the idea that, to meet the goal that education should be fun, animals need to be trained to “entertain.” It is a shortcoming of our own ability to inspire amazement and wonder in observing the animals in appropriately designed habitats, and observing simply their normal behaviour.

b) Persisting in having incompatible individuals cohabit causes serious issues – points 1 and 6 highlight this.

c) The orca’s conservation status is unknown at the moment. Breeding programs and techniques may need to be studied should they be endangered.

d) If we are to study and understand orcas, we either need to start breeding the ones already in captivity or study them in the wild. To stop them from being held in captivity, we need to demonstrate that the keeping of captive orcas offers us no further information over the study of wild ones. Keeping them for entertainment is not appropriate.

e) The captivity itself of the orca individuals may or may not be beneficial, but a number of the article’s points indicate malpractice at SeaWorld, a specific organisation. Only points 1 and 3 indicate a problem with actual captivity, and point 1 does not present any causal links.

This gallery contains 1 photos.

Colour Spaces mini-Demo Prompted by a question from a friend, I did a brief read-up on colour spaces, as the concept still eluded me somewhat. One very useful entry I found was at HiDefColor.com What I found was very interesting: In a nutshell, a colour space defines the collection and limit of the total set

Read more

Olympus Trip 35

Torchlit Procession, EdinburghI was asked to share how I managed to capture the photo to the right using a Trip 35 – what settings, what film?

The Trip is a little… particular. The following is what I gleaned from the internet some time ago trying to hunt down the technical details. There is no single document to back up my statements below, so take them prudently 😉

The default exposure time on a Trip 35 is around 1/100s

When you set aperture to ‘A’ it will auto-expose using the selenium cells around the lens by varying the aperture for an overall even tone. You may already know that if it judges the picture to be too dark, it won’t release the shutter. The inset picture is mostly dark, the auto-expose would not capture that.

To force the shutter to release, you need to use a “manual” aperture setting.

Rose Street, Edinburgh, ScotlandThe manual setting of the aperture is not an imperative – it informs the camera that the maximum aperture you want to allow is what you have set. If it can achieve a balanced picture with a narrower aperture, say f8 instead of f5.6, then it will use the narrower f8.

If it reaches your maximum aperture and still is not satisfied that the picture is bright enough, it switches to a 1/40s exposure.

You can also insert ISO 400 film but set the camera to ASA 200 for example – in this case since the camera will automatically calibrate for a less sensitive film, the aperture will open up further than if you had set it to ASA 400 (to match your film). In “normal” lighting conditions, this means that with ISO 400 film and ASA 200 setting, your picture will be brighter.

For night-time street captures then, ISO 400 film with settings at ASA 400, f2.8 and exposure 1/40s should yield the right results. Certainly, I always buy ISO 400 film these days, as I nearly always have a want to take photos in low-light.

I hope that serves as a useful summary of the basic considerations for using a Trip 35. It’s a good little camera, albeit a little heavy…

This gallery contains 1 photos.

taifwa: I think this counts as one of the saddest and stupidest things I’ve been told in my entire life. Worse than my old piano teacher, who told me repeatedly at nine years old that I would amount to nothing — at least that was an opinion of me rather than a statement of principle.

Read more

Re: “Native language”

[the following is a reflection in response to a friend’s article; read that one first ]

A rule of thumb I have sometimes heard in the world of translation is that you should only really attempt to translate into your “mother tongue” or “native” language. My friend Anne, a professional translator both from English to French and French to English, recently posted on this topic, highlighting her particular situation of not having one sole “native” language, but rather two. She quotes a passage from a book by David Bellos:

What matters is whether you are or feel you are at home in the language into which you are translating.

In this way, bilinguals can asses their own ability to perform translations to their chosen languages.

Whilst this is fine for general conversation and personal satisfaction however, business is another matter, and I do not doubt that some persons of lesser ability may still bill themselves capable of the bidirectional feat — how then does a customer to such service then shape their yardstick?

I myself feel quite capable of translating freely between English and French, having been brought up in English for the first 9 years of my life by a language and poetry-loving father, and then in French for the ten years that followed that (albeit in an international school, so my street jargon might not be totally up to scratch in either dialect). But after having worked in a support role in both French and English, acting as a translation pipe between our American engineers and our French/Belgian/Swiss customers, the limits of my ability became quite apparent in the highly specialized world of I.T. and business. Process jargon and turns of phrase, managerial talk, technical speak, and the oh-so-French habit of turning one’s nose up at loanwords in preference of natively French terminology make for some jarring live translation, and lengthy deliberations on how to word emails.

So whilst I am very much at home talking in French, doing business in French, and even doing some creative writing in the langue de Molière (and you wouldn’t know I wasn’t 100% French, if that even means anything in this context), I could not allow myself to claim the ability to translate from English to French at a professional level. French to English however – fine. I would even tackle poetry translation in that direction.

Which raises another point – it is not sufficient for a person to speak a language to claim mastery over it. I know of many, many English-speaking persons who couldn’t paraphrase an idea in their own language properly, let alone express themselves in another language (it is also said that proficient foreign students of a language often fare better grammatically than the native speakers, but I digress). Ultimately then, it really doesn’t matter how “native” a language is to the translator. What really matters is how much time they’ve spent trying to use it properly and variedly.

So if a good translation comes from a good translator; and a good translator has studied their languages diligently; and you do not need to start out as a native speaker to go on to study a language diligently; then it follows that you do not need to be a native speaker of a language in any sense to professionally do professional translations – quod erat demonstrandum, and I rest my case.

This gallery contains 4 photos.

Kara – by Quantic Dream Aside from the technological capabilities of the PS3 (Sony does it again – w00t), this video is very interesting from a more… philosophical standpoint. I’m what one would call a “fan” of Ghost in the Shell, a Japanese anime series, iconic in the world of robotics geeks and cybernetics nuts.

Read more