Plaintext
The magazine that gives back to the Free Software community
June 2014 114 PAGES
PYTHON RASPBERRY PI LILYPAD OF NEURAL
ASTRONOMY HARDWARE FASHION ENHANCEMENT!
Search the blackness Build a distress beacon for Embed blinkenlights
of space for comets when the zombies come in your cycling jacket
32+ PAGES OF TUTORIALS
LIBVIRT Manage virtual machines with Python
June 2014 £5.99 Printed in the UK
LXDE Upgrade your desktop from dowdy to dashing
GOOGLE APP SCRIPTING Share even more data with Google
OLDE CODE FIDEI DEFENSOR
TURING FREEDOM!
Programmer, code Inside the Free
breaker, genius Software Foundation Europe
WELCOME
Command and conquer
The June issue
Linux Voice is different.
Linux Voice is special.
Here’s why… GRAHAM MORRISON
A free software advocate
At the end of each financial and writer since the late
1
year we’ll give 50% of our 1990s, Graham is a lapsed
profits to a selection of KDE contributor and author
organisations that support free of the Meeq MIDI step
software, decided by a vote among sequencer.
our readers (that’s you).
I
t’s truly remarkable that despite an almost infinite expansion in
No later than nine months bandwidth and computing power since the 1970s, the humble
2
after first publication, we will command line has remained relevant, and perhaps, become
relicense all of our content under even more relevant. We were promised voice input and Minority
the Creative Commons CC-BY-SA Report-style gesture control, and in some technology that’s what
licence, so that old content can we’ve got. But whatever advancements have come along, whether
still be useful, and can live on even it’s the mouse or drag-and-drop, the direct and indivisible connection
after the magazine has come off between your words and the command prompt cannot beaten.
the shelves. Which is why there has never been a better time to take the
plunge. It’s not difficult, and you can experiment safely from a
We’re a small company, so new user account or a virtual machine without any worry of
3
we don’t have a board of wayward arguments deleting important files. Even when you
directors or a bunch of go back to your desktop, there’s something very empowering SUBSCRIBE
shareholders in the City of London
to keep happy. The only people
knowing that, if you needed to, you could drop back to a
prompt, regardless of your distro, hardware or connection, ON PAGE 64
that matter to us are the readers and perform almost any task. And there’s no other operating
(you again). system that gives you that kind of power.
Graham Morrison
THE LINUX VOICE TEAM Editor, Linux Voice
Editor Graham Morrison
graham@linuxvoice.com
Deputy editor Andrew Gregory
andrew@linuxvoice.com What’s hot in LV#003
Technical editor Ben Everard
ben@linuxvoice.com
Editor at large Mike Saunders
mike@linuxvoice.com
Games editor Liam Dawe
liam@linuxvoice.com
Creative director Stacey Black
stacey@linuxvoice.com
Malign puppetmaster Nick Veitch
nick@linuxvoice.com
Editorial contributors:
ANDREW GREGORY BEN EVERARD MIKE SAUNDERS
Mark Crutch, Juliet Kemp, John Lane,
Vincent Mealing, Simon Phipps, Attack ships off the Shoulder Even though it’s something I’ve Looking for a new Linux PC? We
Jonathan Roberts, of Orion! Well, almost. Discover written, I’m really pleased with went into real shops and asked
Mayank Sharma, Valentine Sinitsyn comets from the comfort of your my Arduino-based cycling jacket. them about Linux support. Their
Linux box p86 I’ve not had a crash yet! p80 responses were surprising p26
www.linuxvoice.com 3
CONTENTS
June LV003
We are all in the gutter, but some of us are searching for comets
18
SUBSCRIBE
ON PAGE 64
Master the
command line
Peek under the
surface of your
Linux box and reveal
the power within
38 REGULARS
06 News
Bitesize facts to lodge in our
receptive brains.
08 Distrohopper
What’s rolling off the Linux
production line this month?
Gaming
How one ordinary genius 10
Portal 2, The Dark Mod, Oil
Rush, Wasteland 2 and more.
came to develop the Speak your brains
single most important 12
Ideas, criticisms, suggestions
and book review confusion.
computer ever made. LV on tour
16
Brighton, Bristol, Manchester
and Munich get a visitation.
34 Open Cores
A hardware architecture that’s
open to hack about with.
44 Interview
Damian Conway – one of the
founding fathers of Perl.
58 Group test
Reach out and touch your
shiny new Linux desktops.
110 Masterclass
Get deep into Inkscape and
ImageMagick. Arty!
26
SHOPPING 42
FAQ Bad guys want 66 SYSADMIN 114 My Linux desktop
How to buy a Linux box to DDOS your server. Jon Roberts finds a Mr KDE Plasma tablet Aaron
Seigo shows us around.
on the high street. But why, and how? better filesystem.
4 www.linuxvoice.com
REVIEWS
TUTORIALS
78 80
50 Bitwig 1.0 In one bound, audio
production and editing on Linux
became a lot more interesting,
Customise the Make smart clothes and cheaper, and better. Win!
LXDE desktop with an Arduino Lilypad
Make your Raspberry Pi a lot Sew a wearable circuit into
prettier, by enhancing its default clothing to turn your clothing
desktop environment. into an electronic canvas.
86 90
52 Gnome 3.12 This ‘next
generation’ desktop came in
for a lot of criticism on its 3.0
release – has it improved?
53 Udoo Do you love playing with
your Raspberry Pi, but feel like
it’s lacking in grunt? If so, this
Hunt comets with Raspberry Pi: build an quad-core ARM device awaits.
Python and open data emergency beacon 54 Roundcube 1.0 If you think
webmail is all about selling your
Filter image data in the search Stay safe in the event of disaster details to advertisers, you could
for Thargoids comets, from the by broadcasting the theme from be in for a pleasant surprise.
comfort of your Linux machine. Star Wars from a lunch box.
94
104
Code 101 Genetic
algorithms: create
life with Python
Programming done backwards,
for people like Ben and NASA.
55 Pibrella In our day toys were
Control virtual machines Ruby: Why absolutely,
106
lumps of junk that taught only
with Python and libvirt positively, everything disappointment. The world has
got a lot better since then.
is an object
Dispense with the GUI for the
Get your head around object- Books Ada Lovelace, Nine
awesome power of virtual
56
Algorithms That Changed the
machines commanded by Python. oriented to the nth degree. Future, and the scribblings of
some chap called Everard.
www.linuxvoice.com 5
ANALYSIS
NEWSANALYSIS
The Linux Voice view on what’s going on in the world of Free Software.
Opinion
Birth of a party
Calm down Mr Farage: there’s some actual politics happening in Brussells!
Simon Phipps Germany, the party gained seats in various
is president of the elections. The movement spread, chaotic
Open Source Initiative
rabble though it often appeared, until this
and a board member
of the Open Rights year it became clear it was present
Group and of Open throughout Europe.
Source for America. Which brings us to here. This weekend,
the grassroots movement from all of Europe
assembled in Brussels for the next stage of
organisation. Some present were concerned
that the whole new thing was getting too
A
s society changes, so can European- much like the old thing it wanted to replace.
level politics. The formation of the But those few bit their lip and savoured the The European Pirate Party was founded in
European Pirate Party this weekend moment as a rabble of smart geeks (many March 2014, and should have a great future.
was thus an event of unique interest. an open source committer among them)
Responding to the emergence of the became the newest political party in Europe. European Elections and it’s clear that the
meshed society, geeks of all flavours European Pirate Party needs her elected.
realised there was no one speaking up for Bright beginnings And that name. It turns out that people
the reality they saw. Not all was shiny. The opening keynotes for with English as a second language have
The treatment of the Pirate Bay was the the event were frankly disappointing for an fewer problems with it, picking up the
catalyst. Instead of considering its existence outsider, with little sign of a coherent humour and Disneyesque romance. But the
as civil disobedience arising from market intellectual framework being propounded by negative implications, both from the real
failure, politicians sided with the legacy the speakers and no speech from Amelia meaning of the word “pirate” and its cynical
media intermediaries in treating it as Andersdotter, the clear leader of the party at misuse in connection with unauthorised
organised crime akin to drug dealing or this juncture. But there were flashes of copyright usage, tend to make it become a
currency counterfeiting. promising insight. Keynote speaker (and slur to many with English as a first language.
The result was outrage, at least in the later Plenary chair) Julia Rede said “I want a This doesn’t have to be a problem though.
more socially coherent communities of Europe more like the internet -- connected, It’s a word true to the origins of the
Scandinavia and Germany. Political parties collaborative and a community of peers.” movement, and there is a historic precedent
formed almost spontaneously in those This is a visionary statement, which could for adopting the slurs of one’s detractors as
countries, dedicated to bringing about a just provide a prototype for a policy framework. a name. The Tories did it (the term originally
society for the digital age. The smirks of Rede also recognised that a Pirate Party meaning a mugger); before them the Whigs
derision of the incumbent politicians in needs to be more than just a movement did it; even Christianity did it. With time, the
those countries faded as they discovered comprising Linux sysadmins, as well as name Pirate Party will become a strength
this was not just a protest movement but tackling current issues like the Transatlantic rather than a weakness.
was electorally viable. In 2009 Christian Trade and Investment Partnership (TTIP): This is not a political movement funded
Engström was elected representing Sweden “The greatest fear of TTIP is that it will raise from the deep pockets of corporations or
in the European Parliament, as was the corporations to the same status as states”. unions. There was no expensive partying, no
brilliant Amelia Andersdotter. Then in She is a candidate in the upcoming glitz or glamour, no side meetings funded by
sponsors, no exhibition to gain fees. But
there was broad attendance from across
“The Pirate Party needs to be more than just a Europe by party members and supporters of
movement comprising Linux sysadmins.” all ages. The Pirate Party is a voice we all
need in Europe. Welcome!
6 www.linuxvoice.com
ANALYSIS
CATCHUP Summarised: the eight biggest news
stories from the last month
Windows XP EOL pushing Quake III ported to the QR codes considered for
1 companies to try Linux 2 Raspberry Pi 3 kernel crash messages
It’s official: Windows XP Hang on – Quake III came Kernel panic text isn’t useful
is dead. The OS had an incredibly out in 1999. So that’s hardly impressive, to many people, but if non-technical
long life, but even Microsoft got sick eh? Well, it is when it’s part of a users could send a QR code containing
of supporting it. However, with an $10,000 bounty. In February, Broadcom the information to the relevant
estimated 70% of businesses still announced a wealth of documentation developers, that could help everyone.
running at least one XP machine, what for the graphics chip in the Pi, and
can they do? Buy new hardware and provided a driver for a similar chip.
upgrade to the UI nightmare that is Then the Raspberry Pi foundation
Windows 8? Or switch to Linux? Well, offered $10,000 to the first person to
various surveys are suggesting that port the driver to the Pi’s own GPU and
between 10 and 30% of businesses show Quake III runnning silky-smooth
are now considering moving to Linux. on it. Long-time Pi hacker Simon Hall
That’s millions of new users coming… managed it, and bagged the loot.
GOG.com announces plan Major GnuTLS bug leaves Linus Torvalds refuses
4 to support Linux 5 “secure” websites open to 6 to accept any more code
Formerly known as Good eavesdropping from prominent hacker
Old Games, GOG.com is a rather It’s easy to become complacent as a Linus doesn’t mince his words,
spiffing site that sells (mainly older) Linux user, given the overall reliability especially when someone breaks his
games without DRM and other such and security of the operating system. beloved kernel. Kay Sievers, one of
horrible nonsense. The company has But vulnerabilities do happen, and the developers of systemd, managed
announced plans to support Linux in now a Red Hat researcher has found to bring Linus’s blood to a boil over a
the near future, focusing on Ubuntu and a problem with GnuTLS, a library that complication with the “debug” flag on
Mint, with 100 games in the pipeline. implements TLS and SSL support for the kernel command line. (As if systemd
There aren’t many other details right websites. The vulnerability affects weren’t controversial enough…) “I will
now, but for some gamers, it will be one certificate verification, potentially not be merging any code from Kay into
fewer reason to reboot into Windows. showing unsecure, spied-on the kernel” until fixes are made, said
Read the full announcement here: connections as secure. Distros are Linus. Check out the the full email:
http://tinyurl.com/kcdozjz scrambling to push out fixed packages. http://tinyurl.com/linusrage
Microsoft Office released $2,400 ‘Introduction to
7 for Linux – well, Android 8 Linux’ course made free
But Android is a flavour This is jolly generous of The
of Linux, right? It was an unusually Linux Foundation. Its ‘Introduction
cold day in Hell when Microsoft to Linux’ course, previously available
announced this, but yes, you can now for a wallet-bursting $2,400, will soon
get mini versions of Word, Excel and be freely available for everyone. The
PowerPoint for your Android device. Foundation plans to release it as part
The reviews so far aren’t very positive, of a MOOC (Massively Open Online
with users complaining of problems Course), so if you’re fairly new to Linux
opening desktop Office files. Which is and still trying to fathom your way
especially ironic, as Microsoft always around the operating system, it could
championed its supposed cross-app help you enormously. Here’s the full text
and platform file compatibility. Anyway, of the announcement:
the suite is also available for iOS. http://tinyurl.com/lskhx8u
www.linuxvoice.com 7
DISTROHOPPER
DISTROHOPPER
We’ve tapped GCHQ’s communications to find out what’s going on in distro land.
Porteus
Lightning-fast live Linux.
P
orteus is a distribution designed for
running directly off a USB stick. Big
deal – almost every distribution can
do that these days, so you may wonder if
there’s still room for a distro like Porteus.
However, there’s plenty that’s unusual
about it. Porteus doesn’t have a download
link like you may expect, but a build service
where you can customise your own version
of Porteus. You can select things like the
desktop environment, the web browser
and word processor, and in the Advanced
options you can set things like the system
passwords and boot behaviour.
The second unusual thing about Porteus
is how quickly it boots. On our test system,
Porteus Mate got from Grub to the desktop
in under 10 seconds, and this was in a Porteus Kiosk has a bounty scheme where you can donate money towards certain features.
virtual machine. The VM was allocated two
cores of the i7 processor, but to put it into distro, it took just 15 seconds. On the down targeted very firmly at people who want
context, OpenSuse took just over a minute. side there is quite a limited choice for the a minimal live distro. Of course, this isn’t
This speed is incredible for a live distro. We applications you can install, and there’s really a problem, because there are loads of
ran the test again with the KDE version of little else other than those you select in the alternative options for people who want a
Porteus, and even with the heavyweight build system. This means that Porteus is heavyweight live desktop.
Kali 1.0.6
Hindu Goddess and pen-tester’s best friend.
K
ali Linux is undoubtedly the premiere and outputs the help from that command.
penetration testing Linux distro. It’s It’s a nice way of doing things that combines
packed full of all manner of the power of the command line with the
security-focused software, such as the discoverability of a graphical system, and is
Metasploit Framework. It’s also got a lot of a trick that quite a few other distros would
software that is not usually thought of as do well to learn.
security focused, but has its place in the In addition to 32- and 64-bit PCs, there If you’re not a security expert, browsing the Kali
hacker’s arsenal, such as the Arduino IDE. are builds available for Amazon Machine menu can be an eye-opening experience.
Much of the security software is Images (AMI), Google’s Compute Engine,
command line-based, but the developers and nine different ARM systems (including designed to make it look edgy. The stylised
have still included it in the applications menu the Raspberry Pi). dragon on the desktop seems to be there to
to make it easy to find. When you click on Finally, we can’t help but wonder if the remind you that the software running is the
the menu item, it opens a terminal window artwork in Kali has been deliberately digital equivalent of a private ninja army.
8 www.linuxvoice.com
DISTROHOPPER
KWheezy
Can Debian look good with KDE?
W
e call this section Distrohopper,
and we talk about the different
distros we try out. However, what
really constitutes a Linux distribution as
opposed to a mere respin? It’s a complicated
question, and Kwheezy is a perfect example
of why. It’s based on Debian 7 (Wheezy) with
KDE. It does have its own repositories, but
these only hold a few pieces that aren’t in
mainline Debian.
However, it would be a mistake to think
that just because it’s not a standalone distro,
it doesn’t have any value. The Kwheezy
website describes it as ‘A well configured
Debian KDE installer’, and this is probably
the best way to think about it. Once it’s up
and running, what you have is just a Debian
system with the Kwheezy settings, but it can
be difficult to set up KDE well, so in terms of
effort, it’s actually much more than that. The KDE setting are much improved from the defaults, but the dreaded blue glow remains.
The download is 4GB, and so the distro is
bundled full of software. For instance, there in Debian (such as Firefox), and a small full power. Although Kwheezy isn’t fully to
are two full office suites (LibreOffice and collection of Kwheezy-specific tools for our tastes – there’s a bit too much Debian
Calligra). This would be annoying if you were changing settings such as the keyboard or pink for our tastes, and it doesn’t have the
installing it on a machine with limited hard applications started on bootup. best-looking KDE desktop – we welcome an
drive space, but as long as you know what There are, frankly, too many distros with effort to add a bit of glamour to this
you’re getting, choice is good. The extra KDE that just use the unattractive default powerful desktop. KDE is crying out for
software comprises a few things that aren’t settings of the desktop and don’t unleash its customisation, so bravo Kwheezy!
NixOS And now for something completely different
Nix is a package manager, and it’s the basis for about how to build a file, but don’t include the We Like NixOS, and wish the project well.
NixOS. Not many distros tout their package actual source files themselves (these can be However, at this stage, there are too few packages
manager as their best feature, but then there isn’t fetched from upstream sources as described in the available for us to recommend it for most users.
another package manager quite like Nix. It’s a little package file). Tinkerers looking for a new challenge who aren’t
hard to explain, so bear with us. As well as being able to install packages, Nix afraid of getting their hands a little dirty will find
Firstly, packages are written in a functional enables you to specify in a declarative language a NoxOS an intriguing project with lots of potential.
language that describes how to compile the state that you want. For example, you could state
software and where to download it. When you that you want an SSH server running and
install a package, it compiles it and places it in a accessible. The package manager would then
new directory in /nix. This directory is given a name download and compile everything as necessary, and
generated by a hash of all the inputs to the set this up.
compilation (including the source code and the There are a couple of useful effects of this. It’s
compiler options). very easy to deploy a custom version of NixOS with
New versions of packages don’t automatically specially configured packages across a number of
overwrite the older versions, so multiple versions machines. Although it’s yet to see wide-spread
can quite happily co-exist on the same system – so adoption, it definitely has potential as a cloud OS
too can multiple versions of the same package because of this. In fact, there are some tools to
compiled with different options. You can roll back make this easy.
changes that haven’t played out as expected, and To ease the load of compiling everything from
even choose to boot into different versions of the scratch, there’s a NixOS repository, which holds
OS from Grub. You can remove older versions to pre-compiled versions of particular software. When
save space, but it isn’t necessary, and can be done you go to install software, if there’s a pre-compiled
after the newer version has been thoroughly tested. version with the same options you want then the We like Nix – it’s a revolutionary package
Equally intriguing is the way that the package package manager will download that; otherwise, it manager, but is the world ready for a package
files for different versions detail all the information will compile the software from scratch. management revolution?
www.linuxvoice.com 9
GAMING ON LINUX
GAMING ON LINUX
The tastiest brain candy to relax those tired neurons
TENTACLES OF CTHULU
Portal 2
Prepare to return to the Aperture Science Labs.
L
ook out puzzle fans
– here comes a big What is left of the labs!
one! Valve, our new
benevolent gaming overlord,
has unleashed the Linux
beta version of its highly
praised sequel to Portal, and
Liam Dawe is our Games Editor and
the founder of gamingonlinux.com, appropriately named this
the home of Tux gaming on the web. beast Portal 2. It was originally
released in 2007, and Linux
S
teamOS, from Valve, is a Linux users now get to join in on
distribution aimed solely at the fun as Valve pushes more
gaming, with Valve’s own
games our way.
patches included to increase
performance of various systems Something important to Portal 2 is a first-person a co-op mode too, so you can
within the distribution. SteamOS was remember is the fact that it is puzzle game involving a solve puzzles with your friends
one of the major announcements that in beta, so there will be certain special gun that opens portals – we suggest playing the
Valve made in September 2013, bugs and issues you may between two places for you to single-player first.
alongside its own gaming controller
come across, but it is still well jump through and overcome http://store.steampowered.
(the Steam Controller), and also its
console-like Steam Machines. The worth a look. obstacles. This sequel includes com/app/620
distribution will be pre-installed on
Steam Machines, removing a barrier
to Linux adoption.
SteamOS has gained positive
feedback from quite a few big names
in the indie gaming scene, including
The Dark Mod
Markus “Notch” Persson, creator of Did you just see something move? Nah, just my imagination…
Minecraft, and DICE, the creator of
O
the Battlefield series of first person pen-source developers
shooters. But the really fantastic Peekaboo!
are at it again! The
thing about Valve pushing Linux so Oh wait, I’m
profusely is that it has led the leading Dark Mod has finally
supposed to
graphics card manufacturers (Nvidia released a stable version and
be stealthy!
and AMD) to improve their graphics it is simply fantastic. The Dark
driver performance. Mod is inspired by the Thief
Valve has recently open sourced
series of games and plays a
two internal projects, the first being
its Direct3D to OpenGL translation lot like the older games in the
layer, which could prove useful for series. It was originally a mod
other big name developers in saving for Doom 3, before it became a
time when porting to Linux. standalone game.
The second of these big projects is
The game is all about stealth:
the new OpenGL debugger named
“Vogl”, which should help developers you play a hooded ninja-like
boost performance and find figure who is on a mission
bottlenecks in their OpenGL hunting valuables. You have looks simply beautiful. It is The Dark Mod, as it doubles as
rendering. To put it simply, to be careful though – the easily one of the best-looking a friendly toolkit as well as a
performance of games for us Linux
swordsmen of the land don’t free and open-source games game, so be sure to share your
gamers in future should improve if
they use Vogl. Onwards and upwards! take too kindly to thieves. around at the moment. favourite packs with us on the
Liam Dawe, gamingonlinux.com The Dark Mod is set in a You can even create and Linux Voice forum.
Gothic steampunk city and download mission packs for www.thedarkmod.com/main
10 www.linuxvoice.com
GAMING ON LINUX
Wasteland 2 ALSO RELEASED…
Massive robo-scorpions and other nasties await you.
R
PG fans, get ready to be excited,
as Wasteland 2 – one of the
biggest crowdfunded projects
ever, having raised over $2.9m on
Kickstarter from 61,290 backers – is
making its way onto a computer near you.
Wasteland 2 is also the project that helped
to get a Linux export option in the Unity3D Paper Dungeons
game toolkit, so the developers do of Paper Dungeons is a brand-new mix of RPG,
course plan a Linux version as well as Rogue-like and a board game. It mixes dice
OS X and Windows versions. throwing into combat, and it’s a hard game to
Wasteland 2 is a post-apocalyptic master. It features 155 levels, three different
game-modes, five different classes and more
turn-based RPG game with beautiful content! It manages to keep things fresh with
graphics and solid-looking gameplay. We unlockable sets of dice and characters, and it
don’t have many good RPG games like it, also gives you the ability to create and
so it’s a welcome addition to our game download levels too.
library. It is a direct sequel to the 1988 www.desura.com/games/paper-dungeons
The original Wasteland was released in 1988,
game Wasteland, which also has a Linux and has since been re-released for Linux.
version now.
The Linux version of Wasteland 2 hasn’t buy it now and consider it a pre-order of
landed yet, but it is expected soon, as it sorts you will get a copy of Wasteland 1
has only recently become part of Steam’s for free, which is quite the classic.
Early Access program, although if you do http://wasteland.inxile-entertainment.com
Oil Rush OpenXcom
Prepare your tactical warfare skills for An open source engine for one of the
Stranded
You like pointing & clicking, right? Good.
when the oil runs out. greatest games ever made. Stranded has just been released, promising to
make you scratch your head while you wave
your mouse around.
It has a nice sci-fi setting where you have
wound up ‘Stranded’ on an unnamed planet
with nothing to guide you but your own will.
Join us in being confused – you know you
want to!
www.petermoorhead.com/stranded
I hope you don’t get sea-sick! Oil Rush OpenXcom is why we love open source. It
may have been out for a while, but it’s still has revived a true classic – UFO: Enemy
not the best-known game. It’s sad Unknown, a strategy game from another
because it’s actually quite brilliant. era in computing, originally released in
Oil Rush is a mix of a real-time strategy 1994 for DOS and Amiga.
and a tower defence game, set in a world You will need the game files from
ruined by nuclear war changing the planet somewhere like gog.com, but it will be well
forever. It was an early supporter of the worth the minor effort involved. Natural Selection 2
Linux platform, and when it came out it UFO: Enemy Unknown pits humans Dust off those graphics cards: Natural
was one of the most graphically intensive vs aliens in a mix between real-time Selection 2 is a seriously demanding hybrid of
games we had (it is still easily in the top strategy on a planetary view and turn- first person shooter and real time strategy
games that pits humans vs aliens.
10 in that respect). based tactical combat when you shoot
You can play as a traditional shooter or be a
There is no micro-management to be a UFO down. You will need to capture team commander, whereupon the game turns
had; you don’t even control the units and research the aliens while keeping the into a real time strategy in which you
directly during battle, so it’s easy to get world happy with funding you raise from command other members of your team.
into, but hard to master. the nations of the world. www.naturalselection2.com
http://oilrush-game.com http://openxcom.org
www.linuxvoice.com 11
MAIL
YOUR LETTERS
Got something to say? An idea for a new magazine feature?
Or a great discovery? Email us: letters@linuxvoice.com
LINUX VOICE STAR LETTER
MIGRATION HERO It is important to
check with the user as
requested, the only exception
being the odd printing issue but
I found it interesting an attempt to spread the to their expectations and once that’s resolved I get nothing.
listening to various podcast good word. I usually install requirements – Linux is not I ask them how’s it going only to
discussions regarding Mint (Cinnamon), Mint the best for syncing iTunes! be told that it’s all fine and how
installing Linux for other (Mate) or Xubuntu, all LTS I always put the programs much quicker it is now. It just
users of Windows and would versions, depending on the I think the user will use on does what they need. I get far
like to share my experiences. computer type, power of the desktop along with a more cries for help from Windows
I have installed Linux on machine and if there are any ReadMe file detailing the users than Linux ones.
behalf of about 12 users in installation difficulties. Linux equivalents of the My point is that should
Windows software, how to anybody be deciding whether or
find and install software, not to install Linux for a family
update the computer and member or friend and is worried
details of where and how that the user will need constant
to look for help should they support my experience indicates
need it. I like to run through the exact opposite, just make
the setup with them so that sure you do your homework first.
they know how to connect Charlie Ogier, Guernsey
to the internet etc, and this
gives them the opportunity Andrew says: As Roy Keane once
to ask any questions. said: “Failure to prepare is preparing
Once I have packed to fail.” You’re completely right to
them off home, I have been ask what your users want out of their
Linux Mint (in Cinnamon or Mate) makes a great desktop system for surprised by the total lack Linux boxes, and we salute you for
users who just want to do the basics with their computer. of support that has been your work.
I’M STICKING WITH YOU
I’ve just got a copy of Linux Charles Barnwel, Birmingham,
Voice issue 2. You are rightfully UK
receiving many plaudits for the
work you have done to set up this Andrew says: Like penicillin and
magazine, however, one thing WD-40, sometime the best things
seems to have been missed in the are discovered by accident. We can’t
congratulations – it is the glue. claim that Mike has been working on a
You have managed to get a glue secret formula for the perfect glue; it’s
that firmly holds the DVD to the just what we were given by default by
magazine, but when you take the our distributors. Things do seem to be
DVD off, the remnants of the glue working out well so far, but if anyone
roll off nicely leaving no residue at has feedback about the magazine or
all. This is a fantastic achievement, the physical quality of the magazine When there’s a great distro, we’ll put it on the DVD; when there
keep up the good work. please do get in touch. aren’t any big releases, we won’t bother with the DVD.
12 www.linuxvoice.com
MAIL
UNSOUND GEDIT
I am by no means a newbie since I I very much enjoyed the text editor
have been using Linux as my comparison in the May issue.
operating system of choice since However, I have an addition and an
2000, but sound always seems to objection.
be a problem. Banshee and other The objection first: take a look at
players work OK and hide the TextAdept. You are really missing
difficulties from you but if you ever a nice cross-platform editor. I
step outside the music player area use it on Linux and MacOS and I
it is a nightmare. Sound settings in always have the installer ready in
PulseAudio and ALSA are arcane. the event that I need to work on a
Despite this I thought I would try Some audio apps, such Windows machine. It’s open, free
Ubuntu Studio as a dual boot how to know which ‘device’ as Bitwig, are fantastic and completely extensible. What
option on my main PC. I assumed corresponds to which piece of – it’s the underlying more do you want?
that the good folks at Canonical hardware. sound architecture in The addition: I really like Gedit. In
would have everything set up just John Paton Linux that causes the fact, I used the text editor control
so… I started Audacity and tried problems. to learn Python. I got a nice clone
recording my voice. Selecting an Graham says: We have a lot of with additional features I missed.
input device proved to be the first sympathy for your situation, John. I was even thinking of embedding
problem. Audacity listed 26 input One of our audio devices is a the Evince viewer in order to
devices, and when I decided to Focusrite Saffire Pro 40, and this lists have a clone for TexWorks. It
Rescan Audio Devices the list of 20 separate inputs and 20 separate should not be that difficult, being
input devices increased to 36. I outputs, with no indication of which as there is a lot of code floating
have no idea which of these channel does what or goes where. The around. That could be an idea for a
options refer to the microphone I only solution is trial and error. Python programming tutorial that
plugged into the sound card. The reason for this is lack of produces useful tools along the
I can eliminate the USB options manufacturer support – many Linux road…
since I suspect that they refer to drivers are created blind by developers Pedro A Aranda, Madrid
my webcam and I could try each of trying their best to bring as wide
the other options till I find which hardware compatibility as possible. Ben says: Hi Pedro! We did include
one gets a response on the meter This is wonderful, but they often don’t one cross-platform application in the
but life is short, especially when even have access to the hardware shape of Sublime Text, which is a
you get to my advanced years. they’re writing drivers for. What’s superbly polished piece of software
And then I would have to do the needed, we think, is some way to and could easily have been declared
same with the output devices. create sensible default configurations the Group Test winner. As for Gedit,
I doubt if you can sort the for hardware. And perhaps that’s we like it too. We’re just spoiled for
problem but it would be nice to something we, as a community, could choice when it comes to text editors.
have some sort of guidance on help with.
www.linuxvoice.com 13
MAIL
PLAIN TEXT PASSWORDS
Congratulations on your second
issue; you seem to have the
contents about right for the
greatest number of readers.
I would just like to mention that,
although an excellent piece of
software in many respects, Filezilla
does have a potential security Security concern aside, FileZilla is a
problem for some users. The login fantastic FTP tool.
information that is entered into
the Site Manager is stored in an Ben says: For home users, as you
XML file in ~/.filezilla as plain text, say, this isn’t such a big deal, but it
including any passwords. Probably does serve as yet another reminder
not a problem for a home user, but not to use the same password on
something others may need to be multiple sites, because it only takes
aware of. one to leak and you’re compromised
Chris Whelan all over the place.
WHAT NAS BOX?
Having just read the article from putting a full-fledged distro like
issue 2 on “Filing Effective Bug Debian on it? In both cases, can’t
Reports,” I thought I’d comment the box be used for exactly the
on how you’re striking quite a nice same thing, network storage?
balance between newb-friendly Wouldn’t the difference just be in
content and more advanced stuff. setting up the Debian distro as a
The bug report article has probably file server?
assuaged many readers’ fears on Congratulations on the
the topic and it might have done magazine, and keep the great
many open source projects quite a content coming.
nice favour. Roy Birk, Maryland, USA
Speaking of newb-friendly
content, I have a question: Over Andrew says: Debian is an excellent
the couple of years that I’ve been OS for a NAS, and it’s even used by
messing around with Linux, I’ve some commercial products. NAS4Free
seen a few articles on NAS, often is based on FreeBSD, so it’s the
on FreeBSD and how to set up an best way to get the advanced ZFS
NAS device. For me, this begs that filesystem. You can’t go wrong with
question, what is the difference either – just make sure to uninstall
between using, say, a 2TB box any services you’re not using, as each
and putting NAS4Free on it, vice one is a potential vulnerability.
Debian running
without a graphical
server is a perfect
choice for a
netword attached
storage (NAS) box.
14
MAIL
MANY IDEAS PAST AGES
You have mentioned in both For the first time in my life I am
magazines about running linux on writing to a magazine, which is
MAC. Just wondering if you will mind blowing considering I’ve
throw a tutorial in for installing been collecting various mags
Linux on the late 2013 macbook since the late 80s when my
pro(11,1) in an upcoming issue? parents opted to give me pocket
I’d really like to get Linux up and money. While my friends bought
running on my new laptop and use sweets I saved mine and bought
it as my main OS. Any help would Metal Hammer Magazine or some
be greatly appreciated. other publication in that vein. but
Brian Meyers as I plod my way through my 30s
I’ve started collecting magazines
Andrew says: I’m a big fan of the once more. I literally started buying
construction quality of Apple them again last month with Linux
Ah, the Debian flying
hardware, in particularly the battery Voice as previously I just used the involved in creating the distro. It
pig. A joke devised by
life of the laptops. Linus Torvalds internet for all my needs from the could be a real community project our esteemed Mr Nick
uses a Macbook running Fedora, Mike mid 2000s to now. and the timing is good with the Veitch, who now dwells
uses one running Xubuntu, and all the The last publication on Linux release of Ubuntu 14.04 imminent, on page 114.
geeks at OSCON seem to have a shiny I bought was Linux Format back so there’s a nice fresh LTS Distro to
Apple device running some sort of in September 2005. While I don’t fork from.
Linux. It would be remiss of us not to have that magazine I recently The tutorial could cover a lot of
try sone sort of dual-booting tutorial, found the DVD that came with it issues and really generate interest
so look out for it soon. in an old box of odds and sods among the Linux Voice reader
that I found at my parents’ place. base, as learning how to build an
I include a picture of the DVD OS from nothing is something I’m
MORE IDEAS! cover for no real reason other than
nostalgia. In short your magazine
sure everyone would like to know
how to do.I’m sure you would also
It’s amazing to look at the is so good it has rekindled my see a jump in users on the forums.
historical code tutorials and interest in Linux and got me Think about it. How cool would it
understand exactly what’s going buying magazines again. be to put your own distro out on a
on. But after Ada Lovelace in I had an idea for a long-term future DVD release and also to see
LV001, Grace Hopper in LV002: tutorial that could be covered from it on Distrowatch.com?
who’s next? issue to issue where you detail Well I hope you take the time to
Brian Meyers the building of a Linux distribution, read this and would love if you ran
using Linux From Scratch. Each with my idea and did it.
Andrew says: Alan Turing’s next, month you dedicate a few pages PJ
that’s who, but as the Bletchley Park (maybe 10 or so) to building the
stuff isn’t all that hands-on we’ve Linux Voice Distro (or whatever Ben says: That’s an awesome idea,
moved him into the features section you want to call it). This could thanks PJ. We’ll think of you when
this issue; he’ll be reinstated to the be really cool as a tutorial for we’ve taken over the world and we’re
tutorials when Juliet gets onto the everyone and get a lot of people drinking fresh mango juice.
work he did around prime numbers.
There’s also Von Neumann and Konrad
ILLITERACY
Zuse in the pipeline, so stay tuned.
For a review of the
worst book in the world
Issue 2 is great. But oh no –
ever, turn to page 56.
there’s a gaffe on page 27!
The author of A Computer
Called LEO is Georgina Ferry
However, on the front cover, at
the bottom, there’s a quote by a
Brenda Maddox. Keep Ben off of
the cider this month! I shall not
If you’ve ever dabbled in Assembly
language, Ada Lovelace’s code for be cancelling my subscription
the Analytical Engine should look however as I consider it money
familiar – even though she wrote it in well spent!
the 1840s. John Evans
www.linuxvoice.com 15
LUGS ON TOUR
LUGS ON TOUR
FLOSSUK Spring Conference
Josette Garcia likes to be beside the seaside; specifically, Brighton.
I
n 1783, the Prince Regent, from configuration management
played by Hugh Laurie in and automation, security,
Blackadder, (later King George performance improvements, as well
IV) made his first visit. He then as updates on the development of
spent much of his leisure time in key free software projects.
the town and constructed the Royal The opening keynote was
Pavilion during the early part of delivered by Paul Downey from
his Regency. Government Digital Services –
So what’s a bunch of Unix “Make things open, it makes them
System administrators doing in better”. I feel this philosophy is not
Brighton? They did not come for the only for techies but is applicable to
German sausage – they came to plenty of other situations.
learn, network and find out different Kris Buytaert presented two talks:
ways to improve their workload. ‘Building and Deploying MediaSalsa’
Dammit Blackadder,
It seems they are always looking and ‘Continuous Delivery of your the dinner, which was held at Why is it that no matter
out for more automation that will Infrastructure’. The premise of this the Alfresco Bar and Restaurant how many millions of
reduce human error. was that software developers are on the seafront. After-dinner pairs of socks I buy, I
adopting continuous delivery for entertainment was provided by never seem to have any?
Tutorials and talks their software, and infrastructure the LHS Bikeshed, members of
The conference started with a day people can do the same. the London Hackspace. The LHS
of tutorials, covering LDAP for Linux Other subjects covered Bikeshed is an interactive sci-fi
Admins, Ansible, Learning Perl included the latest news from the space shuttle simulator – not for
Together, and Caching and tuning PostgreSQL database project, a the faint hearted! You can find out
fun for high scalability.There was look at some of the new projects more on lhsbished.tumblr.com.
also a full-day Google Workshop – going on in Perl and the wonderfully Watch out for the videos on
Large-Scale System Design. named ‘Incident Response or http://flossuk.org. The next
The wide selection of talks When you find that you’ve lost your FlossUK Spring Conference will be
(covering three tracks over the paddle and you are up the creek’. held in March 2015 in York, which I
two-day conference) covered topics No conference can be without am told is a wonderful city!
Open-Source-Treffen
Mike Saunders strapped on his Lederhosen for a meetup in Munich.
S
trictly speaking, the Open- welcome. Although most of the general technological advances to
Source-Treffen isn’t a LUG, regulars have been using Linux and come – eg more powerful hardware
as it covers much more than Free Software for many years, we and better cryptography – and
just Linux. But like any good LUG, it had a good chinwag with some toe- then focused on medical and social
meets up regularly (the last Friday dipping experimenters who were issues, such as artificial organs and
of each month), everyone brings there to see how open source could implants to track people.
laptops to do some impromptu benefit them. Although most of the discussion
hacking, and there’s plenty of beer In March’s meetup, Maximilian was in German, everyone was well-
to go round. It’s an informal event Batz gave a great presentation (in versed in English too. So if you’re
held in a cafe near Munich’s main German) about “the outlook for ever in that neck of the woods and
train station – just a few minutes’ development of computers and fancy some FOSS banter, pop by:
walk away – and newbies are users”. It started off looking at www.opensourcetreffen.de.
16 www.linuxvoice.com
LUGS NEWS
Digimakers Bristol
Ben Everard goes to Bristol’s four-times-a-year children’s geek-fest.
E
very three months, shrimping, Sonic Pi… the list goes
Digimakers comes to on and on. As well as teaching
@Bristol (the awkwardly sessions, there are a few stands
named science exhibition centre). showing off some of the latest
It’s a day of geeky fun for all the tech. The MagPi team are usually
family (actually, it’s designed for present (and usually have sweets),
children and teenagers, but in our and earlier in the year, you could try
experience, the adults enjoy it just out an Oculus Rift. Recent events
as much). The basic premise is have proved popular with local
simple: the University of Bristol teachers as well who have been
takes over a floor of the @Bristol keen to brush up on the latest skills.
centre and invites local techies to
run sessions to help kids with tech. Get involved!
It’s not exclusively Linux focused, The next event is on 14 June 2014
but there’s a strong Raspberry Pi (unfortunately, Linux Voice won’t be
focus to many of the events. attending this one). Keep up to date
For the past two Digimakers, with what’s happening on their
Linux Voice’s Ben Everard has run Facebook page (www.facebook.
sessions first on the Raspberry com/digimakersbristol). You have
Pi camera module, and secondly to keep an eye on this, as spaces
on Scratch programming. There’s in the sessions are limited and
a very hands-on approach, with require attendees to sign up
sessions on Arduino robotics, beforehand. They usually fill Ben taught ‘Interactive cartoons with Scratch’ at the March
making Lego Mindstorms dance, up a few days before the event. Digimakers to 54 fledgling Linux users.
Manchester Raspberry Jam
Jack Kelly reports on a rapidly growing success story.
T
his month’s Manchester As always, we continue to be
Raspberry Jam was a astounded by the projects that
little different from the attendees bring to our Jams, as
norm. Thanks to the University well as their willingness to share
of Manchester’s School of and help others. As an event
Computer Science – where I am an organised primarily by myself, it’s
undergraduate student – we traded great to see people so enthusiastic
our usual chaotic assembly for a about introducing people to the
lab fully set up for 70 Raspberry Pi’s Raspberry Pi.
and a lecture hall for talks. The challenge we face running
We had our usual hack session; the Jam from here is adapting to
People of all ages gathered to make a changing range of attendants.
and share their creations in Scratch, While the Manchester Jam started
Python and even Minecraft. We had as a simple user group, where There must be something in the water in the North West of
Simon Walters showing off another enthusiasts could share their England – it’s a hive of hacker activity.
set of new Scratch-powered robots, projects and ideas, more and
and Simon Duffy demonstrated more attendees turn up at Jams gets the absolute most they can
various methods of home network with intrigue alone – having never out of their Pi.
hacking with Pi’s. Pete Lomas from owned or even used a Pi before, Anybody and everybody is
the Pi Foundation also attended, wondering what all the fuss is welcome to a Raspberry Jam. If
giving talks about the design of about – and we’re still figuring out you’re interested in attending, our
the Pi and the objectives of the how to deal with that in the best Jam runs monthly throughout the
Foundation, as well as answering way. But we look forward to the year. To see when our next Jam will
questions from the event’s challenge; our goal is to make sure be held visit mcrraspjam.org.uk or
attendees. everybody who attends the Jam follow @McrRaspJam on Twitter.
www.linuxvoice.com 17
FEATURE THE COMMAND LINE
If you haven’t mastered the command line, you’re missing
out on the most powerful features of Linux. Mike Saunders
has tips galore for both newbies and old-timers...
“The command line can do certain jobs
much more efficiently than GUI apps.”
Y
ou know how in films, when they want to that that’s nonsense, and the command line
portray a computer genius/nerd/hacker at interface has its benefits. But have you really
work, they always show someone tapping delved deeply into it? Have you discovered all its
incomprehensible gobbledygook into a command hidden tricks? And have you been able to ditch
line? Sometimes it’ll be a green-on-black text the mouse and start working more quickly? Over
terminal from the 1980s, accompanied by various the next seven pages we’ll show you how the
beeping noises, just to add to the mystique. And command line interface (CLI) can do certain jobs
thanks to stereotypes like these, many non- much more efficiently than GUI applications,
technical people assume that the command making your day-to-day Linux life smarter, easier
line is a weird and arcane tool, only to be used if and faster. Even if you’ve been using the CLI for
there’s no pointy-clicky GUI goodness at hand. a while, you’ll find plenty of new gems in here, so
Now, as a Linux user, you already know let’s get started.
18 www.linuxvoice.com
THE COMMAND LINE FEATURE
Better file management
GUI file managers are clunky and slow. Here’s how to work at light speed.
D
olphin, Nautilus, Thunar and co.
are OK for simple drag-and-drop
jobs, but in all honesty they don’t
compare to the CLI. As soon as you need
to do something complicated, you end
up with a horribly long workflow involving
countless mouse clicks until your wrists get
overloaded with RSI.
Let’s take a complex job and see how
it can be made simpler with some CLI
magic. Even though you might not need this
specific command on a day-to-day basis,
you can break out the component parts and
use them on your Linux travels in future,
saving you heaps of time. So: imagine
that you have a bunch of files without any
extensions, and you don’t know what’s
inside them. (You can see hundreds of these
in Firefox’s cache, for example.) They look
like this:
3F7DFd01
E64C7d01 Using pipes and multiple commands, you can narrow down to just the filenames you need, all
C42F9d01 without hundreds of tedious mouse clicks.
F0887d01
... lines like this: it, you can see how powerful the CLI is for
Let’s say you want to open the 10 biggest CBD2Fd01: JPEG image data, JFIF standard 1.01 working with files. (For instance, you could
JPEG files in Gimp to have a look at them. D0488m01: raw G3 data, byte-padded replace xargs gimp with xargs rm to delete
Think about how you’d do that in your DB54Ad01: gzip compressed data, max compression those 10 biggest JPEG files.) Try adding
graphical file manager – if it’s even possible. We only want JPEG files, so we take the your own components to the command, and
Providing that your file manager can peek output from the file * command via a pipe making new ones using parts of it.
inside the contents of files to determine their (|), then grep to just retrieve lines containing
format, you might be able to click around JPEG. After this point we don’t need any
Essential tips
and somehow sort the list by file format and information other than the filename, so
size simultaneously (very few file managers we pipe the text to sed, the stream editor, If you’re new to the command line, here are
some things you absolutely need to know. In
can do that), and then click and drag to which does a replacement. It takes a colon
most Linux distros, the CLI is accessible in your
select the top 10, and right-click on the : followed by any sequence of characters desktop’s program menu as Terminal, XTerm or
selection to open them in a program, then (.*) and replaces it with nothing (// – ie Konsole.
click down the list to find Gimp… Ugh. nothing between the slashes). So it gets rid ls/cd/rm/mv The most common commands
Now check this command out: of everything but the filenames. (list files, change directory, remove file and
move/rename file). Each command has a
file * | grep JPEG | sed s/:.*// | xargs ls -S | head -n10 Then, using xargs ls, we bundle together
manual page (eg man ls – hit Q to quit the
| xargs gimp all the filenames we’ve got so far and list viewer). Many commands have extra options;
It’s a beast, isn’t it? But actually, it’s them, sorting by size (-S). The head part for example, ls -la lists all files, including
a bunch of smaller commands linked retrieves the top 10 items of the list, and hidden ones, with details.
together, done in such as way that you can then using xargs again, we bundle up all the Tab Hit the Tab key to automatically complete
a filename or directory. If you want to delete
understand what each part does. filenames into a single string and tell Gimp
foobarlongfile.txt, for instance, enter rm foo
First, the file * part looks at every file in the to open them. and hit Tab, and it should be completed.
current directory, and works out the filetype It might take a few re-reads to really grok History Use the up and down cursor keys to
from the bytes contained inside. So you get all this, but once you have your head around navigate through previous commands. You
can edit them as well.
~ Your home directory (eg /home/bob/)
“Once you have your head around it, you can see > and >> sends output of a command to a file,
overwriting (>) or appending (>>). Eg ls -l >
how powerful the CLI is for working with files.” list.txt.
www.linuxvoice.com 19
FEATURE THE COMMAND LINE
Better editing
Learning a good text editor on the command line is essential.
W
e can’t stress enough how
important it is to learn a good
text editor. It really makes a vast
difference to how you work – even if you’re
not a programmer. Some GUI text editors
are well-specced with plenty of features, but
when you’re working with plain text, why
should you keep moving your hands away
from the keyboard to grab the mouse?
The two most notable text editors are
Emacs and Vim. They both have their
strengths and weaknesses, but we’ll focus
on the latter here because it’s installed in
nigh-on every Linux distro by default.
This isn’t a guide to the basics – we did
that in issue 1. If you don’t have that issue
and you’ve never used Vim before, see the
“Micro guide” box and then do the vimtutor.
Here we’ll explain why it’s well worth
learning, and if you’re a regular Vim user,
we’ll show you some tricks that you might
not have come across. A well-tuned ~/.vimrc file makes Vim more attractive, informative and welcoming.
How to love Vim Vim’s commands look weird and cryptic, but some programming, and want to find a
Many people try Vim and come away when you piece them together they make matching bracket or brace? Move the cursor
frustrated, because they don’t spend time more sense. For instance, in Vim-speak d is over the bracket and hit %. Want to quickly
getting into the right mindset. Some people delete, a means around an object, and P go back to the last place you entered text?
use it often but never learn to enjoy it. That’s refers to a paragraph. Hit dap and voila: Use gi.
fair enough – it’s not a very welcoming delete text around a paragraph (that is, text Earlier we mentioned using dap to delete
program. But bear these in mind and you’ll inside the paragraph and trailing spaces). a whole paragraph. This is an example of
learn to love it: It’s also worth customising the .vimrc file using a text object, and this is where Vim is
Always switch back command mode in your home directory to make the editor a ridiculously powerful. For instance, das
(with Esc) straight after editing. Make bit friendlier. Here’s what we have: deletes a sentence, while ci” (C-I-double
command mode your default mode. Vim is a set number ruler laststatus=2 hlsearch ignorecase quotes) changes text inside a pair of double
modal editor, which means sometimes title quotes. Say you have this text:
you’re editing text, and sometimes you’re syntax on <img src=”foo/bar/baz.jpg” />
giving commands. You should only be in This adds: line numbering; a ruler showing To change the filename: move the cursor
insert mode when you’re editing text, so the current line number; a status line with the anywhere inside the quotes, and hit ci”. Vim
always hit Esc as soon as you’re done. You’ll filename; highlighted searches; case- will remove all text inside the quotes and
learn commands better this way, instead of insensitive searches; more information in the place you in insert mode, so you can type in
accidentally adding them to your text. terminal window title; and syntax highlighting some new text and hit Esc when you’re
Use the H, J, K and L keys to navigate. for various programming languages. done. And this opens up possibilities for the
These are on the home row, ie under your equally awesome . (dot) command.
fingers, so you don’t have to move your Advanced Vim tricks Basically, . repeats the last text editing action
hands down to the cursor keys. They really Vim is chock-full of keyboard shortcuts and – both the command(s) you used in Vim
help you work faster – although it might commands that make life easier. Want to and the text you typed. So if you move the
take a few days to get used to them. search for the next instance of the word cursor into another <img src… line, between
Treat commands as a language. At first, under the cursor? Hit * (asterisk). Doing the quotes, and hit . then the text will be
replaced again, exactly like the first time.
This is tremendously useful if you need to
“Vim is chock-full of keyboard shortcuts and do a lot of quick replacements: do the
commands that make life easier.” command once, then jump around to other
places and tap . where necessary. Because .
20 www.linuxvoice.com
THE COMMAND LINE FEATURE
includes a whole text action, it can even be
used to repeat editing operations with New to Vim? Here’s a micro guide
backspaces inside. Enter vim newfile.txt to edit a new file. Hit I and and press Shift+G to go to that line. Hit Ctrl+G
Imagine you have some function you’ll see -- INSERT -- at the bottom, which means to view the current line number and U to undo an
prototypes copied from a header file: you’re in the Vim mode for adding text. Type in a operation.
int foo(int a, int b); few lines. When you’re done, hit Esc to return to To save, make sure you’re in command mode
void bar(char *d); command mode. (hit Esc to be sure) and type :W. To quit, use :Q.
Use the H/J/K/L keys to move around. Hit X To quit without saving, :Q!. Those are the basics –
void baz(int a, bool d);
to delete a character under the cursor and DD now enter vimtutor and follow the more detailed
Now you want to implement the functions to delete a line. Use 0 (zero) to go to the start of guide, which will take about 20 minutes. Then
themselves. Go to the first line (int foo) and a line, and $ to jump to the end. Type a number you’ll be ready to use the tips here.
tap A (capital) to append text onto the end of
the line. Hit Backspace to remove the
semi-colon, Enter (for a newline), {, Enter
again, }, and Enter once more. Then hit Esc
to get back to command mode. Now the
first line has changed into this:
int foo(int a, int b)
{
}
So, we’ve converted a prototype into a
proper function. Now move the cursor to the
second prototype line (void bar), hit . and
voilà, it is also converted, using the exact
same editing action as before. You can then
hit . again to convert the third line. It’s a
massive time saver.
Globalisation
Another hugely powerful (and not well
known) command is :g – the global
command. Take this for instance: Although the Vimtutor doesn’t make you an expert in Vim, it gets you well-versed with the
:g/someword/m0 basics of this powerful, flexible text editor (and its many offshoots).
This takes all lines containing the word
someword and moves them to line zero, ie
the top of the file. Or you could use :g/ (command) mode, and then executes the :g/DEBUG/norm 0i#
someword/d to delete all lines containing commands as written. For instance, say you Here, for each line containing DEBUG, Vim
someword. have some Python code and you want to executes 0i# – that is, go to the start of the
An especially useful add-on option for :g is comment out all lines containing DEBUG by line, switch to insert mode, and add a hash.
norm, which puts Vim into normal putting hash marks at the start: How cool is that? And then you can even
add Esc keystrokes when entering a :g
command by tapping Ctrl+V and then Esc.
Vim learning curve
Save time and energy
Imagine you want to add C-like comments
to DEBUG lines, so that:
climbing up
printf(“DEBUG: Blah blah”);
becomes:
/* printf(“DEBUG: Blah blah”); */
sliding down Use this:
:g/DEBUG/norm 0i/* ^[A */
(Again, use Ctrl+V followed by Esc to input
the ^[ escape character here.) This goes to
the start of the line, inserts /* followed by a
space, then Escapes back out of insert
mode, goes to the end, and adds */.
Just like we said – ridiculously powerful.
And more fun than using dreaded regular
expressions. (PS: Turn to the inside back
Vim’s learning curve, jocularly depicted at http://tinyurl.com/nfbj3mv (“Why I use Vim” by Pascal cover of this very magazine for a great
Precht). There’s a huge amount to learn at the start, but it all makes sense with time. cheat-sheet for Vim commands!)
www.linuxvoice.com 21
FEATURE THE COMMAND LINE
Better image editing
Huh? The CLI is good at editing pictures? Surely you can’t be serious…
I
am serious, and don’t call me Shirley. version of the PNG file. Of course, when Along with file format conversions and
Yes, there are many cases where it’s you’re generating JPEGs you’ll often want to resizing, another common job is to crop an
easier and faster to edit images at the alter the quality: image – that is, only save a portion of the
command line, rather than doing them in convert -quality 90 image.png image.jpg original. This is fairly straightforward too:
pointy-click fashion via a graphical tool like Resizing is possible as well. The first convert -crop 250x100+20+40 image.png image.jpg
Gimp. This is especially true if you want to command here specifies a percentage of This takes a 250-pixel-wide and 100-pixel-
perform editing or processing operations the original size, while the second uses high chunk of the original picture, from 20
on multiple files at the same time – in other exact dimensions: pixels across and 40 pixels down, and saves
words, batch processing. convert -resize 75% image.png image.jpg it into image.jpg. For crop operations you
The suite of programs we’re using here is convert -resize 300x300 image.png image.jpg might not want to convert the file – instead,
ImageMagick, which you’ve probably heard you just want to overwrite the original.
of if you’ve been on the Linux scene for a Don’t be so square You can do this by changing the convert
while, because it has been in development Something interesting happens with the command to mogrify and omitting the
since the early 90s. ImageMagick is second command, and it’s to do with aspect destination file:
monumentally versatile and supports over ratios. If the source image isn’t a square, mogrify -crop 250x100+20+40 image.png
100 different file formats – so it will handle the resulting image will be 300 pixels wide Another useful option is rotate, which
nigh-on anything you throw at it. and however many pixels tall to match the takes the amount of degrees (clockwise):
The most commonly used tool in original aspect ratio. If you want to force the mogrify -rotate 90 image.png
ImageMagick is convert, which works like image to be 300 x 300 pixels and ignore the
this example command: aspect ratio, add blackslash-exclamation to Lightning fast batch jobs
convert image.png image.jpg the dimensions, like so: So far so good, but these commands aren’t
Pretty simple, right? This just makes a JPEG convert -resize 300x300\! image.png image.jpg much quicker than doing the same jobs in
a graphical editor. But! When we add some
command line scripting into the mix, it all
“Image Magick is monumentally versatile and becomes a lot more efficient. Say you have
supports over 100 different file formats.” 200 .png files in the current directory, and
you want to shrink them all to 50% of their
original sizes:
for f in *.png; do mogrify -resize 50% $f; done
Here we create a loop, saying that for
every file in the current directory that has
a .png extension, we perform a mogrify
operation on that file (the filename is
contained within the $f variable).
What about if you want to convert all
the PNGs to a different format? You could
do this:
for f in *.png; do convert $f $f.jpg; done
But the resulting filenames are a bit ugly
here – foo.png becomes foo.png.jpg, blah.
png becomes blah.png.jpg, and so forth.
However, using a command line trick called
parameter substitution, we can remove the
.png from the destination filenames:
for f in *.png; do convert $f ${f%.png}.jpg; done
Here, the ${f%.png}.jpg bit does the clever
work, removing .png and then adding .jpg
on to the filename stem. (You can also use
mogrify to convert images and replace their
extensions, but it’s worth knowing these
tricks for the future.)
So, with the convert tool and some
Convert, resize, flip, crop and add captions to hundreds of images in seconds, thanks to ImageMagick. command line scripting, you can do
22 www.linuxvoice.com
THE COMMAND LINE FEATURE
mogrify -blur 5x2 image.jpg
The first number here is the radius, while the
second is the sigma (the actual amount of
blurring). Try playing around with different
values. You may not think it, but you can
even turn pictures into charcoal drawings
with a single command:
mogrify -charcoal 5 image.jpg
Another tool included in ImageMagick is
montage, which creates a single image from
a bunch of images. It’s also useful for adding
captions onto images, like so:
montage -label “My caption” image.jpg -geometry
+0+0 -pointsize 30 newimage.jpg
This adds the words “My caption” in 30 point
font to the bottom of the picture, without
resizing the picture (hence the +0+0), and
writes out the result to newimage.jpg.
Command-line line drawing
One of ImageMagick’s most powerful
features is its set of drawing commands.
You can add all kinds of shapes to images
via the command line, which is also useful
when you’re doing batch processing jobs
and want to add labels or diagrams to
Use shellpic (https://github.com/larsjsol/shellpic) to view images in the terminal – handy if individual images. Take a look at this simple
you’re SSHed into a remote server and want a quick preview of an image file. example:
mogrify -fill white -stroke black -draw “rectangle
conversion, resizing and cropping jobs on mogrify tools have an option for this: 30,10 200,100” file.png
hundreds of images in a matter of seconds. mogrify -brightness-contrast 20x-30 image.jpg This creates a white rectangle with a
If you had to do all the alterations by hand, This improves the brightness of the 1-pixel black border, 200 pixels wide and 100
it’d take hours or even days. ImageMagick image by 20%, and reduces the contrast by pixels tall, and places it at 30 pixels across
has more cunning features though, so let’s 30%. Again, you could include this mogrify and 10 pixels down on file.png. Many other
take a closer look. command in a ‘for’ loop as discussed earlier, options are available for drawing circles,
If you’re working with batches of photos, to fix hundreds of images at once. polygons and Bézier curves – see the
you’ll often need to correct their brightness ImageMagick is packed full of filters, such full list at www.imagemagick.org/script/
and contrast settings. The convert and as blurring: command-line-options.php.
Better calculating
Doing calculations at the command line makes much more sense than clicking
loads of little buttons, over and over and over. With Qalc, part of the Qulculator
suite (which also includes GUI tools) you can do some very funky stuff. On
Debian/Ubuntu/Mint-based systems, grab the command line tool with sudo
apt-get install qalc. The program’s manual page is disappointingly small, and
there’s little else in the way of documentation, so the best way to learn it is via
examples. Like so: Qalc is part
qalc “((78*30)+(13*19))/2” of Qalculate,
Fair enough, that’s a normal calculation. But Qalc is capable of a lot more: a bigger suite
qalc “addDays(2014-06-18, 50)” of tools that
This asks Qalc to perform its internal addDays routine - you can guess what include fancy
that does. In our case, we tell it to add 50 days onto the 18th of June, and it GUI front-
spits out the result: ends.
addDays(“2014-06-18”, 50) = “2014-08-07”
When you first run Qalc it downloads exchange rate information from the
It’s especially useful for doing bandwidth calculations:
internet, so you can do:
qalc “10Gibyte / 300(Kibyte/second) to hours”
qalc “500 EUR to GBP”
This tells us how many hours it will take to download 10GB at 300k/sec. Qalc’s
The program also understands lots of other units and conversions:
data files are stored in the /usr/share/qalculate/ directory, so it’s well worth
qalc “1300 feet to metres” having a nosey in there to see what other units are supported. You can even do
qalc “70 mph to kmh” calculations with planets and atomic elements…
www.linuxvoice.com 23
FEATURE THE COMMAND LINE
Better email
“All mail clients suck. This one just sucks less.” This is the motto for Mutt…
G
iven that most emails are plain text,
you don’t lose much by switching
from a GUI to a CLI mail client. And
indeed you gain a lot more, especially if you
choose a client like Mutt. Like many of the
programs we’ve covered in this feature, Mutt
has been around for most of Linux’s history
– its first release was in 1995. And although
it might look old-fashioned and complicated,
in the right hands it’s a superb program, and
it’s available in almost every distribution’s
package repositories.
Before starting Mutt for the first time,
you’ll need to create a .muttrc file in your
home directory. This contains the program’s
settings, and an example for connecting to
an IMAP server (with SMTP for sending) is:
set spoolfile=”imaps://user:password@server.com/
Inbox”
set folder=”imaps://server.com/Inbox”
set smtp_url=”smtp://user:password@server.com:25” The Mutt email client makes decent use of colour in the terminal, and like everything in this
set ssl_starttls=yes venerable application, these colours are highly configurable.
set from=”name@domain.com”
set use_from=yes you’ll see keyboard shortcuts displayed at This tells Mutt to display only new
set record=”=Sent” the top of the screen. messages (~N) or messages less than 7
set postponed=”=Drafts” Interestingly, Mutt doesn’t include its own days old (~d<7d). The pipe (|) character is
Change user, server.com, name and domain. editor; instead, it uses one already installed used in the middle to create the “or” part.
com here to match your mail server settings. on your system. So if you reply to a mail (or To switch back to the full message list, hit L
If you access your mail via POP3, see the hit m in the message list to create a new and then type all. (Mutt’s documentation has
relevant section of the Mutt documentation mail), you’ll be thrown into Vim by default. a detailed list of all the options – see
at http://tinyurl.com/64j7tzp. But you can change the editor in your ~/. http://tinyurl.com/yzwbrur.)
Now enter mutt to start the program, and muttrc like so: Additionally, Mutt has excellent support
it’ll retrieve the headers for your emails. Right set editor=”nano” for macros – that is, pre-determined
away you can see that Mutt does a decent (Or you could change that to “emacs”, or sequences of actions. For instance, in the
job given the limits of text mode: it uses even “gedit” if you need some GUI love.) message composition view, after you’ve
colours and highlighting effectively, and even entered the text in your editor and Mutt is
displays threaded conversations via red Macho macros asking if you’re ready to send, you can hit the
arrow symbols. So Mutt is great: it’s lightning fast, looks A key to attach a file. Enter a filename, hit
To select a message, use the up and good, and has loads of keyboard shortcuts Enter, and the file will be attached. But you
down cursor keys (or J and K in proper Vi so you don’t have to mess around with the could create a macro for this in your .muttrc:
fashion) and then hit Enter. The mail mouse. But it has some brilliant advanced macro compose \cb ‘<attach-file>file.txt<enter>’
contents will be displayed – hit D to delete features too. Instead of using / to search, hit This means: in the compose view, if the
the mail, R to reply, and I to go back to the L and then type a word. This is the “limit” user hits Ctrl+B, the attach-file command
message list. Use / (forward slash) and command, and it narrows down the will be executed. The word file.txt is inserted
enter a word to search for a mail, and N to displayed messages to match your automatically, and a virtual Enter key is
repeat the search. In the main list view, specifications. You can set some very pressed. So Ctrl+B now does the whole
tapping Q quits the program and returns you specific limits: action at once – useful if you frequently
to the command line. And in most views, ~N|~d<7d attach the same file to a message.
This is just one example; Mutt supports
hundreds of functions that you can use in
“Mutt has loads of keyboard shortcuts, so you don’t your macros, and really speed up your
have to mess around with the mouse.” day-to-day work. See http://tinyurl.
com/677feer for the full list.
24 www.linuxvoice.com
THE COMMAND LINE FEATURE
Better administration
Keep tabs on your Linux boxes, wherever in the world they are.
I
t goes without saying that the command
line is the best way to administer a Linux
box. Sure, there are some decent GUI
tools, but if you’re working with mail, web or
database servers, chances are they don’t
have anything graphical installed and you’re
logged in via SSH. Or even on your desktop
Linux box, if X goes down you’ll need some
way to fix and monitor things.
Slurm (https://github.com/mattthias/
slurm) is a great little network bandwidth
monitor. Start it by providing the name of a
network interface, eg:
slurm -i eth1
If you don’t know the name of the network
interface(s) on your Linux box, enter ifconfig
for a list. Slurm displays textual information
about the current data send and receive
rates, along with the total number of
transmitted packets and megabytes. It also
shows a colourful graph of bandwidth using
ASCII characters – so if you’re administering
multiple machines, you can leave it running A sprinkling of ASCII art provides an at-a-glance overview of network activity in Slurm.
in an SSH session on one, and quickly check
it to see if it’s being maxed out. tried it, you’ll never go back to using plain old sudo pip install --upgrade asciinema
top again. (The package might have another name
Monitor machine activity After all of the command line goodness of than python-pip in other distros.) Now enter
Htop (http://htop.sf.net), meanwhile, is a the last seven pages, wouldn’t it be great if asciinema rec, do some work, and type exit
souped-up version of the top utility. Like top, you could record your favourite tricks and when you’re done. Asciinema will offer to
it displays information about currently share them with others? You could use automatically upload the recording of your
running processes, but with much more flair some screen recording software and upload session to its website, and provide you with
and interactivity. As the program is running, the results to YouTube, but a more elegant an URL you can then share with others. For
hit F4 to filter processes based on name solution is Asciinema (www.asciinema.org). instance, here’s a recording of us
– or hit F5 to switch to a tree view, so you You can get it on Debian/Ubuntu like so: demonstrating the mighty power of Figlet:
can see which processes were launched by sudo apt-get install python-pip http://asciinema.org/a/8746
other ones.
A series of bar charts at the top shows the
Better downloads
current usage of your RAM banks and CPU
cores, and you can hit F2 to configure The download dialogs included in web browsers It’s possible to limit download speeds, so adding
various settings in the program. Once you’ve are very limited, and although more featureful --max-download-limit=100K to the command line
standalone GUI alternatives exist, sometimes it’s will restrict Aria2 to using 100KB/second of your
best to go straight to the CLI. Aria2 is arguably bandwidth. And you can even tell it to give up if a
the best command line download manager in connection becomes too slow:
existence, supporting a gigantic range of features --lowest-speed-limit=10K
and options. For instance, say you want to grab an (So if the bandwidth drops to less than 10KB/
ISO image that’s hosted on two servers, and they’re sec, Aria2 quits.) Other useful options include
both rather slow: --on-download-complete=command, which
aria2c -s2 http://foo.com/blah.iso http://another. automatically performs a command after a file has
com/blah.iso been downloaded. There’s also the --on-download-
Here Aria2 downloads one half of the file from error argument, which is handy for dealing with
foo.com, and the other half from another.com, connection failures.
simultaneously, so you get the file much more See Aria2’s website at http://aria2.sf.net for
quickly than you would using a single connection the full documentation – it’s immensely powerful
to one server. when you include it in Bash scripts.
Htop is a process monitor like the standard ‘top’
command, but literally a jillion times better.
www.linuxvoice.com 25
BUYING A
LINUX
COMPUTER
Can you buy a Linux computer on the high street?
Ben Everard investigates.
F
ifteen years ago, buying a Linux computer was get any help there. The only major computer chain left
a challenge. Back then, few people had heard of in the UK is PC World, so we wandered in and started
it, and even fewer knew what installing it poking around at PCs until one of the sales staff
entailed. The web was approached us.
still in its youth, internet “Hello there, do you
shopping wasn’t as “We wandered into PC World and need any help?”
popular as it now is, poked around at PCs until one of “Yes, I was
Linux still came in boxed wondering if you had
sets and hardware the sales staff approached.” any machines that
support was patchy. ran Linux.”
There hasn’t been a single watershed moment, but “Oh, um, hang on, I’ll just go and ask someone.”
things have gradually improved. We went undercover At this point, the sales assistant (a young man in his
to find out how much things have changed. mid twenties) scampered off to the support area
Since the world isn’t yet fully digital, we started by where a group of similarly aged young men poked
visiting the local shopping complex to see if we could around at the innards of computers. A few minutes
26 www.linuxvoice.com
BUYING A LINUX COMPUTER FEATURE
later he came back with the information that we were
looking for.
“Any of these computers will run Linux, but you
might not get all of the features of the hardware on
some of them. The best thing to do is have a look
online to see which manufacturers have the best
Linux support, and go with that. You’ll also have to
install Linux yourself.”
“Is that difficult?”
“Very. I wouldn’t do it myself. In fact, there’s only one
person in the store I’d trust to do it.”
This was a bit of an overstatement. Installing a
modern distro shouldn’t be too much of a headache
as long as your hardware is supported, but the rest of
the information I’d received was pretty good.
Bare-bones option
“Is it possible to get one of these machines without
Windows? I don’t really want to pay for it if I’m not
going to use it.”
“We do bare-bones computers without operating
PC World in Gloucester. It’s
systems, but we don’t have them in store. They’re only PC World may be the last of the major PC retailers
not glamorous and they
on the website. I can show you…” in the UK, but it’s not the only place to get computer don’t sell Linux computers,
We went over to one of the Windows machines and parts. The next stop on my shopping trip was Maplin. but the staff there did offer
he pointed the web browser to the PC World website, This is an electronics retailer that sells everything some useful advice.
but there was a problem with the internet connection. from remote control cars to transistors, and it has
We continued chatting for a bit. been a major retailer of the Raspberry Pi. Maplin
“Do many people come in asking for Linux?” doesn’t sell assembled PCs, but it does have ‘bundles’,
“Not many, but a few do. We get a lot of people which include motherboard, processor, memory, hard
asking about alternative operating systems.” drive, etc. Essentially, a flat-packed computer. Perhaps
“What do they want?” they’ll guide us to a Linux desktop.
“Anything other than Windows 8.” Again, we waited to be approached.
“What do they get?” “Can I help you?”
“Windows 8. It’s the only option.” “Yes. I’m hoping to build a Linux computer, and I
We left it there, and went on our way. We looked up was wondering if you knew which components would
the bare bones PCs on the PC World website back in work best.”
the office. There are only four options listed, and of “Ah. Umm. I don’t actually know too much about
these, just one is available for sale (a low-end desktop Linux. Hmmm. Let’s go and ask the manager. He
for £209). Not particularly impressive since PC World knows a lot about most things”
has 50 Windows PCs. “This gentleman wants to build a Linux computer.
Do you know parts he should use?”
“All the parts we have should work under Linux, but
Second-hand computers the drivers for some of them might not be as good as
the Windows ones. It’s been a few years since I last
Unless you need cutting-edge performance, a second-hand
machine can also be a good choice. The majority of second- used Linux, so I don’t know what’s best. There’s loads
hand machines are old corporate laptops by HP, Dell or of advice on the internet. If you do a search, you
Lenovo. There are some great bargains to be had, especially should find some forums where people can give you
if battery life isn’t critical to you. better advice than I can.”
Perhaps the best thing is that these slightly older laptops
So far this was almost identical to our experience at
have been tried and tested with Linux for a few years, so it’s
easy to find out what’s compatible with Linux. A quick web PC World, though the chap in the shop did suggest
!
that we should be able to install Linux “easily enough”.
SALE
search should bring up what works and what doesn’t on a
particular make and model. It would be nice to have people more knowledgeable
Some companies sell refurbished computers with Linux about Linux in shops, but the advice they were giving
G
BUYIN
installed, and one of these that deserves a particular
was actually pretty good.
mention is gluglug.co.uk. It sells refurbished ThinkPad
UX
A LIN ER
laptops with Linux installed, but not only that, it flashes the
firmware with Libreboot, so the laptop has no proprietary Heading online
UT
COMP
software on it. It’s the first (and at the time of writing, only) Of course, fewer and fewer of us do our shopping in
computer vendor to earn the Free Software Foundation’s
!
real shops any more, so we decided to see what the
SALE
‘Respects Your Freedoms’ certification. Laptops start at
state of the online Linux computer market place is
£168 including shipping to Europe, USA or Canada.
now. If you’re in the US, ZaReason and System76 both
www.linuxvoice.com 27
build computers specifically for Linux, so you can be
sure that the hardware will be well supported.
Unfortunately for us this side of the pond, ZaReason
doesn’t ship across the Atlantic, though it has
promised us a UK store soon. System76 does ship
internationally, though the shipping costs and import
duty add to the bill, and not everyone is happy about
ordering expensive items like computers
internationally, as it complicates the returns process if
anything goes wrong.
There aren’t any specialist Linux vendors in the UK, Three of the four ‘No OS’ computers from PC World are
but we do have a few companies that custom build not available. Perhaps they’re sold out because all the
computers, such as pcspecialist.co.uk and other computers run Windows 8.
cyberpowersystems.co.uk. While these won’t ensure
your system is fully compatible with Linux, or even Intel has been pushing smaller computers with its
install Linux for you, they do enable you to select Next Unit of Computing (NUC). With motherboards
everything that goes into your computer so that you measuring just 4 x 4 inches, these almost fit into the
can make sure that everything’s Linux compatible. palm of your hand, yet can be kitted out with a spec
Perhaps a little surprisingly, the desktop PC niche is that would put many desktops to shame.
the hardest computing market in which to find Linux From a Linux user’s perspective, there are two great
support. On Amazon, the top three best-selling laptops things about the NUC: it uses Intel hardware, so is well
all run Linux. They’re running it in the form of supported, and operating systems cost extra. This
ChromeOS rather than last point is good because it makes people see the
“On Amazon, the top three best- a more traditional
GNU/Linux system, but
cost of having Windows installed on their computer,
and it means that you don’t have to pay for Windows
selling laptops all run Linux, in from a hardware if you don’t want it.
the form of ChromeOS.” perspective this isn’t a
problem, because it
Intel was far from the first company to make
computers in this form factor though. There have
means that all of the been small home servers for several years, and even
hardware will work with the kernel, so will work with computing heavyweights such as Apple (the Mini)
other distributions as well, and there are a few built little computers.
projects – such as Crouton – that make installing
Linux on Chromebooks easy. Mint machines
The flexibility of Linux makes it a great system for Embedded PC makers Compulab teamed up with
building non-desktop, or slightly unusual desktop Linux Mint to create the Mint Box, a small fanless PC.
hardware. In the last few years, we’ve seen plenty of It’s been available in America for some time, but has
new takes on computing where manufacturers have only just launched in Europe. This would be another
created something a little different from a traditional great option for Linux users this side of the Atlantic,
desktop or laptop computer. More often than not, except it was such a good option that it promptly sold
Most NUC sellers offer
these computers have either run Linux exclusively, or out. The Mint team assure us that more units are on
Windows as an option
supported it as an option. Closed source systems their way, so should be for sale (on Amazon.de and
rather than installing it
as standard. Is this a sign can’t hope to have the same level of flexibility as open possibly Amazon.co.uk) by the time you read this.
that the once powerful source ones, and this flexibility is essential when These smaller computers make great Linux boxes.
Windows-Intel alliance is designing things that don’t fit into traditional modes of The one major downside to the form factor is that
faltering? computing. they’re not as upgradeable as traditional ATX
machines. You usually have some ability to put in
more memory, or replace the hard drives, but typically
not the processor. Whether or not this is a problem
really depends on you. Here at Linux Voice Mansions,
we can’t remember the last time we upgraded a CPU,
so are inclined to say it’s not an issue. However, other
people may feel differently.
There’s a special type of small form-factor
computer that’s been around for a long time – the
games console. While Linux has run on some of them,
none of the previous ones could have been called
Linux Friendly. All this is about to change with the
anticipated launch of SteamBoxes later in 2014.
This has excited gamers of all OS persuasions, but
it could also be of interest to Linux computer
28 www.linuxvoice.com
BUYING A LINUX COMPUTER FEATURE
Open hardware
Some people like the flexibility of using Linux; some working computer built from plans that anyone
people like the concept of open source software; could download and copy. These plans include
and some people like freedom. For these latter everything from the mainboard upwards. Early in
people, free software is only part of the solution. In 2014, he showed off the laptop in a working state.
a truly free computer, both the hardware and the He plans to launch a crowdfunding campaign for
software should be free. This not only means no people looking for a similar computer this year.
binary drivers, but also that the full schematics of Bunnie’s laptop is impressive, but it doesn’t go all
the computer should be available too. This way, the the way to truly free hardware, since it still relies on
user has the same freedoms with the hardware that commercial chips with closed designs.
they have with free software. It might seem crazy to try to design an open
Perhaps the biggest success story of open source chip, especially one as complex as a CPU.
hardware is the Arduino microcontroller board. Perhaps it is crazy, but that hasn’t stopped people We have no idea what this is, but it’s part of
While these are several orders of magnitude less from doing it. The OpenRISC 1000 is an open the schematic for Bunnie’s laptop.
complex than PCs, their success shows the power source CPU written in Verilog. Verilog is a hardware
of the idea. Because they combine open hardware description language that can be loaded onto Field OpenRISC-based SoC and implement it in an
and open software, people have been able to take Programmable Gate Arrays (FPGAs). Application Specific Integrated Circuit (ASIC). This,
the idea and convert it into new boards. The OpenCore community, which developed for the first time, will mean you can buy a
Back in 2012, Bunnie Huang set out to build a OpenRISC, is hoping to go one better and is completely open source board that will run Linux.
laptop based on the same principals. He aimed for a currently running a fundraiser to develop an See www.opencores.org/donation for more details.
shoppers. After all, SteamOS is built on Debian, so these run Linux (either a traditional desktop, or
anything that works with SteamOS should also work Android). There really isn’t a credible alternative OS for
with other Linuxes (at this stage, we use the word small ARM boards. The disadvantage here, though, is
‘should’ because it’s still possible that Valve will do that the hardware isn’t as standardised as it is on x86
something to stop this working – though this seems systems, so just because it runs one version of Linux,
unlikely). There is really no difference between a you can’t be sure it’ll run another. This is why, for
SteamBox and a PC except the form-factor. There still example, you can run
aren’t many hard details on the specifications of the Ubuntu on the Udoo,
SteamBoxes, but several of the ones announced have but not the Raspberry “In the modern world, it’s the
been listed as having configurable hardware. We’ll Pi, and vice versa with PC shops that are struggling to
have to wait to see exactly what this means, but it Raspbian. It’s also why
looks like it could soon be another excellent option for you can’t easily replace keep up, not Linux.”
buying a computer that’s guaranteed to work with Android with desktop
Linux regardless of whether you want to use it as a Linux on most devices.
games console.
Perhaps the most famous small computers haven’t Welcome to the new reality
been high-powered x86 machines, but lower-powered While it can sometimes be a little depressing to walk
ARM ones. The Raspberry Pi is an obvious example, into a PC shop and see Windows machines all around
but it’s not alone in this category. The Udoo (reviewed you, the truth is that, in the modern world, it’s these PC
on page 53) and the Cubie board are just two more of shops that are struggling to keep up, not Linux. If we
an ever-growing range. Almost without exception, really are moving into a post-PC world, then it’s a world
that Linux is poised to dominate. No other OS has the
depth of hardware support and flexibility to enable it to
run on so many different devices. It could be Android
on embedded devices, an XBMC system running on a
Home Theatre PC (HTPC), or an NUC that dual-boots
SteamOS and desktop Linux. It’s hard to see any other
OS catching up to the lead Linux has when you look
across all these computing platforms.
This writer, though, is highly sceptical of the term
SAL
‘post-PC world’. It seems that the new devices that are
coming out almost every day aren’t replacing PCs and BUY ! E
laptops, but supplementing them. If this is the case,
AL I N G
COM INUX
Linux support is bound to increase as more of the
non-PC computing devices use Linux, but it’ll take
PUT
a long time to supplant Microsoft on the desktop. ER
While they don’t have the raw processing power of x86, Whatever happens in the future, right now is a SAL
ARM chips are getting more powerful and are starting to
become an option for desktop computing.
great time to buy a new Linux computer, and
it’s only likely to get better in the future.
E!
www.linuxvoice.com 29
FEATURE FSF EUROPE
FREE SOFTWARE
FOUNDATION: EUROPE
We discover what this bastion of digital
rights in Europe is doing for all of us.
“E ver since FSFE was founded in 2001, creating
public awareness for Free Software has been
at the heart of what we do. Today, there are
more groups than ever before that really understand
his idealism, insight and intelligence. Which is why,
among those other accomplishments, he also
founded the Free Software Foundation in early
October 1985, just as Dire Straits’ Money for Nothing
Free Software, and that are working to promote it. We was to lose its reign at the top of the US singles chart.
talk to a lot of different audiences: developers, public But what many people don’t realise is that there are
sector people, businessfolks, students, police, church several sister organisations to the Free Software
groups, and even the military – basically, we’ll go Foundation, including the Free Software Foundation
anywhere where people need to hear about Free Europe – or FSFE, as it’s better known. FSFE is far
Software. And on most of those occasions, we still more than a local mirror for the US-based FSF. It’s
need to start off by explaining what Free Software is been a significant third party in the European Union’s
and why it matters.” antitrust case against Microsoft by helping to put the
These are the words of Karsten Gerloff in his reply case forward that competition in the file/print server
to a question about how you measure the success of market (thanks to Samba) is essential. At the end of
the Free Software Foundation, and more specifically, March, the foundation also published an open letter to
its European counterpart, the FSFE. the EU Parliament and the European Commission
“Being able to reach all these audiences is a huge asking for the support of open standards.
success. Seeing all the groups that have sprung up to We had a chance to speak to Karsten Gerloff and
promote Free Software in their specific environment is Matthias Kirschner, President and Vice President of
very satisfying. But there is so much left to do.” the Free Software Foundation Europe, about the
European branch of their organisation, and Sam Tuke,
In the beginning… its Campaign Manager, who writes a great report on
Richard Stallman has done many great things. this year’s Document Freedom Day over the page.
Without him, there’d be no GNU, no GPL and no First, we asked whether there are any policy
Emacs, and arguably, no Linux in the way that we differences between the FSF and the FSF Europe. .
know it. If the free software ecosystem existed “No”, answered Karsten, “We share the goal of
without RMS, it wouldn’t be half as effective without promoting Free Software, and do so by similar means.”
30 www.linuxvoice.com
FSF EUROPE FEATURE
Income and expenses
2012
INCOME
Donations €197,420.59
Fellowship/membership contribs €106,411.08
Paid services €26,036.85
Merchandise €13,493.84
Interest/currency exchange gains €15.16
Total €343,377.52
EXPENDITURE
Basic infrastructure costs €92,830.45
Public awareness €96,626.77
Fellowship €47,411.87
Legal work €69,877.86
Policy work €50,158.26
Merchandise €14,262.61
Total €371,167.82
For us, that begs the question of why a European- “That’s a tough call to make. We have had a lot of
centric FSF is important. success in all three areas!” Karsten told us.
“Being based and rooted in a specific region, in our “In the legal field, FSFE has achieved something
case in Europe, makes it easier to be effective as unique. Through eight years of careful work, we have
advocates, by adapting to the local cultures and built the world’s largest network of legal experts on
circumstances.” Free Software. There are currently over 340 lawyers
and engineers in this group,
Shared goals
“We frequently work together [with the FSF, FSF India
including many of the
very best people in the field.“We have built the world’s
and FSF Latin America] to come up with shared They are helping each other largest network of legal
approaches to fundamental issues. These internal
discussions tend to be very thorough, and quite
learn more about Free
Software and about how experts on Free Software.”
productive. In organisational terms, however, all FSFs their respective companies
are fully independent of each other. FSFE has its own and organisations are using it, and remove fear,
legal entity, employees, independent governance uncertainty, and doubt. This has given us a great set
structure, and raises its own funds.” of contacts to many of the companies that build Free
Raising your own funding under the umbrella of a Software. For the companies, this exchange of
perhaps more widely known organisation must be a
difficult task. We wanted to know how you measure
the success of the FSFE, rather than the wider
organisation, to be able to attract funding.
Help the FSFE
We asked Karsten how best we the community might help.
“There are many different ways how people can
contribute to FSFE.” he told us.
“We have a page (http://fsfe.org/contribute/contribute.
en.html) that outlines most of them. If you’re passionate
about Free Software, and want to work with others who
care for the same thing as you, there will be a place for you.
One of the reasons FSFE is doing so well is that we try very
hard to identify each person’s speciality, and help them use
it for Free Software in the most effective way. In the UK
especially, we would love to get more local groups going,
with regular meetings and occasional events. People
who are interested should write to fellowship@fsfeurope. Karsten Gerloff, protector
org, or simply contact anyone they know in FSFE! of Free Software and
President of FSFE.
www.linuxvoice.com 31
FEATURE FSF EUROPE
knowledge means that they better understand “When companies lose the fear of putting Free
their obligations when using Free Software, leading to Software into their products, and ideally give users the
fewer licence violations.” possibility to change it on their devices, that is
“We have always invested a lot of time and effort in success for us.” Karsten told us.
policy work, whether it was about keeping software This is just as important today, now that Windows
patents out of Europe, helping the European XP is no longer supported, as it was when Microsoft
Commission to bring Microsoft to book for its was more confrontational and the FSF was trying to
anti-competitive behaviour, promoting Open side-step the FUD being thrown. But times have
Standards like ODF, or changing public procurement. definitely changed.
These issues often take many years to bring to a “When the European Commission gives Microsoft a
conclusion -- that is, if they ever end. FSFE is one record antitrust fine, along with a clear message that
of very few organisations, and almost the only one their behaviour isn’t acceptable around here, that is
specialising in Free Software, that has the skills and success for us,” Karsten began.
resources to stay on the ball for as long as it takes.” “When the UK government goes ahead and opts for
We love the way Karsten says “for as long as it ODF as a default format for its documents, in the face
takes”, as we think that’s the vital component in the of fierce resistance from the incumbent IT suppliers,
FSF’s strategy – an unrelenting approach to Free that is success for us. We don’t always get everything
Software advocacy and adoption. You know it’s not we want. But often we’ll get most of what we push for.”
going to sell out or dilute its vision in the face of “The biggest challenge for the next 10 years will be
commercial pressure. And that’s an important making sure that we can be in control of our own
differentiator between Free Software and other computing. That’s really what a lot of the fights we are
development models. It’s channelling spirit of Stallman fighting today are about: Can you be trusted to control
through the foundation he created 30 years ago. your own computer?”
Document Freedom Day 2014
Freedom to read, write, and create requires freedom of formats, writes Sam Tuke.
Here’s how one campaign brought open standards to 51 locations in 22 countries.
B
alloons litter the floor, cream smeared plates Document Freedom Day is when people celebrate
pile high on tressel tables, beside which the freedom from data format tyranny and the systems
crowd of participants file out of the auditorium that preserve it. On the last Wednesday of March
door. “Give us a chance – choose Open Standards” every year groups like GALPon in Granada University
reads the Spanish posters adorning the walls, and a (“Grupo de Amigos de Linux de Pontevedra”) take the
typical Document Freedom Day event ends. opportunity to run events that explain why these
An animated band of students and professors have freedoms are important, and share the knowledge and
been debating the video files that Grenada University tools necessary for citizens to take them back.
uses for publishing research in Southern Spain. Some events are big, like the 300-attendee speech
They’ve been here all afternoon, and in a few hours at Istanbul Turkey. Some are small, like the group of
As well as baking cakes, their pictures will join hundreds of others that have sixteen friends who discussed Open Document
volunteers took the word been streaming out of cafes, lecture halls and Format (ODF) in Yuli Township, Taiwan. Others are run
of document freedom out hackerspaces around the world the last 24 hours. by governments, like the Brazilian Federal Government
into the streets. CISL Committee. And a few take place in schools, like
Maltepe Nezahat Aslan Ekşioğlu Primary in Istanbul.
All are organised at a local level by independent
community leaders.
Open as standard
While DFD is about people, events, and not a little
cake, many of the issues addressed are necessarily
technical. What you can do with a file once it’s been
saved depends on the format of the data inside. What
governs such formats are loosely called standards.
And similarly to software applications, some
standards protect freedoms while others prohibit
them. Unlike software however, generic licences like
32 www.linuxvoice.com
FSF EUROPE FEATURE
the GPL don’t exist for standards. The two serve even showed hers off during a keynote speech
fundamentally different purposes, and what makes a (www.guardian.co.uk/technology/2012/
file format useful is more nuanced than what make apr/19/digital-handcuffs-ec-vice-president).
software free. For example ,the future development of Last year netizens reported popular
a standard can be just as important as its past. When websites that used Adobe Flash instead of HTML5
LibreOffice forked OpenOffice, the result was two technology for streaming video. Educational packs All this year’s DFD
materials and source
separate, independently useful applications. But if a were duly delivered to the appropriate webmasters,
code are hosted online
fork of their native file format, ODF, had also been together with a pair of blacked-out “plugin required” under copyleft licenses.
made, it would have been far less useful, as no other glasses illustrating the downgraded experience of Recipes, origame,
applications would have been able to understand it. users missing closed standard browser extensions. certificate templates and
Standards provide a platform of data compatibility In March, MEPs were challenged to reconsider forms for claiming back
upon which software is built and competes. Parliamentary security when a panel of experts expenses are all in public
So instead of a license, criteria are used to identify debated surveillance in the European Parliament for repositories.
freedom-respecting standards. The ones that pass Document Freedom Day 2014, and on the same day
the test are “Open Standards”, and the rest are an open letter to EU Institutions confronted their
“closed”. Some governments, including the European captivity to Microsoft.
Union, have their own definition. Document Freedom My job as campaign manager is to empower local
Day uses FSFE’s five-point version, and while the people to serve their own communities. Our small
variations are the subject of heated political debate, team in Berlin can’t be in 51 places at once, but our
most agree on core requirements that the standard network of freedom
may be used by everyone, that technical details are fighters can. Nor could “Highlighting the importance of
freely available, and that modifications to the standard
are set by an impartial group.
we generate the
enormous creative open standards to mainstream
While the politics of file extensions may be energy that marks the society is a core goal of DFD.”
fascinating to power-users and freedom fighters, campaign each year. A
getting the message to everyone else can be monkey hitting a
challenging. Highlighting the importance of Open typewriter infinite times may finally write Shakespeare,
Standards to mainstream society is a core goal of but it’s doubtful the otherwordly sounds produced in
Document Freedom Day, and talking direct is a fun last year’s DFD Zurich open audio jam could have
and effective way to achieve this. come from a centralised campaign.
In 2012 we raised eyebrows and headlines by And when getting involved can be so much fun, it’s
sending steel handcuffs to politicians and public easy to ask others to participate, so why not run your
figures whose websites endorsed closed standards. own event? Join us next year in the campaign for
European Commission Vice President Neelie Kroes document freedom!
www.linuxvoice.com 33
FEATURE OPENCORES: DIY CPUS
Designing and implementing your own CPU or System-on-Chip
brings benefits to thousands of researchers and forward-looking
businesses, and is being adopted by a growing number of
hobbyists. Richard Smedley finds freedom
in configurable silicon.
F
or some years (the need for a few binary blobs One such of these is OpenCores, which bills itself as
in the kernel excepted) many readers have run “the #1 community within open source hardware
an entirely Free Software stack on their servers, IP-cores”, backing the claim with a statistic of more
laptops, desktops, and even tablets and phones. But than 200,000 registered users. It hosts projects
at the silicon level it’s another story, with open source ranging from relatively simple UARTs (universal
hardware limited to a few embedded boards like the asynchronous receiver/transmitter) and Ethernet
Arduino. The good news is that not only are there MAC (Media Access Control) LAN implementations
open source designs for CPUs and Systems-on-Chip right up to the complexity of full OpenRISC chips.
(SoC) nowadays, but that it’s not too hard to learn to That reference to “IP-cores”, rather than CPU cores
design and make your own. Indeed, there are projects is an abbreviation for so-called “intellectual property”,
designed to get you started doing just this. and is a telling reflection of the proprietary nature of
34 www.linuxvoice.com
OPENCORES: DIY CPUS FEATURE
Space RISC
OpenCore has gone beyond earth-bound applications, after Raspberry Pi to near-space from your school for 1% of this
students at San Jose State University – funded by NASA’s cost, as David Akerman did when he launched his Pi and a
Ames Research Center – designed a 1U satellite, TechEdSat, camera on a balloon into the skies over Berkshire.
to evaluate ÅAC Microtec’s implementation of OpenRISC, and
perform communications experiments.
The satellite, which was deployed from the International
Space Station in 2012, cost less than US$30,000 to build
thanks to the combination of OpenRISC and off-the-shelf
hardware selected to be rugged enough for space use.
According to engineers from ÅAC Microtec, the standard
OpenRISC design was modified with fault-tolerant features
and toolchain modifications invisible to the end-user software
as different from standard OpenRISC spec. The great thing
about using an open specification is that these modifications
have no barrier in terms of licensing or configuration
information, while the flexibility of FPGAs makes prototyping
quick and (relatively) easy.
At these prices it’s now conceivable that with savvy
sponsorship, even schools could launch a satellite with their OpenCores in space: the OpenRISC powered TechEdSat
own custom CPU. However, don’t forget you can send a is deployed from the International Space Station.
most work cast into silicon. The fast growth of list of logic gates and connections used in your
OpenCores shows that there’s enthusiasm and a chosen FPGA. This latest acronym is a Field
business need for a more open alternative. Naturally, Programmable Gate Array, which is a kind of chip that
the opportunity that OpenRISC presents to gives isn’t yet set in stone. One FPGA costs a lot more to
playing with the design of a full-blown modern make than the equivalent processor, but the extra
microprocessor makes OpenRISC useful in flexibility means that if the design doesn’t work the
universities, and the freedom to explore means way you want it to, you can simply change it (that’s
another field opened to hobbyists. But what’s really the Field Programmable part).
driving development is a number of businesses taking
advantage of a flexible, cost-effective route to Free as in almost
specialist markets. The netlist produced is a gate level description, which
then usually uses the chip manufacturer’s proprietary
RISCing it software to produce the programmed FPGA. For
Dr Jeremy Bennett of
So, why pursue open CPU architecture, and why go anyone wanting 100% Free and Open Source
Embecosm showing
the RISC route? The latter question is the simplest to hardware and design there doesn’t seem to be a way
the OpenRISC SoC
answer. The case for RISC (Reduced Instruction Set around this at the moment. As Embecosm founder implementation on
Computing) was well made by IBM researchers in the and OpenCores stalwart Dr Jeremy Bennett told Linux FPGA at an Open Source
late 1970s, and producers of the first RISC1 chip at Voice: “The back-end tools are proprietary to the FPGA Hardware Users Group
the Unversity of California, Berkeley 30 years ago. manufacturers. Since these tools depend on intimate meeting in 2011.
Reducing the operation code instructions in silicon (by
a factor of 10 at the time), not only simplifies design
but frees up space for more registers and cache.
Efficient compiler design of the time took away the
need for most instruction operation code, and the
situation is unchanged today.
OpenRISC is a family of 32- and 64-bit processors
with optional floating point and vector processing
support. It’s a free, open source RISC architecture with
DSP (digital signal processor)features and a complete
set of free, open source software development tools,
libraries, operating systems and applications. The
reference design, the snappily titled OR1K (OpenRISC
1000) is implemented as OpenRISC 1200 (OR1200), a
synthesisable CPU core released under the GNU
Lesser General Public Licence (LGPL).
© 2011 Andrew Back
Writing your own design (for an OpenRISC chip)
consists of using a Hardware Description Language
(such as Verilog) to describe the chip at the most
basic level. Then comes synthesis – conversion to the
www.linuxvoice.com 35
FEATURE OPENCORES: DIY CPUS
directly. Many other small companies make chips and
Browsing the hardware boards based on OR1K, including ÅAC Microtec,
which has had its product put into orbit. The fast
While the idea of building your own CPU The project’s GitHub pages –
development offered by open hardware also makes it
appeals to many of us, perhaps you are https://github.com/s-macke/jor1k/ – include
looking for a way of testing the waters a wiki with useful and interesting notes on great for larger companies playing in fast-moving
without all the kit. Sebastian Macke of some of the JavaScript optimisations used markets: Samsung ships OpenRISC chips in the
simulationcorner.net has written jor1k – the in the code, as well as speed differences system-on-chips used in its digital TVs.
JavaScript OpenRisc 1000 emulator – between browsers and a list of the many Any curious hacker or maker can experiment with
which gives you the chance to try out open demonstrations available in the Linux image
FPGAs and OpenRISC. Delving into chip design
hardware design in that most familiar and on the emulator.
comfortable environment, your web browser. enables you to grapple with all sorts of tasty problems
jor1k works with Firefox and Chrome, involving Fused Multiple Accumulator (FMAC)
though if running locally with the latter you arithmetic, bus design, and optimal register numbers.
need to run the browser with the command If you’ve ever programmed at a low level, and cursed
--disable-web-security.
the decisions made by chip designers at Intel, now is
The emulated OpenRISC CPU is around
1000 lines of code – a neat introduction to your chance to show the world a better way!
emulation, the OpenRISC architecture, and Anyone wanting to join in the fun will find many
JavaScript programming all in one! It’s also a resources online, but also meetings and chances to
handy sandbox to test OpenRISC ports, and learn the process of programming your own FPGA
you could try modifying the emulator to test
If your emulated OpenRISC goes wrong through the Open Source Hardware Users Group
out ideas for modifying OpenRISC away from
you can just scrap it and start again. (OSHUG), which conducts meetings in and around
the standard implementation.
London but also ventured north for last year’s Open
Source Hardware Camp at the Wuthering Bytes
knowledge of the device, it is hard to see how there festival in Hebden Bridge.
could be a free and open source implementation,
unless the manufacturer chose to do so.” Open to all
Given the growth of understanding in the Working with OpenCore designs is challenging but
advantages of open source methodology, this is not rewarding. “Inexperienced users should be warned
an impossible wish. Meanwhile, we accept that we that the OpenRISC processor is quite a difficult
live in an imperfect world, and continue to make it processor,” warns Patrick Pelgrims of the Belgian De
better – or at least more interesting – to the best of Nayer Instituut, in his tutorial on designing and
our abilities. At least the Linux-compatibility of the implementing an OpenRISC-based embedded
tools is good. system. But we don’t want that to put you off – the
reference design is a good place to start, and as with
Fabulous Fabless learning programming through playing with existing,
Designing and fabricating semiconductors is an working code, so with hardware.
expensive business. You don’t get many opportunities We asked Dr Bennett about the difficulties involved.
to create prototypes of designs that have tens of He pointed out that it’s “a relatively simple and well
millions of transistors in them, and this has led to documented architecture. It has a pipeline (more
notable bugs such as the Pentium FDIV bug, which difficult), but only a five-stage pipeline in the standard
caused the processor to return incorrect results in
floating point calculations (Intel eventually had to OR1200 CP
recall the chip, but not
“It is well within the grasp of before considerable
Instr.
MMU
Instr.
Cache
Wishbone
I/F
damage to its
a competent hobbyist. And of reputation). With even Fetch Timer
course modifying an existing giants like Intel having
rationalised its range of Decode
design is always easier than offerings in the last
D Power
Mgmt.
designing one from scratch!” decade to concentrate Execute S
resources on the most Debug I/F
Dr Jeremy Bennett. Memory P
profitable lines, OpenRisc
is a disruptive
Writeback Interrupts
technology, enabling semiconductor companies to
develop chips for embedded markets like network
devices, personal entertainment hardware, and niche Data Data Wishbone
industrial applications – without having to spend MMU Cache I/F
money on operating their own factories. Optional/Configurable Minimal Configurable
Much of the active development on OpenRISC
comes from companies like Swedish design house Inside the OpenRisc 1200 CPU – configuration at the
ORSoC, which also sponsors the OpenRISC project silicon level, with Free and Open Source Hardware.
36 www.linuxvoice.com
OPENCORES: DIY CPUS FEATURE
You’ll need an FPGA development board to get started
which, while not cost-free, is orders of magnitude less
expensive than building a CPU plant!
implementation (so not that difficult).” He summed it
up as: “more complicated than some, but a lot less
complicated than many. The bottom line is that You could build an entire
processor design is not trivial. On the other hand it is toolchain-build.html) you can test-run your OpenRISC OpenRISC toolchain
well within the grasp of a competent hobbyist. And of environment in a VM with: yourself, but as the hard
course modifying an existing design is always easier or1ksim -f arch/openrisc/or1ksim.cfg vmlinux work’s already been done,
just grab it with Git and get
than designing one from scratch!” Next, you’ll need an FPGA development board. This
on with the fun.
year’s Chip Hack event will use the DE0-Nano board,
Chip Hack & getting involved but there are plenty of others listed on the OpenCores.
OSHUG runs an annual event called Chip Hack, which org website, including some recent developments. As
is a weekend of learning to create embedded noted earlier, you will need proprietary Quartus
hardware, building and making, and taking home your software from Altera installed to turn the Verilog HDL
own OpenRISC SoC: file into something that can be loaded onto the FPGA.
If you can’t get to Chip Hack you can still give it a try Before that you’ll need the Verilog file itself – the
yourself: you could use a browser-based emulator to OpenRISC site has an OpenRISC Reference Platform
explore OpenRISC (see boxout, above-left), but getting System-on-Chip in the flavour you need.
the toolchain installed on your PC to get started can
be as simple as: Environmentally friendly
$ git clone git://openrisc.net/jonas/toolchain Low power consumption has always been an
$ cd toolchain important selling point for RISC chips, enabling them
$ git submodule update --init to quietly conquer the embedded space in the 1990s,
$ make -j3 PREFIX=~/openrisc/toolchain and thus be the big winners in the rise of the mobile
$ export PATH=PREFIX=~/openrisc/toolchain/bin;$PATH device. Given the huge power consumption of data
For an optimum make -j value, double your number of centres on a worldwide scale, it’s no surprise to find
CPU cores, and add one. The destination directory can OpenCore developers at UK-based Embecosm, which
be anywhere you have permission to put it. After did much of the work on GCC and the GNU toolchain
setting up your cross-compile environment and for ORSoC. Adapteva (developers of “a revolutionary
building a Linux kernel (see http://openrisc.net/ many-core embedded computing platform for
applications requiring ultra
high floating-point
DIY chips on the web
performance with minimal “Low power consumption has
Introduction to FPGA programming event.
http://chiphack.org
power consumption”), is
also doing work funded by
always been an important
Good beginners’ introduction.
www.rte.se/blog/blogg-modesty-corex/openrisc-1200-
the UK Technology Strategy selling point for RISC chips.”
soft-processor Board (a UK government
Julius Baxter’s Masters Thesis on the OpenRISC Project. innovation agency), to
http://juliusbaxter.net optimise GCC for compiling binaries with a lower
Paper covering all the chips from OpenSPARC to the power draw.
European Space Agency’s LEON project:
As we go to press, the Chip Hack Cambridge event,
http://ur1.ca/gyitc
jor1k – OpenRisc 1000 in your browser. providing an introduction to FPGA programming, is
http://s-macke.github.com/jor1k already sold out “but a key part of the idea is that he
Open Source Hardware User Group resources are open, so others can run the course
http://oshug.org themselves,” Dr Bennett tells us. Get on the Chip Hack
Also, there’s a supportive community on the #opencores
mailing list, and you should get early news of other
channel on freenode IRC.
events and training opportunities.
www.linuxvoice.com 37
FEATURE ALAN TURING, COLOSSUS, AND TURING MACHINES
We’re taking a break from our Olde Code series this issue to get
some background on a man who was in the news as recently as
last year. Juliet Kemp looks back at the early works of Alan Turing.
A
lan Turing was born in London in 1912, Cypher School (GC&CS), reported to Bletchley Park to
studied mathematics at King’s College, work full time on cryptanalysis. His work on
Cambridge, and was elected a fellow there in deciphering Enigma, on the Bombes, and his
1935. He worked on the Entscheidungsproblem, then contributions to the development of Colossus, were a
spent two years studying maths and cryptology at hugely valuable part of the history of early computing;
Princeton. While there he also built part of an they also remained secret until the 1970s.
electro-mechanical binary multiplier. This type of
machine – a computer, but not a programmable one Turing machines
– was the state of the art in computer hardware at the In 1928, mathematician David Hilbert posed the
time. In 1938, Konrad Zuse would complete the Z1, Entscheidungsproblem (Decision Problem): does an
the first mechanical binary programmable computer, effective procedure exist that would demonstrate
in Berlin, although the Z1 was not a general purpose whether or not a given mathematical statement is
machine as it had no loop capacity. provable from a given set of axioms? In 1931, the
When WWII began, Turing, who was already Austrian mathematician Kurt Gödel demonstrated
working part-time with the Government Code and that any arithmetic system must be incomplete (that
38 www.linuxvoice.com
ALAN TURING, COLOSSUS, AND TURING MACHINES FEATURE
“A universal Turing machine
is one that can compute any
computable sequence. Modern
computers are all universal
Turing machines, and we take
this idea for granted now.”
is, it is possible to construct a statement that can be
neither proved nor disproved), but did not tackle the
provability problem.
In 1936, Turing wrote “On Computable Numbers
with an Application to the Entscheidungsproblem”,
which showed that no such procedure exists. He used
the idea of an “a-machine”, now known as a “Turing
machine”. This is a hypothetical computing device,
which reads an infinite tape. At any one moment the
machine reads a single symbol from the tape. It may
alter that symbol, and the symbol may (combined
with the machine’s instruction table) affect its
behaviour. The tape moves backwards and forwards,
so any symbol may eventually be read by the
machine. Turing equated the problem of deciding
whether a Turing machine halts on a given algorithm
to the Entscheidungsproblem. He proved that some
processes will never halt; and thus that the answer to
the Entscheidungsproblem is ‘no’.
A universal Turing machine is one that can compute
any computable sequence. Modern computers are all
universal Turing machines, and we take this idea for
granted now. At the time, however, it was a huge
breakthrough, which arguably led to the idea of
stored-program computers.
Turing was also an
Germans introduced more rotors and more plugboard
accomplished athlete,
Bombes and Enigma settings to their Enigmas, these machines couldn’t
with a personal best
One of the simplest ciphers is a substitution cipher: keep up. The Bletchley Park codebreakers needed to marathon time of 2 hours
each letter is substituted with another letter. This is up their game to decrypt Enigma traffic. 46 minutes.
readily breakable, but it becomes less so if you use a
different substitution alphabet for each letter of the On the shoulders of Polish giants
message. The Enigma machine, invented at the end Turing took the bomba cryptologiczna and improved
of WWI, had a system of rotors which both on it to create the Bombe. A standard British bombe
mechanised this process (making it easier to operate), contained rotors to the tune of 36 Enigma equivalents,
and increased the number of cipher alphabet options. enabling it to work very rapidly. The bombe input was
Each rotor had 26 positions, and they were connected a crib (a fragment of probable plaintext), which was
in series, so each letter was transformed multiple tested against the ciphertext. The bombe
times. Further, the rings stepped onwards for every electronically performed various logical deductions
letter (how often the rotors stepped varied, but at least based on this, and if a contradiction arose (which it
one rotor would step at least once for each letter). would do with most possible settings), that crib could
This meant that each letter was encrypted with an be discarded. Only a few settings would then be left
entirely new cipher from a huge number of options. for the cryptanalysists to look at in more detail. This
Finally, a ‘plugboard’ swapped some pairs of letters was an electronic computer in one sense, but it wasn’t
before they were output to confuse matters further programmable; it performed just one task. The cribs
(though in fact, contrary to expectation, this made were obtained by taking advantage of various
breaking it slightly simpler). regularities in the messages transmitted, such as
Before WWII, the Poles had already had some weather reports and message setting information.
success with breaking Enigma messages with their Turing’s colleague, Gordon Welchman, later
bomba cryptologiczna machine. However, as the implemented the ‘diagonal board’) improvement. The
www.linuxvoice.com 39
FEATURE ALAN TURING, COLOSSUS, AND TURING MACHINES
bombes were immensely successful, but initially wheels) sent at the start of the message. Being able
Turing and his colleagues could not get the resources to identify when two messages had used the same
for more bombes and more people. Eventually they wheel settings gave the codebreakers access to
went against military procedure and contacted messages in ‘depth’, which is crucial in codebreaking.
Churchill directly; resulting in Churchill giving the A colleague of Turing’s, John Tiltman, managed to
highest priority to support for the codebreaking team identify the cipher used (the Vernam stream cipher)
at Bletchley Park. from studying intercepted ciphertexts, and after this,
Turing also worked specifically on naval Enigma, Bill Tutte worked out the logical structure of the
which he started on “because no one else was machine from further ciphertext study, without ever
interested in it so I could have it all to myself”. The seeing a Lorenz machine – a hugely impressive
chief difficulty here was that the sender enciphered achievement. Tutte and his colleagues correctly
the message settings (the information about which determined that the machine had two sets of wheels,
rotor settings the message was encrypted with) twice, chi and psi. The chi wheels all moved on one position
once by Enigma and once by hand using ‘bigram with each character. The five psi wheels also all
tables’ (tables of letter pairs). Turing deduced how this moved together, but at a different rate, controlled by
system worked, but was not able to move further two ‘mu’ motor wheels. This gave a huge number of
before the Royal Navy machine settings and cipher alphabets, which
“Information about Colossus got hold of some actual
bigram tables.
changed in a complicated way.
Turing’s main contribution was a process known as
began to emerge in the late The Colossus Turingery. This revolved around ‘differencing’, in which
1970s, and GCHQ released a machine was designed
by Tommy Flowers to
he XORed successive characters to emphasise any
points at which the characters moved away from a
1945 report on the breaking help with the uniform distribution. The next step was a complex
of the Tunny cipher in 2000.” cryptanalysis of the
Lorenz cipher. The
statistical analysis of the ciphertext, in which the
cryptanalyst tried out a huge number of possibilities
Lorenz cipher machines and compared the resulting patterns with one another.
were used for high-level wireless traffic between Eventually, the chi wheel settings could be deduced,
German High Command in Berlin and army and from there the psi and mu settings.
commands throughout Europe, during World War II, Turingery was a hand method, and slow. Tutte used
whereas, as discussed above, the more portable it as a basis for his own ‘1+2 break in’. This required
Enigma machines were used for other German army trying all possible combinations of the chi wheels
and naval messages. It has often been stated that against the ciphertext, and looking for subtle
Turing was involved with the development of statistical evidence of non-uniformity. This used
Colossus; in fact, this was true only in that his differencing to amplify the effect, and it worked well --
statistical methods were part of its ancestry and the but it was only practical if it could be automated.
cryptanalysis methods that prompted its building.
Construction time again
Colossus Mark 2 being
operated by Dorothy Du
Rotor encryption So in 1943 Max Newman, with Frank Morrell and
Boisson and Elsie Booker. Lorenz worked in a similar way to Enigma, with Tommy Flowers from the Post Office Research
The tape transport is multiple moving wheels producing a ciphertext. Station, produced a machine known as ‘Heath
shown on the right of the Similarly, one of the routes in to the cryptanalysis was Robinson’, using valves and paper tape. It was
photo. the ‘indicator’ (showing the start position of the Flowers who realised that this could be improved on
by building an entirely electronic machine (using an
electronic key stream rather than reading off paper
tape; although the message was still fed in on tape).
Most people argued that this would be far too
unreliable to be useful, but, supported by the Controller
of Research at the Post Office, Flowers went ahead
and built it. It first ran in December 1943 and was
operational by early February 1944.
This was, then, Colossus, the first programmable
(but not general purpose) digital computer. It had four
main parts:
Tape transport and reading mechanism Read the
message tape in at 5000 characters per second,
using the sprocket holes as a clock signal.
Key generation unit Generated an electronic key
(chi) stream.
Combining unit Implemented the logic of the 2+1
method.
40 www.linuxvoice.com
ALAN TURING, COLOSSUS, AND TURING MACHINES FEATURE
Counting unit Counted the dots in the output and The Turing Bombe rebuild
printed it out if it was over a given total. project at Bletchley Park.
Photograph by Mike Peel
It was so successful that they immediately began
(www.mikepeel.net).
building more in place of the Robinsons. The
Colossuses, and Colossus II (in operation from June
1944, the week before the Normandy landings), were
vital for the remainder of the war effort, but after the
war, all evidence of the project, physical and paper
notes, were destroyed, for security reasons. Despite
this, the number of people who had worked on the
project and who went on to work in early computers
meant that Colossus and the other Bletchley projects
did have a significant indirect impact.
Post-war: the Pilot ACE radar data (further information is still classified). The
After the war, Turing worked on the design of the first personal computer (well, arguably; it was a small
Automatic Computing Engine (ACE) at the National single-user machine), the G-15, built in 1954, also used
Physical Laboratory. The resultant paper, in 1946, was ACE principles. The commercial version of the Pilot
the first detailed design of a stored-program computer. ACE, the DEUCE, was available from 1955 until 1964,
The ACE implemented subroutines, and even and used various languages including one called
something called Abbreviated Computer Instructions, GEORGE (1957) which used reverse Polish notation
which was a sort of programming language. and had a 12-position stack. It was sold with an
In the ACE, instead of a CPU, memory locations and extensive program library of subroutines – perhaps
temporary stores had specific logical functions the descendants of Turing’s on-paper versions for his
associated with them. So transferring two numbers to full ACE.
a particular memory location, for example, added
them. To speed up executing, Turing suggested that ACE program example
instructions should be stored at specific locations, Wilkinson’s Progress Report on the Automatic
with each instruction pointing to the next, in such a Computing Engine (April 1948) includes this code
way as to optimise instruction access. (Experienced example to calculate squares and cubes of n by
UNIVAC programmers did something similar to get iteration until n = m (m is stored in tank TS1):
around the limitations of mercury delay line memory A1 zeros+ zeros -> TS2 Imm 1, A
– see LV002’s tutorial on Grace Hopper and UNIVAC.) A3 zeros+ zeros -> TS3 Imm 1, A
He also included a small fast-access memory for A5 zeros+ zeros -> TS5 Imm 1, A
storing frequently used numbers or ones that needed -----------------------------------
to be stored temporarily. A7 TS2 + TS3 -> TS3 Imm 1, A i.e. n2 + n -> TS3
Turing and his team, as well as sketching versions A9 TS3 + TS4 -> TS4 Imm 1, A i.e. n3 + 3(n2 + n)
of the ACE, also wrote ‘instruction tables’. Their aim -> TS4
was for programmers to be able to select groups of A13 TS2 + P1 -> TS2 Imm 1, A i.e. n + 1 -> TS2
standard instructions and link them together with A15 TS3 + TS2 -> TS3 Imm 1, A i.e. (n2 + n) + (n + 1) -> TS3
other cards, and they prepared in detail ‘instruction A17 TS4 + P1 -> TS4 Imm 1, A i.e. n3 + 3(n2 + n)
routines’ including division, extracting square roots, + 1 -> TS4
and logarithms. This echoes the work later done by A19 TS2 != TS1 -> DISC Imm 18, A If new n = m, return to A7,
Grace Hopper on UNIVAC, but sadly in Turing’s case, else A6
his instructions only ever existed on paper. -----------------------------------
Turing knew that what he proposed was feasible, A6 END
and wanted Tommy Flowers to be involved. However, The temporary TS tanks are used for quick access.
since no one who hadn’t been at Bletchley knew about TS2 holds n, TS3 holds n2, and TS4 holds n3. The first
the Colossus, everyone else thought his proposal far three instructions simply zero the tanks TS2, TS3, and
too ambitious, and Flowers wasn’t recruited. Instead, TS4 (so n, n2, and n3 are all, correctly, zero). The
they eventually built the smaller Pilot Model ACE. This following steps calculate the values iteratively, as
had 1,450 vacuum tubes and 12 mercury delay lines described; by step A19, TS2, TS3, and TS4 will all hold
as its memory (each storing 32 bits – again, see the their new values. (These are all discarded rather than
UNIVAC for more on mercury delay lines). Its clock saved, as this code was for demonstration only.) Imm
speed was 1MHz, which at the time it first ran (10 1 means an immediate transfer with timing number 1,
May, 1950) was the fastest in the world, and around that is, it goes straight to the next instruction. For
10 times faster than its contemporary, the more detailed information, check out the full paper.
Manchester Mark 1. And that, dear readers, is where we’ll have to leave him
The ACE design was also used for the MOSAIC for now. We’ll get to Turing’s work in Manchester in a
(1952) which calculated aircraft trajectories from forthcoming issue of Linux Voice.
www.linuxvoice.com 41
FAQ DDOS
BEN EVERARD
DDOS
The internet attack of choice for gangsters, governments and bored geeks.
across the world. These are distributed
denial of service attacks.
where they use some way of increasing
the amount of data that your computer
Often these DDOS attacks are carried can send. A DNS amplification attack is
Another acronym! First things out by networks of PCs infected with quite a common way of doing this.
first, how do I pronounce it? malware (botnets), but not always. For A Domain Name Server (DNS) is
Dos? D’dos? Dee-dos? And how is it a while it became common for people what computers use to lookup
different from MS-DOS? to volunteer to use their computers to information about a particular domain
For once, there seems to be a DDOS sites for Anonymous. name. For example, if you type www.
fairly accepted pronunciation: google.com into your browser, it sends
Dee-dos. It stands for Distributed Denial Right, I think I understand a request to your DNS server asking
Of Service, and it’s a way that bad what it is, but how do the bad what IP address is associated with
people attempt to mess with your guys go about doing it? www.google.com; then it sends an
computer systems – so it’s nothing at Whatever server you use to HTTP request to that IP address.
all to do with Microsoft’s venerable Disk provide your service has a However, DNS servers can be asked to
Operating System. number of finite limitations. It only has return more than just the IP address.
The idea behind a denial of service so much bandwidth, memory, CPU There’s also a text field associated with
attack is that a bad guy wants to power, etc. If you can overload any one domain names, which can hold up to
interrupt your service. Typically, this of these, then the server will no longer 4,000 bytes. A DNS amplification attack
means ‘take your website offline’, but it be able to function properly. works like this:
could mean stop users from accessing Perhaps the simplest form of DDOS A malicious computer sends a DNS
anything such as email or the database is to overload the network. In this sort request that will return a 4,000-byte
back-end for a mobile app. of attack, you just send loads and loads text field to a DNS server, but spoofs
It’s still possible in some cases for a of data to the server. The aim is simply the IP address.
single computer to take a website to clog up their network port so much The DNS server responds with the
offline, but most of the time, denial of that legitimate traffic starts to time-out. 4,000-byte file. It doesn’t send it to the
service attacks are carried out by large malicious computer, but to the
numbers of computers spread out But surely most big servers spoofed IP address (the victim server).
can cope with so much traffic These two steps take a 60-byte DNS
that a few virus-infected PCs won’t request, and turn it into a 4,000 byte
“You may remember have any impact?
True. However, the targets aren’t
packet that’s sent to the server. These
DNS packets won’t make any sense to
Anonymous’s DDOS attacks always the largest sites. Also, a the server, and it’ll just reject them once
on financial institutions.” cunning DDOS attacker can use what’s
called an amplification attack. This is
they arrive, but the damage will have
already been done.
42 www.linuxvoice.com
DDOS FAQ
This form of amplification allows a
fairly modest collection of computers to
exert a huge force on a server.
An alternative is to work smart
instead of hard. In this, you don’t
overwhelm the server with so much
data that it can’t function, but you use
data such that a small amount can do a
very large amount of damage.
Perhaps the most famous attack of
this kind is the SYN flood. Whenever
you start a connection to a web server,
you do a three-way handshake. This is a
simple way of establishing a TCP
connection over which you can send
and receive data. It has three steps.
Firstly you send a SYN packet to the
server, then the server responds with a
SYN-ACK packet, then finally, you
respond to that with an ACK packet.
A SYN flood abuses this process. The www.digitalattackmap.com shows a live feed of DDOS attacks, and can replay big ones from the past.
attacking computers send loads of SYN
packets with the IP address spoofed. Hang on; people are setting up some structure, and different
The server then responds with a botnets to target their connections have more bandwidth than
SYN-ACK packet, but it doesn’t respond competition? That’s a bit extreme! others. The key to mitigating a network
to the malicious computer’s IP, instead Actually no (well, a few people volume attack is to block it before it
it send it to the spoofed IP. This probably are). You can rent gets to a bottleneck. This means
computer won’t respond, because it botnets set up for DDOS attacks, or pay adjusting the filtering rules on routers at
didn’t send the SYN packet. people to do the DDOS for you. It’s the data centre, or sometimes even at
However, the server will hold this becoming quite a large industry. internet exchange level.
half-open TCP connection while it waits If it’s some other form of attack, it
for a response. This half-open Wow. That’s scary. How bad means making sure that you don’t
connection will lock up some of the can these attacks be? waste resources on malicious packets,
resources of the server. If there are That really depends on how you and again, this means identifying them
enough of them, even if the network define ‘bad’. They can quite easily and filtering them out before they do
isn’t overloaded, the server will stop cripple even quite large operations. damage. Sometimes you can do this at
accepting new TCP connections. These days, a moderate volumeteric server level, but it often means getting
These are examples – there are attack is measured in gigabits per help from the people running the
many more ways to lock up resources second, a large one in tens of gigabits datacentre or your internet connection.
and stop a server working properly. per second, and a huge one in hundreds
of gigabits per second. Once they get to But my server isn’t in some
But why do it? What’s in it for that size, they can be pretty damaging. fancy datacentre. Is there
the attackers? Another way of looking at it is how anything else I can do?
That varies. The most famous long they last. The largest attacks burn There is another way, and that’s
attacks have been politically themselves out, because few people to route all your traffic through a
motivated and were a show of force to can sustain that level of bandwidth for very high bandwidth router that does
try and punish organisations that the long. However, experience shows that the filtering and sends on the
attackers felt were harming them. For there are botnets capable of sustaining appropriate requests with the malicious
example, you may remember large attacks for several days or longer, traffic filtered out. While this may sound
Anonymous’s DDOS attacks on which is long enough to dent the exactly the same as the option above,
financial institutions that refused to do finances of a web-based company. the difference is that the router doesn’t
business with Wikileaks. have to be physically between your
One increasing area is digital What can you do to stop these server and the internet.
extortion. In this, some internet bandits from happening? This is known as a scrubbing centre,
launch a DDOS attack against a site, If (for example) you’re under a and it’s part of what a content delivery
and then tell the site that they’ll only DNS amplification attack, you network (CDN) does (there’s much
stop the attack if the site pays. need to filter out all the rogue DNS more as well). There are a few that you
Other times, it’s a business trying to packets, but you need to do this as far can use without having to change the
cripple a competitor, or just bored geeks upstream as possible. The internet isn’t way you host your site, such as
with a grudge. There are lots of reasons. just a randomly connected web; it has CloudFlare, Incapsula, and SkyFaster.
www.linuxvoice.com 43
INTERVIEW DAMIAN CONWAY
DAMIAN
CONWAY
We meet the creator of a programming language
based on Klingon and one of the architects of
Perl 6. If only we could tell them apart…
D
amian Conway is one of the and has run courses on everything
Guardians of Perl (our term) from Regular Expressions for
and one of Perl 6’s chief Bioinformatics to Presentation Aikido
architects. But he’s chiefly a computer (and of course, lots of Perl). Which
scientist, a brilliant communicator is why, when we discovered he was
and an educator. His presentations making a keynote at this year’s QCon
are often worth crossing continents conference in London in March, we
for. He was the Adjunct Associate braved train delays and the sardine
Professor in the Faculty of Information travelling classes of the London
Technology at Melbourne’s Monash Underground to meet him opposite
University between 2001 and 2010, Westminster Abbey.
“Programming doesn’t
The main reason we wanted to But it can be. There was pride have to be complicated.
talk to you is that we want to
try to simplify people’s experience of
in the Perl community when
you showed the Turing machine
The problems we solve are
programming and computers. John running in this much [gesticulation complicated, but the basic
Horton Conway said recently that to show a tiny thing] code.
tools of programming are
not complicated things.”
his Game of Life is the blight of his Damian: Sure, but that’s a game. To
life because he had gone on to do so me, that’s just that I make this happen
much more interesting and in that kind of way. It’s been very
important work. But what struck us interesting for me. I’ve recently been
by what he said about the attraction starting to put together classes on Perl
to the game is its simplicity and the 6, the new language in the Perl family. It’s insane, for example, that in Perl 5,
fact that that goes on to teach And the thing about Perl 6 is that it just until the release that’s probably coming
things that you could not possibly feels like it’s a lot more polished and out in May, we haven’t had parameter
imagine. So with that in mind, is smooth than Perl 5 ever was. lists. Now this is an advanced
there something like that for I mean, I love Perl 5 dearly, I do technology that was pioneered, what,
programming, how does that fit with almost all my work in Perl 5, but Perl 6 60 years ago, and we still haven’t got
Perl, and is Perl for people that think has all of the same features but with them. And so everyone who’s writing
like that in the first place? the rough edges kind of knocked off of subroutines in Perl spends most of their
Damian: That is a huge question! There them. And what it gives you is the same time simulating the behaviour
is almost an industry in making thing that Perl 5 has always given, necessary for a parameter list. So
programming seem more difficult than which is exactly the right tools to do the finally, with Perl 5.20 coming out this
it is. Programming doesn’t have to be job you want to do and not get in your year, we have parameter lists.
really complicated. The problems we way. What I find when I change to Every language that I code in, I find
solve are complicated, and at the scale programming in JavaScript or C++ or C♯ these issues. A really good one is, this
we have to code things become is that the language itself gets in the afternoon I’m talking about regular
complicated, but the basic tools of way of my using the language. expressions, and I went through 20
programming are not complicated I spend all my time coding around different languages that supply regular
things. And learning the patterns of use either limitations in the language or a expression mechanisms. And in about
of those tools that work, that scale, that particular mindset that makes you do it 18 of them, the regular expression
are robust, reliable and maintainable, in one particular way, and that’s equally mechanism is bolted on the side, so
isn’t really that difficult. This is really not true in Perl 5 on occasion. Perl 5 has you can’t write a regular expression, you
rocket science. This is not quantum got real deficiencies that are only just, in have to write a string, which then gets
mechanics. This is not that difficult. this very year, finally being addressed. translated into a regular expression.
44 www.linuxvoice.com
DAMIAN CONWAY INTERVIEW
And that irritation leads to mistakes too. noise. And the thing about Perl is, in the components are. And I find that equally
You don’t put the right number of very early design of Perl, a decision was true in Python, which is a lovely
backslashes in, ’cause it’s a string, and made that there would be lots of language and has many many benefits.
you’ve got to backslash all the syntactic differentiation. In most But to me, in Python, everything looks
backslashes to get a single backslash. programming languages, there’s only a like a method call, because everything
relatively small amount of syntax. There is a method call. Losing that syntactic
But, to many of us, Perl looks are identifiers, there are a couple of distinction makes it really really hard for
like a regular expression. operators and there’s probably a me to pick up on what’s going on.
Damian: [laughs] Yeah, but this is kind method call mechanism, and then we Now, the problem with that is that it
of the same thing. If I had just gotten up do everything with that. only works if you know the distinction in
on stage this morning and just shown In Lisp it’s even more extreme. In Lisp the syntax. So people coming into Perl
you Klingon sentences without there’s just comments and atoms, get lost in this sea of ampersands and
explaining the structure of them, the basically. But in Perl the decision was stars and all sorts of other symbols that
syntax of them and how they come made very early on that we would use we use in the language. And until you
together, then it would just look like line as much of the keyboard as possible, get past and it sort of goes into your
noise. Alphabetic line noise, but line so that once you knew what a particular hind brain and it just translates
element in the Perl syntax meant, it immediately, ‘ah yes, that’s a scalar
would stand out for you immediately. variable’, ‘ah yes, that’s a type blah, blah,
“In most programming So when I read Lisp, and I can read Lisp
and write Lisp, and I’ve taught Lisp, but
blah’, it doesn’t make sense. It looks like
line noise, and I fully agree.
languages there’s a relatively there’s always this mental gear shift
small amount of syntax.” that has to go on because the language
isn’t helping me see what the different
So do you think it’s better for
people who want to learn
www.linuxvoice.com 45
INTERVIEW DAMIAN CONWAY
Lefkowitz on the subject, he thought
that programming is at a similar
stage to when spaces were
introduced between words in Latin
script, which opened up reading to
more people. And, similarly, stirrups
were fundamental to the feudal
system because they enabled riders
to wield a sword and shield.
Damian: Or the zero in the number
system.
Yes, exactly. So is that a
relevant question for Perl, or is
it better suited to Python or
JavaScript, say, and should we just
be teaching people concepts before
we teach abstraction?
Damian: Wow!
Sorry, I’ve had too much coffee
this morning.
Damian: No, these are fantastic and
deep and important questions. Let’s go
back to the very beginning. Anyone who
“Never settle for just being a Perl
believes you can teach programming in
programmer or just being a Java
programmer or just being whatever.” an hour has no idea about what
programming is. I think that I finally
thought that I was a confident
programming to dive into Perl was. But the key is always the same. programmer maybe about four or five
straight away? You have to give them a way of years ago, so after about a quarter of a
Damian: I don’t think it is. To be focusing on one level of abstraction at a century of coding. I felt that I was an
perfectly honest, I think Perl 5 at least is time. And so the more syntax that the ordinary good programmer by that
a lousy first language. And the reason I language that they’re using has, the stage. I don’t think you can even teach
think that is that learning to program harder it is for them to focus on the HTML in an hour, to be brutally honest.
isn’t just about learning syntax. It’s level of what does this mean, what
about learning at six or seven different does it do and how do I make it do what That’s one of the very
levels at the same time. So the purely I want. I think from that point of view examples they gave.
lexical level of what character do I type there have been many CS programs Damian: No, no. So there’s a
here, the syntactic level of what that over time that have taught Lisp as their fundamental misunderstanding about
means, the semantic level of what does first language. I think, in one sense, how complicated a task it is that we do
the construct that this represents that’s a really good thing, because I can when we do programming and how
mean, the algorithmic level of how do I tell you the syntax of Lisp in three quickly one ought to be able to do that
put these things together to make minutes, and from then on it’s just task. And I think we do a disservice if
things work… for me it’s like when I was trying to understand how the we try and throw people in at the deep
learning to juggle or to drive a car or any mechanisms work and how the end. And a lot of language choices
other complicated multi-level activity. If algorithms work. throw people in the deep end. I would,
you think about learning to drive a car, So I don’t think Perl 5 is a good for example, put JavaScript or Java in
it’s not just about how do I steer or how language for that. I think Perl 6 is a that same category.
do I push the accelerator pedal, it’s also better language because Perl 6 doesn’t If you try to teach people Java, just
about how aware I am on the road, how need as much syntax to get the basic think about the Java ‘Hello World’
I’m aware of what the car is doing, how stuff done. There’s of acres of syntax in program, you see it online all the time.
do I anticipate what’s happening next, the background but you don’t need it The Java ‘Hello World’ program has a
how do I navigate at the same time and early on. class declaration and then it has a
how do I listen to the radio as well. And method declaration, it has the loading
for me, coding is exactly like that. The UK government has of libraries that make the thing work, it
For nearly a decade, I taught the decreed this year as the Year then has the method call chain to
introductory programming class at our of Code. Its representative said that actually do that. And in order to even
university, and I was forced to teach it in it was possible to learn some code understand the presumably simplest of
C and C++ and Java and whatever it in an hour. Talking to Robert all programs, you have to understand
46 www.linuxvoice.com
DAMIAN CONWAY INTERVIEW
Java at about four different levels of about the abstractions of how to the one way of JavaScript, or of Java, or
abstraction. You have to understand a express this series of instructions C♯, or C++ or anything. I think the
lot of very sophisticated concepts, clearly and unambiguously. In Perl or important thing is that if you want to
including things as simple as what’s the Perl 6, Hello World is literally “say ‘Hello become an experienced programmer,
difference between static and non- World’”. The thing is, I can teach you need to be exposed to an
static. Now, a lot of good programmers someone to do that in 30 seconds, not enormously wide range of ways of
would not be able to tell you what the an hour, and I can go from there if I’m thinking about coding. You need to be
difference between static and non-static very very careful about what I introduce exposed to functional programming
really is. So, a language like that, which them to next. There are other systems and imperative programming
is often touted as being a relatively languages where you don’t have to be systems and object-oriented
simple language, actually isn’t. quite as careful because there just programming systems and declarative
aren’t that many constructs, and they programming systems and concurrent
“Anyone who believes you can have pitfalls as well.
What’s important is that we do need
programming systems. Because it’s
only by opening up your mind to these
teach programming in an hour good programmers, we do need people different views on the same reality that
has no idea about programming.” who can do this stuff, because our
entire society will utterly fall apart if we
you really see.
It’s like back in the early days of
do not have people that can maintain physics where everyone either just
So you can just dive in a our software. We are not a society that thought of light as particles or just as
change things? can survive if our software goes down. waves, and there was this enormous
Damian: Yeah, and that’s what people But to think that we can teach them in fight over which one is it. Well, the
do. They don’t learn to program, they an hour, or a day, or a week, or a month answer is both. And is programming a
learn to evolve or mutate existing or even a year, or the three years of the purely functional activity or a purely
programs, and that’s not the same skill standard program, is highly optimistic. object-oriented activity or a purely
set. And, frankly, a lot of Perl developers imperative activity or a declarative
are like that as well. Their only exposure Does that mean that, in some activity? It’s all of them. And what I try
to Perl is in existing large-scale scripts way, computer science has to do in all of the syllabuses that I ever
on which their entire organisation failed if we still want people to put together and what I try to do for
depends. And all that they’re asked to become expert scientists, when the myself in my own ongoing learning is
do is go in and make a small change to future promised us some pseudo- find new ways of thinking about what it
that. They’re not asked to develop, to code that we could just transfer our is that I do. How can I do functional
design, to build, to implement. It’s thoughts to the computer? programming in C, for example? How
strictly about “let’s twiddle”. Damian: Yes. The future promised us a do I do object orientation in C? Well you
When you’re looking for a language to lot of things, didn’t it! I’m still waiting for can do that it. It’s not easy, but you can
actually get people up and running, you my flying car. do it. So, for me, it doesn’t matter what
need a language that doesn’t get in But should programming become a tool I’m looking at, what I want to know
their way, that allows them to think commodity? Eventually, for a large is how can I think of this problem in a
number of people, it will be. We will find way that makes the solution obvious
ways whereby people can set up their and simple and correct and robust. And
environments and have the behaviour often that’s just I need to look at it
they want. But there’s a fundamental entirely differently. And so what I would
mistake there in thinking things that are encourage every young programmer,
that complicated can be reduced down and every old programmer as well, is
to something so simple. never give up.
Look at the new languages that are
Considering the context of the coming out. Look at the Clojures, and
conversation, what do you the Scalas and the Darts and the Gos,
think is the ideal path? Is there an and all of the different languages that
ideal language to start with? How are constantly coming up. See what
would you recommend people get they have to give you in the way of
started if you want to take them to insights about what programming
Perl nirvana? actually is. Because the only way you’re
Damian: Perl nirvana! I can probably going to eventually understand what
only go by my own path and by the this elephant looks like is if you feel the
paths that I’ve shown to my of students various parts of it individually and
over time. And for me, the most realise that they are simply parts of a
important thing was diversity. Not being greater whole.
“Ruby on Rails makes it possible for
stuck thinking this is one way that we
not very strong developers to build
fairly sophisticated systems.” code. And I don’t care if it’s the one way Brilliant. Thanks Damian.
of Python, or the one way of Ruby, or Damian: My pleasure.
www.linuxvoice.com 47
LISTEN TO THE PODCAST
WWW.LINUXVOICE.COM
72
INTRO REVIEWS
REVIEWS
The latest software and hardware for your Linux box, reviewed
and rated by the most experienced writers in the business
On test this issue...
50 52
Andrew Gregory
//ART NOTE//Please run the shave and haircut
filter over this photo//END NOTE///
L
ast week, I fixed my mum’s
laptop. Being of adequate
intelligence with a good standard
of linguistic comprehension I can
Bitwig Studio 1.0 Gnome 3.12
normally muddle through most IT fixes, We say it often, but this really is a game- If you have a shiny new Dell XPS 13 and
but this question (non-functioning changer. Audio editing and production on you need a desktop to take advantage of
wireless, which had apparently turned Linux just got deliciously better. your lovely pixel density, try this.
itself off) had me stumped. Google
eventually told me that you can get a
Start menu in Windows 8 by pressing 53 54 55
the WIndows key and X together, which
is appalling – not since the early days
of Gnome 3 have we seen such a silly,
non-intuitive way to perform an
essential function.
If you need an instructional video
telling your users how to turn a Udoo Roundcube 1.0 Pibrella
machine off (http://windows.
Four times the power of a The convenience of Gmail A big red button, a buzzer
microsoft.com/en-gb/windows-8/
Raspberry Pi, at around 3.5 without the ads or NSA and three LEDs for Pi
how-shut-down-turn-off-pc), there’s
times the price. Value? surveillance. Email bliss. hacking. What’s not to like?
something seriously wrong with your
design. At least with Linux, users have a
choice, and a voice, and developers
have to listen very quickly unless they BOOKS AND GROUP TEST
want to see their projects abandoned.
Touchscreens are the future. I know, because Tom
Gnome 3 came very close to irrelevance
Cruise told me so in Minority Report, and a Mexican
last year, but Darwinian inevitability has friend of ours still makes swishing noises and waves
driven the project to improve. Fixes are his hands about any time he’s trying to convey
implemented quickly, rather than anything futuristic. You too can be just like Tom
grudgingly as with Microsoft’s belated Cruise by using a touchscreen Linux – just read our
Group Test first to find out which one’s right for you.
restoration of the Start menu. Gnome 3
Books are the past. I know, because self-appointed
is back to where it was: a usable media ‘experts’ keep telling me. Still, they remain a
desktop for anyone. I just need to popular medium for information – none more so than
persuade my mum to start using it. the excellent Learning Python with Raspberry Pi.
andrew@linuxvoice.com
www.linuxvoice.com 49
REVIEWS BITWIG STUDIO 1.0
Bitwig Studio 1.0
Graham Morrison pulls himself out of rapture to write not nearly as many words as
he wanted to.
T
his is a day-one Linux release of a market With our i5 CPU, the Pro 40 and the Jack audio
DATA changing desktop music composition layer, we got ultra-low latencies of 2.9ms running with
Web
application. On Apple’s OS X and Microsoft a Frames/Period buffer of 64. That was fast enough
www.bitwig.com Windows, Bitwig Studio is causing a stir because it for realtime effects processing and monitoring on
Developer implements a similar workflow to an industry incoming audio, plus MIDI software synthesiser
Bitwig GmbH standard, Ableton Live. Instead of creating music by playback, without any hint of latency, at least to our
Price recording onto tracks, an arrangement is created by ears. A slightly larger buffer did significantly reduce
£259.99
recording a sequence of triggered loops of audio and the CPU overhead of polling the audio interface, which
MIDI, often live and augmented with bucketloads of we’d recommend if your CPU is a few years old. We
effects, automation and processing. also tested latency on the Dell XPS 13’s internal audio,
There’s simply nothing like this for Linux. Bitwig and found it perfectly acceptable for playback, being
Studio is a refined, minimally styled and powerful in the region of 12ms, making Bitwig and Linux a great
application. It’s capable of full-blown music production gigging combination.
and is a joy to work with. It’s occasionally frustrating The brilliant thing about Bitwig Studio is that it
and slightly unstable – mostly because this is the features an arrangement view and a clip view that can
first release – but it’s constantly capable of the kind be opened side-by-side. The arrangement view is how
of audio gymnastics that a certain kind of music Audacity, Ardour, Rosegarden, Cubase, Cakewalk,
producer can’t live without. Apple’s Logic and countless others manage their
multitrack productions. Each track of MIDI or audio is
Jack your body a different horizontal bar on the screen, and a mixer
The only officially supported Linux platform is Ubuntu view usually handles effect sends and processing for
12.04 LTS, which is unambitious but understandable. each track. The clip view is where you create loops of
You can activate up to three installations, the idea either audio or MIDI, putting variations on the same
Partner packages provide
an instant hit of sounds being that you have a workstation at the studio and a track and arranged into groups you want triggered at
that can be dragged and laptop for travel, and you can activate an instance for the same time.
dropped into your own a single session, which is useful if you’re using Thanks to Jack, we found the process of creating
compositions. someone else’s machine. audio input and output channels, send and return
THE BITWIG INTERFACE
Transport control Clip view Arrangement Browser
Play, rewind, record, Uniquely, Bitwig Traditional DAW All instruments, clips, loops
and enable the can place the clips functional for audio, and effects are accessible
various latch modes alongside the MIDI and hybrid through a single panel. You
for controlling the arrangement view. tracks. can also build your own
application with collection of sounds and
remote hardware. presets and access them
from here.
Channel inspector Device panel
Colorise and Create chains of devices
manage device made up from instruments
assignment for and effects then control
each channel, as their parameters using your
well as the effects mouse or an external MIDI
sends, volume and device. It’s also possible to
channel I/O. script your own controllers.
Edit mode
Switch between the Sound preview
arrangement, clip Listen to clips, sounds
and edit views and and instruments through
create screen sets. separate output.
50 www.linuxvoice.com
BITWIG STUDIO 1.0 REVIEWS
Hardware configuration
Bitwig Studio enabled us to make best use of our audio
hardware by allowing us to create virtual inputs and output
that pointed to their hardware counterparts. We would have
appreciated some input monitoring to make assignments
without the guesswork, but reassignments could be done
without starting the audio engine.
MIDI was picked up and handled automatically, but you
have to create a generic MIDI device to handle standard USB
ports before they’ll work. We’ve also got two MIDI controllers
– a Behringer BC2000 and BCF2000. These are devices with
lots of knobs and sliders, and Bitwig Studio comes with two
patches that can be loaded into both to allow you to control
the application remotely.
With the MIDI devices enabled, one of Bitwig’s best
features is its remote control provision. You can right-click
on almost any control on the screen and then move a remote
MIDI controller to make a quick and easy assignment. This
is perfect for adjusting the equaliser without looking at the
screen, for example, or turning the BCR2000 into a hardware
controller for the built-in synth, and it obviously helps when it Our audio device has 20 individual inputs and outputs,
comes to creating a clip-launching environment, which many but Bitwig is able to make sense of this configuration
performers will want to do for their live work. with only a little help from us.
effects channels, external instruments and MIDI Alongside the samples, the loops, drum kits and
surprisingly straightforward. Tracks can be armed for effects, there’s also a small selection of virtual
recording and enabled for input monitoring. When instruments. There’s a lovely analogue-styled
recording and editing loops, the markers used to polyphonic synth, a four operator FM synth, several
delineate duration and loop points were intuitive and drum sound generators and a drawbar organ, all with
easy to modify. The pitch-shifting algorithm sounds a considerable amount of control. Combined with the
good, though maybe not that creative at extremes. We effects modularity, you can create both bread-and-
missed MIDI recording quantisation, but post- butter sounds and more experimental timbres. But
recording quantisation worked well, and the this is where we hit the biggest problem for this first
automation control on tracks was brilliant, right down release – Bitwig only supports plugins compiled
to the per-note level for built-in devices. against Steinberg’s VST API, even on Linux. This is
good for VST
Wired for sound
Bitwig Studio comes with a lot of sounds, instrument
developers who want
to create cross- “If you have any interest in
and effects devices, all navigable through a context platform versions of music composition or production,
you need to try the demo.”
search enabled browser panel on the right of each their instruments and
view. We don’t particularly enjoy the building block effects, but not so
approach to creating music, where bass, drums and good for native Linux
melody loops are dragged into the clip view to be developers. We’d love to see LV2 supported in a future
reconstituted into a new piece of music, but it works release, without having to go through Jack re-routing
well in Bitwig, and you’ll be plundering commercial hoops, and can we also ask for a loop-building effects
sample banks and libraries before you can say plugin and a way of filtering MIDI input by channel?
‘Rhythm Is A Dancer’. We’ve barely scratched the surface. All we can say is
Far better for us were the drum machine and synth that there’s nothing like Bitwig Studio on Linux. If you
samples, which can be used to construct your own have any interest in music composition or production,
kits using a drum kit device or quickly added to your you need to try out the demo. It is relatively expensive
project as a pre-built configuration. Every drum in a kit (though not compared with its competitor), but it’s the
can have its own send control and dynamism, and result of many years of beta testing and development.
you often find you can unfold instruments to reveal From a music production perspective, Bitwig feels like,
further parameters, and you can fold racks together in finally, Linux has come in from the cold.
the same way. We found the remaining sounds a little
uninspiring, but as karma dictates you should build LINUX VOICE VERDICT
everything from the ground-up using your own loops
Amazing. A top-tier audio workstation
and samples in the comprehensive sampler device, released for Linux. Look out for a
this isn’t problem for us. We’re also certain that it Paldandy gig near you.
won’t be long before Bitwig’s community starts
sharing sound packs.
www.linuxvoice.com 51
REVIEWS GNOME 3.12
Gnome 3.12
Do you have a shiny touchscreen laptop? Ben Everard thinks
he may have found the right desktop environment for you.
G
nome 3.12 is the latest stable incarnation of has received an overhaul and is getting closer in terms
DATA the Gnome 3 desktop environment, which of function to the Ubuntu Software Centre, which in
Web
includes the Gnome Shell desktop and a range our opinion is the best of such applications for Linux.
www.gnome.org of core applications, most of which have seen some It still has a little way to go, but it’s looking good so far.
Developer form of improvement. Support for high resolution (HiDPI) screens is
The Gnome Project One of these integrated apps is the Videos significantly better than in 3.10, and it’s certainly worth
Price application, which has been given a thoroughly taking a look at if you’re struggling to get the best out
Free under the GPL
modern look with floating controls and links to online of your expensive monitor. This comes as the Gnome
video sources. In fact, integration with online services team have been doing excellent work in making the
seems to be a focus point for the Gnome team at the desktop look more beautiful. We may even go so far
moment. Support for the Pocket app, which is a way as to say that Gnome 3.12 has the most attractive
for users to save online content for later perusal, has default state of any Linux desktop.
been added in a number of places, and Photos now
supports importing pictures from online sources such Tip-top for tablets
as Facebook. Using the Gnome 3 live CD released by the Gnome
foundation should be the best way to try out the
Better integration desktop environment. However, unfortunately we
It seemed to take a long time to migrate the Gedit text found it a terrible experience. It completely crashed on
editor from the old Gnome 2.x style to Gnome 3, but us on several occasions forcing a reboot. Hopefully
it’s there now. This means it fits in better with the rest this won’t be an issue once it’s made its way onto
of Gnome 3 and users of the mainstream distros, but we can’t yet say for sure.
“Gnome 3.12 has the most
desktop environment should Gnome 3 divided opinion on its release. This
feel more at home in it. Of reviewer really didn’t like Gnome 3 when it first came
attractive default state of course, it does mean that out, but it’s now maturing into a usable system. It’s at
any Linux desktop.”
Gedit now looks out of place its best on touchscreen devices (desktops and
on other desktop laptops rather than tablets and phones), which might
environments, but as it’s part seem a little excessive now but given the large
of the Gnome suite, we can’t really criticise it for that. proportion of computers selling now with touch
The Gnome lust for simple names has really screens, it’s good to see that one Linux desktop
Application folders in
Gnome 3.12 could herald reached a zenith (or nadir, depending on your point of environment is taking on the challenge.
the start of a shift back to view) with the naming Software. This isn’t a generic Of course, the majority of Linux machines still have
a hierarchical application term for the stuff that runs on your computer; instead traditional non-touch screens. The Gnome team have
menu. it’s the name of the Gnome software centre, which managed to create a desktop that works well with
both mouse and touch. Unfortunately, it’s usually
compared to desktops that work really well on one or
the other (such as Cinnamon with a mouse or Android
with touch). Those have both had a head start, but
Gnome 3 is catching up in both areas. For some
people, it’s already the best option and we can see
why, but none of us at Linux Voice are quite impressed
enough to make the switch yet. Everything still seems
to take one or two more clicks than it does on other
desktops, and that’s still enough to put us off.
However, it has reached the stage where we’re now
considering it as an option, and that’s something we
didn’t think would happen when Gnome 3 came out.
LINUX VOICE VERDICT
Gnome 3.12 doesn’t contain enough
to persuade us to switch, but users
will appreciate the improvements.
52 www.linuxvoice.com
REVIEWS UDOO
Udoo
You do like small ARM computers? So does everyone
these days, it seems, including Ben Everard.
T
he Udoo is a small ARM-based machine that
runs Linux (both traditional desktop Linux and
Android), and has some programmable input/
output pins exposed. If that sounds familiar, it’s
because that’s exactly what the Raspberry Pi is. The
Pi has proven extremely popular, but for all its uses, it’s
a little lacking in hardware grunt. That’s the niche that
the Udoo is aimed at: simple, accessible Linux-based
hacking, on a board that packs a little more punch
than its fruit-based counterpart.
The CPU is a quad-core 1GHz ARM v7 (a dual-core
version is also available). See the box below for
benchmarks – these show that each of the Udoo’s
cores is more powerful than the Raspberry Pi on its
own. While benchmarks provide quantitative data,
qualitative data about computer performance is harder
to capture. The Udoo has enough power to make the
desktop feel snappy, and tasks that swamp the Pi (like
browsing JavaScript-heavy websites or unzipping separately). Network access is accounted for with An Udoo is almost
packages) are handled with relative ease. Put simply, it Wi-Fi and Gigbit Ethernet on the Quad-core version. exactly twice the size of a
feels an order of magnitude quicker than the Pi. The extra power of the Udoo comes at a cost. It’s Raspberry Pi, and it packs
many more connectors
However, it’s still no match for most x86 machines. more expensive, bigger and draws more power than
into that space.
The Udoo uses a separate microcontroller to handle the Pi. All of these make it a significantly worse option
the inputs and outputs. In fact, the microcontroller and for projects where the board will be included into the
pin layout is identical to the Arduino Due, with 76 IOs project physically.
including 12 analogue inputs and two analogue
outputs. However, unlike most Arduino boards, the Desktop replacement?
Due (and Udoo) use 3.3 volts rather than 5, so The comparison to the Pi, though, is a bit unfair. The
hardware designed for 5V boards won’t work. Udoo is more than three times the cost, and while it is
Connectivity doesn’t just come in the form of IO still cheap compared to a PC at around £110
pins: the Udoo also has a SATA connector (quad-core (including taxes and shipping to the UK), that takes it DATA
version only) to allow regular hard drives to connect; out of the impulse buy range for many people. Web
an LVDS connector for touchscreens (especially good Boards like the Udoo live or die based on whether www.udoo.org
if you want to build your own tablet – Udoo sells they get enough mindshare. If there are plenty of Developer
7- and 15-inch screens); and a USB OTG connection. It tutorials and books available, it becomes easy to work SECO USA Ltd and Adilab
also has a camera connection (camera module sold around the limitations and compromises that are Price
€73–99
essential to all small board computers. If they don’t,
using them becomes more hassle than not. A quick
Udoo vs RPi performance Google search brings up about 40,000 results for
Benchmark Udoo RPi normal RPi max overclocked ‘Udoo tutorial’, compared with 180,000 for
‘Beaglebone tutorial’ and over seven million for
Blowfish 47.43 99.00 68.58
‘Raspberry Pi tutorial’. That’s a lot less, but then the
Cryptohash 22.39 9.07 13.28 *
Udoo is the youngest of the three. The Udoo website
Fibbonachi 11.49 26.07 18.16
explicitly pitches it as a competitor to the Raspberry
N Queens 41.64 84.97 69.07 Pi, and it’s hard to ignore that, but we can definitely
FFT 48.94 149.16 101.19 see a useful future for this device on its own merits.
Raytracing 49.02 130.38 89.84
LINUX VOICE VERDICT
Hardinfo benchmarks. This compares a single core
of the four-core Udoo against the only core on the The Udoo is good value for money
Raspberry Pi. if you’re ready for a home hacking
board with more power than a Pi.
* More is better. For all others, less is better
www.linuxvoice.com 53
REVIEWS MAIL IN A BROWSER
Roundcube 1.0
How well does this webmail client fare against desktop apps?
Mike Saunders investigates.
I
n the early 2000s, webmail used to be regarded as
DATA pretty rubbish compared to desktop applications.
Web
Searching facilities were limited, the interfaces
www.roundcube.net were slow and clumsy, and you couldn’t read your
Developer mail when you were disconnected. Then Google Mail
Roundcube team came along and changed everything: it was fast, had
Price excellent searching capabilities, and its Ajax-heavy
Free (open source
licences)
interface made it feel somewhat like a native app
But for all its strengths, Google Mail is closed
source and proprietary. If you want to implement your
own webmail system, you’ll need an alternative – and
one of the best is Roundcube. Here at Linux Voice HQ,
we’ve been using Roundcube extensively for the last
few months, pushing it to the limits from different If you’re not a fan of the stock dark theme, a lighter (and
corners of Europe. Now version 1.0 has finally arrived, more retro looking) alternative is available.
so what does it have to offer?
Fortunately, installation is straightforward: the main was a doddle – we were up and running in seconds.
requirements are a web server (eg Apache) with PHP On the whole, the installation is impressively quick and
enabled. With the files in place and the right polished, so Roundcube scores full points here.
permissions set, we pointed our web browser at the
installer/ directory, Interface and docs
“Installation is impressively
which guided us By and large, Roundcube works like a typical desktop
effortlessly through the mail client: there’s a folder list down the left, message
quick and polished, so setup process. list on the right, and a toolbar on top (with buttons for
Roundcube scores points here.”
Roundcube can use composing, deleting, marking as unread) and so forth.
MySQL to store its The interface doesn’t make much use of large
data, or SQLite as an displays by default, though, as you have to double-
easier-to-set-up alternative. click a message to view it. But via Settings > Mailbox
This is how Roundcube Because Roundcube is just a webmail client, and View > Show Preview Pane you can see the contents
looks with the Preview not a complete solution with a mail transfer agent, you of messages from the main screen.
Pane enabled; otherwise need to point it to an IMAP server for retrieving Feature-wise, Roundcube includes: decent search
you just get a message list messages, along with an SMTP server for sending. facilities (based on subject, from, message body and
in the default setup. Configuring the client to talk to Google’s mail servers other fields); spell checking; drag-and-drop for moving
messages between folders; both plain text and HTML
composition; and an address book that can import
contacts in vCard and CSV formats, or hook up to an
LDAP server. It has pretty much everything you’d need
in a desktop client, and a plugin system is available for
some bolt-on features.
What lets Roundcube down, however, is its
documentation. For an end user, it’s pretty bad and
limited to some scraps of information on the project’s
wiki. There’s no comprehensive handbook or getting
started guide – and this caught us out when trying to
enable certain features. It’s a shame, because
otherwise Roundcube is a superb piece of work.
LINUX VOICE VERDICT
Easy to install, polished and loaded
with impressive features – but the
lack of documentation is a problem.
54 www.linuxvoice.com
REVIEWS PIBRELLA
Pimoroni & Cyntech Pibrella
No, it has nothing to do with Rihanna, but Les Pounder
lets us stand under his Pibrella… ella
P
imoroni, the Sheffield-based company of
makers and tinkerers, has become the place DATA
to go to for Raspberry Pi-related kit. Fresh Web
from the success of its popular PiGlow add-on board http://pibrella.com
comes the new kid on the block: the Pibrella, which Developer
is a partnership with Cyntech Components, the Pimoroni vs Cyntech
company behind the Raspberry Pi logo-shaped hub. Price
£10
The Pibrella is a simple add-on board that is placed
on to the GPIO pins of the Raspberry Pi, and provides
the user with extra methods of input and output. At
first glance you can easily see two forms of output in
the shape of a red, a yellow and a green LED, as well You can use the Pibrella’s extra IO methods to create
as one buzzer. There’s also a big red button that looks simple projects such as traffic lights or a reaction timer.
as though it’s come from the leftovers of a nuclear
decommissioning programme. to use, and it really helps newcomers quickly hack
If you look a little closer you’ll see two banks of together a project with minimal fuss.
female connections on either side of the button.
The left bank provides four extra methods of input, Python library
whereas the right bank provides four methods of The board itself is simple to use. By importing the
output. These extra IO ports provide you with an easy library into your Python code, you can easily turn lights
way to extend the functionality of the Pibrella via the on and off by colour using a simple line of code, so to
use of sensors and motors. turn the red light on and off you can use pibrella.light.
Pibrella can be used with two programming red.on() and pibrella.light.red.off(). The library also
languages – Python and Scratch – using Simon provides ingenious ways to make LEDs blink and use
Walters’ ScratchGPIO (http://cymplecy.wordpress. pulse width modulation (PWM) to create a fading
com). Pibrella comes with its own Python library effect. The use of the
courtesy of Pimoroni’s GitHub repo (https://github.
com/pimoroni/pibrella). The library is a sheer delight
extra IO ports is also
handled via the library, “Pibrella can be used via
and when a port is in two programming languages
use the corresponding
LED is lit up to indicate – Python and Scratch.”
as such, enabling you
to quickly diagnose any faults.
It’s possible to connect motors, servos and
solenoids to the Pibrella, but they require a little more
power than a standard Raspberry Pi can provide –
have no fear though, as the team have considered this
issue and incorporated a separate micro USB port to
provide the additional power.
The Pibrella is the answer to a lot of our problems.
It provides an easy-to-use device that enables anyone
to create fun projects in Python and Scratch. The
expansion possibilities are tremendous, and we
can see this board becoming very popular indeed –
particularly in education, as it will easily slot into the
UK’s secondary school curriculum.
LINUX VOICE VERDICT
The right features for all levels of
users coupled with the right price
makes this a must-have piece of kit.
There’s easily £10 worth of weekend hardware hacking
packed into this little Raspberry Pi add-on.
www.linuxvoice.com 55
REVIEWS BOOKS
Learning Python with Raspberry Pi
Graham Morrison absolutely hates this book. It’s rubbish. Honestly.
F
irst, a little disclosure. We have a For us, this is the best way of learning a
vested interest in the failure of this language, because there’s very little theory
book. Its co-author, Ben Everard, is without an example, and as a reader, you
a co-founder of this very magazine. He’s want to expand upon what you’ve learnt.
one of its most technical, most entertaining Each new concept comes as part of a
and most erudite authors. If this book is a project that teaches you something about
success, he’s going to want to write another, the Raspberry Pi; develop your own web
and another, and another. He’ll no longer browser, write a platform game, generate
have time to sew LEDs into his bike jacket, OpenGL 3D graphics and script Minecraft.
or brew alcoholic ginger beer, or cycle Later chapters deal with networking,
across minefields. Before we know it, he’ll hardware interfaces and debugging,
be packing his bags and jumping on the first basically covering every aspect to
stage coach out of the Shire to make his programming in Python without labouring
fortune in Wolverhampton. And Linux Voice in theory or too much detail. Each chapter
will have lost one of its best contributors. finishes with some suggestions for taking
Despite all this, we can’t help but admit things further, and sometimes a few
that Learning Python With Raspberry Pi exercises, as well as a summary of what’s
has its moments. To start with, it hits the been covered. Even if you’ve never done
potential target audience straight on the any programming before, you should find
head; you’ve bought your first Raspberry everything easy to follow, and we also think
Pi, you want to start using it for your own the book will work well if you go through the
projects. Python is to the Raspberry Pi what examples with an older child, for example, or Whatever you do, don’t buy this book.
BASIC was to Acorn’s BBC. It’s the lingua as part of a Python and Pi primer course.
franca of the Pi generation, which we know wishing the authors had written more, which
isn’t a coincidence. Lousy food, and such small portions we suppose leaves open the potential for
Python has a similar immediacy to BASIC, If there’s a criticism, it’s that we think the slightly more advanced sequel.
and rewards experimentation. It’s fun and book could go further. It won’t take too
it’s forgiving. And like the Pi itself, Python long to work your way through its 270 Don’t give up the day job
can scale far beyond humble beginnings. pages, and there’s perhaps a little too much Until now, there wasn’t an easy, entertaining
Just take a look at our guide to controlling emphasis on gaming. But it’s something of and educational resource that would do
virtualisation (p94), or Ben’s own tutorial a compliment to say you want each chapter justice to the pairing of Python and the
on genetic algorithms (p104) – both use to give you more. It’s not enough to write a Raspberry Pi. It’s perhaps no coincidence
Python because it’s the best tool for the job. speech recognition program in 10 lines of that one of the early chapters in this book
Python may flatter by starting off simple, but code - we want to spend Friday evenings deals with Turtle graphics. We fondly
there’s no limit to where the language might chatting politics with our Raspberry Pi! We remember getting an Acorn Electron in the
take you. want to play chess! We want more than a early 80s, and it came with two books – one
paragraph on robots! was Start Programming with the Electron,
The (very) few good bits It also ends quite abruptly, and while both and the other was entitled Turtle Graphics.
We love the way the book jumps straight the internet and this very magazine are full Together they encapsulated the same sense
into practical examples, forgoing the of new projects to try, we can’t help but feel a of wonder and exploration as Ben and Alex’s
ceremonial respect usually given by little sympathy for the Python beginner who book, nurturing a new generation of coders
describing a language by its syntax and dutifully works their way through the book in the process. This book might do the same.
conditional statements. Within the first two only to be dumped unceremoniously out of Just don’t tell Ben.
dozen pages, you’re writing code that does the end with little more than a link to
stuff and draws things on screen, while http://docs.python.org/3 for comfort.
at the same time, teaching you essential
concepts about programming. We can only
But really, we only wrote that section
to inject a little pseudo objectivity into the
LINUX VOICE VERDICT
imagine this was Alex Bradbury’s idea. review. What we want from a book like Author Alex Bradbury and Ben Everard
It’s also the way the majority of the book this is for it to pique your interest without Publisher Wiley
ISBN 978-1-118-71705-9
continues. Any theory is always backed up scaring you off, and to capture the essence
Price £17.99/US $29.99/CAN $35.99
by practical examples, which slowly get of what both the Raspberry Pi and Python
An excellent book for beginners to both the
more advanced as they dive into more and are capable of. Learning Python With Raspberry Pi and the Python language.
more of the Raspberry Pi’s potential. Raspberry Pi does both and leaves you
56 www.linuxvoice.com
REVIEWS BOOKS
Nine algorithms that changed the future:
The ingenious ideas that drive today’s computers ALSO RELEASED…
Ben Everard wonders if all nine are required to look at Facebook.
T
his book is written to bring the
idea of algorithms to the masses.
Without assuming any computing
knowledge, John MacCormick takes the
reader through nine algorithms such as Learn all about
PageRank, Zip compression, and digital Ethernet and
signatures in just over two hundred pages. give yourself
How does John
To achieve this the book simplifies – a job security
MacCormick know
lot – and sometimes it just changes for life.
that the future’s been
algorithms to suit his purpose. For changed? Ethernet: The Definitive Guide
example, the chapter on public key Cities, airports and rail stations are so often
cryptography actually deals with the Diffie- even a slight interest in computing. judged on their free WiFi, but the backbone to
Hellman key exchange, which is private As an introduction to a fascinating all networking is still Ethernet and that’s not
about to change. Good job that its definitive
key cryptography. subject, though, it’s great.
guide has just had an upgrade then, and the
Nine Algorithms… tries hard to deliver 2nd edition should be a great bit of research.
a simple description of how algorithms LINUX VOICE VERDICT
work to a non-technical audience. In Author John MacCormick
this aim, it succeeds. It walks the reader Publisher Princeton University Press
through the algorithm and explains their ISBN 978-0-691-15819-9
Price £11.95
basic function in a very readable manner
An easy to read introduction to algorithms
without challenging the reader much. for a non-technical audience
However, the writing is so overtly non-
technical that it’s off-putting to people with
Scrum: the
chance to
A Female Genius: How Ada Lovelace, laugh at co-
workers every
single day.
Lord Byron’s daughter, started the computer age
Testing in Scrum
Ben Everard is building a difference engine out of papier maché. Agile is one of those ideas that seems to have
found itself into all kinds of management
T
structures, regardless of whether they have
his is a book about Ada Lovelace anything to do with development. This is book
the person, not her contributions promises practical help on testing and QA, and
to computer science. This isn’t includes several case studies. Now sit down.
a criticism, just a fact that we feel needs
Ada Lovelace was
stating, especially as the subtitle How Ada
simply a genius. It’s a
Lovelace, Lord Byron’s Daughter, Started
little unfortunate that
the Computer Age implies otherwise. It this book feels the
actually covers almost everything about need to qualify this
her life other than the technical details of with the adjective
her work. ‘female’.
Linux Voice readers, of course, will Linux is
already be well versed in the mathematical considered – this isn’t a book for people everywhere.
aspects of her life from a tutorial in issue like that. We, however, enjoyed it greatly. Unfortunately,
1, so this book is the perfect companion KDE has yet to
follow.
to that. It chronicles her life from a baby LINUX VOICE VERDICT
growing up in the shadow of her father’s Author James Essinger Designing Multi-Device Experiences
scandalous life, to her untimely death. Publisher Gibson Square These days, we expect our web experience to
In doing this, it adds some colour and ISBN 9781908096067 be similar to the supporting app experience,
Price £14.99
context to the cold, dry mathematics for which is similar again to the desktop
A thorough exploration of the Countess of experience on all platforms. That’s a tough
which she is most famous. Lovelace’s life, this book tells the story of challenge, and this book promises a practical
Some people may feel that the details of how the computer age almost started early.
approach to developing your own framework.
a scientist’s life aren’t important, and only
their contribution to the subject should be
www.linuxvoice.com 57
GROUP TEST TOUCH DESKTOPS
TOUCH
DESKTOPS
GROUP TEST
Graham Morrison and his trusty touch laptop explore
the cutting edge of Linux desktops.
On Test Touch Desktops
Don’t let your touchscreen go to waste.
Unity
T
URL www.ubuntu.com his is a technology that is work best. The third reason is that
Version 7.1.2 still on the very cutting edge the touch interfaces of Apple’s iOS
Licence L/GPL v3 of what Linux desktops can and Google’s Android have shaken
Promised touch do – desktops designed to be used up the old launch menu and file
enhancements didn’t make with a touchscreen. There are management desktop metaphor,
it into 14.04, but does several important reasons why and many newer Linux desktops
Unity still do enough? have incorporated some of their
we’re doing this now, rather than
Gnome waiting an indeterminate amount of
time for the technology to mature.
features already.
Even if they’re not designed
URL www.gnome.org The first is that it’s fun. New specifically for touching, it’s good
Version 3.9
technology, and new ways of to know whether the new style of
Licence L/GPL
Gnome looks a little like interacting with it, is exciting, and design works with new hardware,
Unity, but without the Linux is going to have to find a way or whether touch gets in the way.
tablet and smartphone to work with touch. The second Which is exactly the challenge we’ve
emphasis. important reason is that the set ourselves for this group test.
technology is already here, not just We spent a few weeks with our
Plasma Active in the form of Android tablets, but multi-boot system playing with
URL http://plasma- increasingly in our laptops. Thanks each desktop as we would a
active.org to Microsoft’s emphasis on touch desktop in a real production
Version 4 for Windows 8, many new laptops environment. That meant we
(from Kubuntu daily) now come with a touchscreen by missed the latest Gnome release
Licence GPL default, and if you install Linux on (see p52 for our review), but it also
It’s KDE with added touch one of these devices, you’ll want meant we took a pretty ruthless
and less KDE. view on whether touch worked.
to know which desktop is going to
KDE
URL www.kde.org “New technology, and new ways of
interacting with it, is fun.”
Version 4.13 beta
(Kubuntu)
Licence L/GPL
It’s KDE.
THE CRUCIAL CRITERIA
Our target is the standard x86 PC, rather specifically for touch, the borrow heavily
than pure touch devices. We’re using from the full-screen design of Android
Android x86 Dell’s XPS 13, as reviewed last issue and iOS. We can also look at Android
and as lent to us by www.apt-net.co.uk itself. The latest x86 release of Android
URL www.android-x86.org
(thanks Alan!). 4.4 works brilliantly and offers the
Version 4.4 RC1 As such, any desktop can be made other side of the touch coin – a touch
Licence Apache 2 to work with a touchscreen, but we’re desktop shoehorned into a laptop. For
It’s just like the phone and not going to look at every desktop. the others, we’re going to use a base
tablet OS, only it’s running We’re going to pick those we’ve found of Ubuntu as this ensures hardware
off your laptop. to be the most effective. Gnome 3.x and configuration isn’t the differentiator –
Ubuntu’s Unity are two obvious choices, only the way the desktops are designed
because while they’re not designed to interact with touch input.
58 www.linuxvoice.com
TOUCH DESKTOPS GROUP TEST
Installation and Touch
configuration input
Working at the cutting edge isn’t always easy. You’ve got the touch.
T
he Android-x86 build has come a
long way since we first tried it a
couple of years ago. It might initially
seem counter-intuitive to install something
designed for tablets onto what is essentially
a touchscreen laptop, but we really enjoyed
the results. It’s like a very fast Nexus with
built in keyboard. All the gestures from your
smartphone work instantly, from sliding down
notifications, or swiping across desktops,
to pinch zoom, rotation with no further
configuration. It’s tough to write about Android
as a legitimate alternative to a more traditional
Linux distribution, but if it brings extended
functionality to your touchscreen and you
enjoy using it, we don’t see the problem. It’s
Plasma Active is tricky to install on x86. We used Unetbootin and a recent Kubuntu daily image. still Linux.
Second to Android this time is Unity. This is
T
he Plasma Active and Android and it worked amazingly well from there, because it does some sensible things to take
desktops we’re looking at are so including both multitouch from the screen, into account the touch input. You can scroll up
cutting-edge that they can’t be keyboard control and WiFi (an important and down lists, for example, resize a window
installed in the way you may be used to. consideration for Android), as well as with three fingers and the cursor is hidden
Not only that, you’re going to need a more touch control when needed. when you touch the screen. Those features
traditional Linux distribution installed For other desktops, the challenge is alone put it in a different class. Plasma Active
alongside for those times when you don’t getting the touchscreen to work well, as is pretty good, as you’d imagine, and KDE is
want to be dealing with what are ‘works in most will be able to use touch as a mouse acceptable, but not without modifications.
progress’. You won’t have these problems cursor. The best strategy is to find the very Gnome running off both Fedora 20 and
with Unity, Gnome or KDE, but it is latest version of a distribution, as this will Ubuntu almost manages it. But only some
something you have to deal with when include the latest drivers. This approach window title bars register a touch, leaving
installing Plasma Active and Android, as worked for the Haswell XPS 13 for all the certain windows unable to move without
both are different to most Linux desktops. distributions and desktops we tried, resorting to the touchpad.
Plasma Active is best described as a especially as the XPS 13 Developer Edition
remix of KDE for touchscreens. But it’s not originally shipped with Ubuntu 12.04, but
just a skin. It takes over the entire system this will also depend on your hardware.
and doesn’t work particularly well installed Our touchscreen presents itself to the
alongside other KDE Plasma workspaces system as a multitouch Synaptic
(as they’re called), at least not in the way touchpad, which means it works out of the
it’s currently distributed. box. But this can also add complications if
you’re using a genuine Synaptic touchpad
Needs attention alongside the screen. When you combine
Plasma Active in general suffers from a these two aspects together, Ubuntu’s Unity
lack of love, despite early success, and it’s is the only desktop to have taken both the
a struggle to find a working configuration. installation and configuration into
As such, installation is best done through consideration, by its nature, with Android Android comes closest to just working.
a custom Kubuntu re-spin, or by adding coming a close second.
package repositories to vanilla Ubuntu or VERDICT
OpenSUSE. We went for the Kubuntu spin VERDICT Android
Unity
written to a USB stick before committing it Android Gnome
Unity KDE
to a section of the hard drive. Similarly, we Gnome Plasma Active
KDE
dropped the USB image of Android 4.4 Plasma Active
onto a USB stick booting with Easy2Boot,
www.linuxvoice.com 59
GROUP TEST TOUCH DESKTOPS
Customisation Usability
If it’s not great, just what can Does a touchscreen actually add anything?
H
you do to make things better? ere’s the rub (sorry!) – just our conclusion is that a touchscreen
because your hardware has a can genuinely help in some very specific
The point of this group test is to see which touchscreen, it doesn’t mean cases, and the amount that they help
desktop environments have implemented you should feel duty-bound to use it. If is down to the desktop. In Android, for
features that best work with touch. But it’s you are going to use it, the desktop has example, a gesture to open the settings
also possible to change a great deal about to make it worthwhile. We have used makes a lot of sense. And Unity is
how they look and behave even if they don’t touch and keyboard devices for a few obviously working on phones. But that’s
support touch. KDE comes out best because months, especially when travelling, and where all the others need most work.
there’s just so much you can change. You can
dramatically increase the width of the
scrollbars making them much easier to grab Android
and move with your fingers. You can change Not surprisingly, Android excels at touch. touchpad (it works!). And using the
the size of the title bar, and replace the icons After all, input has been designed around computer in this way is quicker and more
with much more finger-friendly options. fingers rather than mouse and keyboard efficient than doing similar gestures the
A cut-down number of options is also input. But what most surprised us is that it old fashioned way, or even though a
available to Plasma Active users. Android is feels very natural behind a laptop launcher such as Gnome Do. As a laptop
seriously restricted by not running traditional form-factor. You find yourself operating system, it feels much more
Linux applications, but this can be helped a automatically launching apps and swiping mature than Chrome/Chromium OS.
little by using an open source repository such through running processes by touching Though we’re loath to use the word,
as F-Droid, or dual-booting your machine. the screen, while at the same time using there’s some synergy between the
Gnome has plenty of plugins and themes that the keyboard or even reverting to the touchscreen and the keyboard.
can help, while there’s not too much you can
change in Unity.
Plasma Active also has a complete set of
widgets that can be added to a specifically
designed fullscreen background. These
widgets, like the ones you find in Android,
Android x86’s cutting-edge
are a great way of creating something of the nature means not everything
tablet experience with a Linux desktop, and works – Netflix, for example.
they work well with touch and the widescreen But the touch experience is
form factor. We should also be able to pull second to none.
down a task manager in Plasma Active, but in
the three different x86 installations we tried,
this doesn’t work. Instead, we had to rely on KDE
KRunner to launch and configure the desktop. By default, most things in KDE are small. launching an application associated with
In Unity, however, swiping down over the This makes them difficult to use from a a file is useful, and KDE is perhaps the
top-right corner of the display was enough touchscreen. Clicking on an app to launch strongest desktop when it comes to
to reveal the options of whatever icon we from the menu is difficult, for example, configuration options. You can change
happened to touch. This was probably a side and resizing windows is almost almost anything about the desktop to
effect of touching the icon, but it’s very similar impossible, although moving windows is make it more touch friendly. But perhaps
in behaviour to the latest Ubuntu Touch builds slightly easier and is the only mouse because it’s an area the KDE team might
running on phones, where you can slide function with any touch advantage feel is covered by Plasma Active,
down and horizontally to switch between potential. The single-click option for concessions to touch in KDE are very few.
the settings for those widgets running. Unity
definitely has the best potential, and we just
hope that the work that’s gone into the mobile
version isn’t lost on x86 users, even if it’s
through a third-party repository.
VERDICT
Android
Unity
Gnome Without customisation, the
KDE
Plasma Active touch KDE experience is
difficult and clunky. You’re
better off with a mouse.
60 www.linuxvoice.com
TOUCH DESKTOPS GROUP TEST
Touch
Unity 14.04
Hitting the scroll bars at the side of the resize it using large anchor points or
Unity desktop is a problem, as too is maximise and minimise without any
potential
resizing a window from the bottom right difficulty. Tap three fingers and you can
corner. However, one of Unity’s best switch applications. A four finger tap will
features is multitouch support, and this open the dash or bring the launcher back
works on the screen. Place three fingers from a hidden state. These gestures
on a window and you can move it around, transform Unity’s touch possibilities.
Can touch help you do more?
This is going to depend on what you need to
do. Android, for instance, is hobbled by not
being a traditional Linux distribution. You can’t
install many of the applications you may be
used to, and many tasks are impossible. There
are no tools for specific kinds of software
Most icons in Unity are large development, or 3D animation, or any number
enough to prod, especially of other tasks. But there are many everyday
when it comes to restarting or tasks such as web browsing, writing words,
shutting down your machine. staying on top of emails and playing Angry
Birds that are arguably better accomplished
on Android that on a Linux desktop.
Plasma Active Even the Rotate Screen feature was useful,
There are many things to like about comprehensive as Unity’s multitouch as it was a perfect way of proofing pages for
Plasma Active. It’s the only big Linux support. The large widgets you can place this very magazine. We’d love to see an
desktop, bar Android, to have been on the background can go some way to Android mash-up where you had X11 desktop
designed for touch devices, so it has the make Plasma Active feel like Android, and functionality and package compatibility.
potential to be the best of both worlds. By there’s a primitive settings dialog that However, touch on other desktops can be
default, window management is easy presents its options in large, slidable more productive. Web browsing in Plasma
thanks to the large icons and scroll bars, controllers. There’s a customised version Active, file management and app launching
although there’s nothing as of KDE’s web browser too. from Unity, and cursor placement in all of
them makes a touchscreen worthwhile.
Plasma Active has a lock screen designed
for touch, so you can easily slide open the
screen when you want to resume a session.
Android does the same, obviously, but it feels
like the right thing to do – much better than
Plasma Active has plenty
of potential, but a lack of flicking the Caps Lock on the keyboard, which
development is holding it is what we usually do to resume a sleeping
back from being a usable laptop. The problem with Plasma Active is
desktop. that everything is just too half-finished to be
useful. Which is disappointing, because when
we tried earlier versions actually running on a
Gnome tablet, usability was top-notch. The problem
Gnome has some of the advantages of changing the theme, and Gnome is really we had then was with performance and
Unity, thanks to its launcher and panel. missing the multitouch features of Unity, efficiency, not usability, while running on an
Applications and icons are easy to locate, but it’s better than KDE because the shell ARM CPU.
and the application launcher view, along makes more sense from a touch Gnome had a problem where we couldn’t
with its containers for other applications, perspective. Thanks to the click zones move the settings windows with the touch
is an excellent mechanism for navigating being up against the edge of the top panel, screen. This might have been a hardware
to the tools you want to run. It’s difficult to you can also swipe down on the screen to issue, but as we experienced the same
close and resize windows without do things like logout or open the settings. problem on both Fedora and Ubuntu, it might
be a deeper issue with the different ways
Gnome handles window management, or it
might be interpreting touch differently.
VERDICT
Android
Unity
Gnome is hampered by some Gnome
KDE
of the window borders not Plasma Active
working in the same way that
others do.
www.linuxvoice.com 61
GROUP TEST TOUCH DESKTOPS
Productivity
Is touch a gimmick, or can it help you do real work?
D
uring the course of this and the the chances are you want to do some
previous issue, we spent a serious computing with it, so while
considerable period of time Android is great at certain mobile-
with each desktop, doing the stuff that friendly jobs, it wouldn’t be our desert
we normally do. We wanted to see island desktop.
whether the presence of a touchscreen
would change the way we interact with Multitouch FTW
the Linux desktop. Thanks to its multitouch support, the
We’ve probably written more words issues of resizing and moving windows
about Android in this group test than don’t affect Unity, as you can just push Android made a shockingly good, and surprisingly
we have about the other desktops, and three fingers across the screen to do productive, laptop operating system.
that’s because Android has surprised what needs to be done. The same
us by being remarkably productive. configuration can be made to work with hardly worth buying a laptop with a
When you pull it out of the CPU- and other desktops, but that requires some touchscreen for. Finally, there’s Plasma
memory-restrictive environment of a tinkering. One slight hitch might be Active. The biggest problem we had
smartphone or a tablet, and put it onto whether multitouch makes its way to with this was stability, so while some
a fully fledged Intel Core i7 CPU with the Mir display server, but considering aspects were better than other
8GB of RAM, it flies. Canonical’s big push on mobile and desktops – such as the browser and
Of course, the problem is that it’s only tablets, it’s more likely that touch will settings support – we couldn’t rely on
going to be good for certain tasks. In get better rather than worse for future the desktop enough to do any real work.
particular, it doesn’t make much sense versions of Unity. Our time was better spent trying to
when you can pick up a tablet for very We were able to work with both KDE make KDE look more like Plasma Active.
little money in comparison to a laptop. and Gnome, but these desktops were
It’s not a stable operating system, and used almost 99% of the time through VERDICT
has quite specific hardware the mouse and keyboard, reverting to Android
Unity
requirements, so it’s not going to be a touch only for cursor placement and Gnome
KDE
good choice for most people. If you’re occasionally to launch an app or editor Plasma Active
using a computer with a touchscreen, in KDE. It’s still better than nothing, but
Third-party support
Can we make the touch experience more accessible?
T
here are many things you the shell. It was touch enabled without
can do to make any of these any further modification and can be
desktops more friendly to latched onto the edge of the screen.
touch. Gnome, Unity and KDE can It also has some useful features such
quickly improve the touch experience as snippets and typing assistance/
in Firefox by installing the ‘Grab & Drag’ auto-correction. The keyboard can also Ubuntu does a great job at making touchscreen input a
extension, for example. This replaces be hidden automatically, and quickly central part of its desktop experience.
Firefox’s default action of left-click brought back to life by keeping a
text selection with a hand that grabs hovering icon on-screen. real keyboard beneath the display, we
and scrolls the web page. It can even We also liked Gnome’s ‘Florence’ found an on-screen keyboard to be
add momentum for the full tablet keyboard . It’s scalable, has a almost essential for some tasks. Finally,
experience, and there’s simple support touchscreen input mode, and you we’d describe KDE’s own on-screen
for page up and page down gestures. can clearly see when you’ve hit the keyboard as functional rather than
This extension alone transforms the key you’re aiming for thanks to the useful for touchscreen users.
non-Android desktops. Even an on- focus zoom feature. Both Florence
screen keyboard can help, when you and Onboard can be set to have a VERDICT
don’t want to move your hand down to transparency, so they don’t have to Android
Unity
the keyboard. get in the way of the remainder of the Gnome
KDE
Our favourite was Ubuntu’s, which display, and while it may sound slightly Plasma Active
can be launched by typing onboard in crazy when there’s a perfectly usable
62 www.linuxvoice.com
TOUCH DESKTOPS GROUP TEST
OUR VERDICT
Touch desktops
T
ouch hasn’t changed our had to check to make sure it was
desktops in the way we still being developed. There’s no Unity is still easily the best Linux desktop for a touchscreen.
thought it might, but touch easy way to install it, and very little
input is something developers and
users still need to consider.
documentation on using it. It could
be a great initiative, but unless
1st Unity
Licence GPL & LGPL v3 Version 7.1.2
Microsoft, for example, got things there’s some reason for developers
spectacularly wrong with its unified to get behind it – such as Aaron www.ubuntu.com
touch interface with Windows 8, Siego’s wonderful Spark tablet idea Ubuntu is perhaps the distribution with the greatest motivation
backtracking to a more traditional – it’s not going to happen. to make touch a central part of its desktop. And it shows.
appearance with each update. The KDE comes next, although a
open source community has taken properly configured KDE desktop 2nd Android x86
a more pragmatic and sober for Linux would score higher. This Licence Apache 2 Version 4.13 beta (Kubuntu)
approach, which we think has paid result is purely because there’s very
off, despite early versions of both little evidence of any changes being www.kde.org
Gnome 3.x and Unity seemingly made to accommodate touch. Next We loved Android on a laptop. If only there were a way of
installing the applications we’re more used to, it would win.
“The Unity launcher, on-screen keyboard 3rd KDE
and panel all work well with touch.” Licence GPL & LGPL Version 4.13 beta (Kubuntu)
embracing the idea. Touch isn’t comes Gnome. Finding and www.kde.org
Just pulls ahead of Gnome because it’s more configurable, and
going to change the desktop launching applications is good, as
when you make the scrollbars large, it’s very usable.
overnight, but nor is it going to be a too is the on-screen keyboard, but
passing fad. The technology is there are some gotchas – such as
seeping into standard PC/laptop/ some of the windows not 4th Gnome
hardware, and Microsoft’s hardware responding in the same way to Licence GPL & LGPL Version 3.9
partners are determined to push for touch control.
www.gnome.org
more tablet/PC convergence. As Despite our falling for Android
Despite looking like Unity, there’s no particular touch
such, there’s still a long way to go x86 4.4, we’ve only ranked it consideration in the GUI, but it has lots of potential.
for the Linux desktop to be second. This is because Android
considered touch friendly. x86 has no crossover with a
We had highest hopes for traditional Linux distro. Unity wins
5th Plasma Active
Plasma Active, because it seems to because there were no big Licence GPL Version 4 (from Kubuntu daily)
be the only mainstream based problems, the launcher, on-screen http://plasma-active.org
Linux desktop taking touch keyboard and panel all work well We feel bad putting this last. We’ve used a build on an ARM
seriously. But so little has happened with touch, and the multitouch tablet that worked brilliantly, but x86 is lacking love.
over the last 12 months that we module makes all the difference.
YOU MAY ALSO WISH TO TRY…
Any Linux desktop is going to be malleable didn’t make them part of this group test. operating system and we spent a
enough to work with a touch interface. They Google recently announced a new considerable about of time getting this to
can all be configured to use larger buttons, or Chromebook, the Acer C720P, and it comes work on the XPS 13. As almost everything is
place large launch icons in places that fingers with a touchscreen. It’s running Google’s own browser based, touch helps when scrolling
will find easier to hit. Mate and Cinnamon, for browser-centric Chrome OS, an OS that falls around and hitting links, but doesn’t offer
example, both work well in out tests, as into the same category as Android for being anything beyond Firefox with a touch plugin,
would XFCE. But there’s nothing specifically non-standard in the way other Linux desktops but it may be worth a try if Android has given
touch friendly about them, which is why we are. But there is an open source build of the you a taste of cutting-edge touch desktops.
www.linuxvoice.com 63
SUBSCRIBE
SUBSCRIBE shop.linuxvoice.com
Not all Linux magazines are the same
Introducing Linux Voice,
the magazine that:
Gives 50% of its profits
back to Free Software
Licenses its content
CC-BY-SA within 9 months
12-month subs prices
UK – £55
Europe – £85
US/Canada – £95
ROW – £99
7-month subs prices
UK – £38 DIGITAL
Europe – £53 SUBSCRIPTION
US/Canada – £55 ONLY £38
ROW – £60
Each month Linux Voice includes 114 pages of in-depth tutorials,
features, interviews and reviews, all written by the most
experienced journalists in the business.
Payment is in Pounds Sterling. 12-month subscribers will receive 12 issues of Linux Voice a year. 7-month
subscribers will receive 7 issue of Linux Voice. If you are dissatisfied in any way you can write to us to cancel your
subscription at subscriptions@linuxvoice.com and we will refund you for all unmailed issues.
64 www.linuxvoice.com
NEXT MONTH
NEXT MONTH IN
EVEN MORE AWESOME!
ON SALE
THURSDAY Old Code
29 MAY Random numbers,
DNA, nuclear
weapons, the first
reprogrammable
computer and more
– John von
Neumann had his
fingers in many pies.
Life on Mars
Build a Mars Rover
with a Raspberry Pi*;
seek out new words
and civilisations.
(*This is an artist’s
impression of Ben’s
Mars Rover.)
No speako lingo
THE BEST UBUNTU RESPIN Internationalisation
is a massive reason
for Linux adoption
The world’s favourite Linux distro has – get involved,
evolved to the next level. We look at the spin- translate something
and quite literally
offs that have grown up and flown the nest – spread the word.
Kubuntu, Elementary OS, Trisquel and more.
LINUX VOICE IS BROUGHT TO YOU BY
Editor Graham Morrison Editorial consultant Nick Veitch through the use of advice in this magazine. Copyright Linux is a trademark of Linus
graham@linuxvoice.com nick@linuxvoice.com Experiment with Linux at your own risk! Torvalds, and is used with permission.
Deputy editor Andrew Gregory Distributed by Marketforce (UK) Ltd, Blue Anything in this magazine may not be
andrew@linuxvoice.com All code printed in this magazine is licensed Fin Building, 110 Southwark Street, London, reproduced without permission of the
Technical editor Ben Everard under the GNU GPLv3 SE1 0SU editor, until January 2015 when all content
ben@linuxvoice.com Tel: +44 (0) 20 3148 3300 (including images) is re-licensed CC-BY-SA.
Editor at large Mike Saunders Printed in the UK by ©Linux Voice Ltd 2014
mike@linuxvoice.com Acorn Web Offset Ltd Circulation Marketing by Intermedia Brand ISSN 2054-3778
Creative director Stacey Black Marketing Ltd, registered office North Quay
stacey@linuxvoice.com Disclaimer We accept no liabiliy for any House, Sutton Harbour, Plymouth PL4 0RA Subscribe: shop.linuxvoice.com
loss of data or damage to your hardware Tel: 01737 852166 subscriptions@linuxvoice.com
www.linuxvoice.com
SYSADMIN
SYSADMIN
System administration technologies brought to you from the coalface of Linux.
Jonathan Roberts
dropped out of an MA
in Theology to work
Btrfs
with Linux. A Fedora The filesystem that’s better (or butter) in so many ways.
advocate and systems
I
administrator, we hear
n our third and final look at new performance and stability on real, albeit
his calming tones
whenever we’re stuck technologies making their way to Linux, easily recoverable, workloads.
with something hard. we’re going to explore Btrfs (which in This anecdotal support from distributions
my head I’m pronouncing butter-eff-ess). and large production environments, along
Among developers, ‘test driven Btrfs is a new copy-on-write filesystem for with the official wiki claiming that the on-disk
development’ has become trendy once Linux, which aims to deliver advanced format is now stable, suggests that if you
more. It’s certainly not a new idea, as
features such as volume management, want to start testing, now is the time to do
similar practices are described in The
snapshots, checksums and send/receive so. It might not be making its way in to the
Mythical Man Month, which was originally
published in 1975, but it is as popular now of subvolumes. next round of enterprise distribution releases
as it has ever been. If you’re not already a filesystem expert, as default, but it will be there for those users
The idea is simple. Developers write many of those terms might sound alien to who really need it.
automated tests to check that functions you, but continue reading and we’ll do our So, if you want to try some of the features
and features they’ve implemented work. best to explain what these features do, why we’ll describe in the rest of this article, make
Usually, these tests take the form of you want them, and when you’ll get them. sure you have automatic and tested
simple functions that call the code to be backups running. Do that, and even if the
tested, and compare the output to an Stability ‘experimental’ status of Btrfs does lead to
expected value, using an assert statement Let’s start with that final question, as any data loss, you won’t be left cursing.
or similar. If the expected and actual value
one who’s paid even a little attention to news
match, the test passes; if they’re different,
the test fails.
about Btrfs has heard horror stories about it Getting started
In TDD, this is taken one step further, destroying data and may well think it’s a long With that word on stability out of the way,
and advocates argue that the developer way from production. let’s get to work and create a new Btrfs
should first write a failing test for the As it stands now, OpenSUSE plans to be filesystem. Once we have the filesystem in
function they’re about to implement, and the first major distribution to use it by place, we’ll start working through some of its
then they can keep working until it passes. default in its November 13.2 release, core features, showing what they do, why
What’s this got to do with system indicating that they believe it’s stable enough they’re great and how to use them.
administration? Well, I would argue that for daily use. Facebook, too, which has For our simple experiments, we’re going to
operations teams should take a similar recently hired many Btrfs developers, has use some plain files mounted as loop
approach when building out the announced plans to begin using Btrfs in its devices. So, to start, first create an empty
infrastructure for a new product.
production web tier, where it can test 3GB file, use losetup to create a new loop
Tests can take the form of checks in
monitoring software such as Check_MK or
Nagios. Ensure that, after your provisioning
servers, your monitoring server is the first
thing you install. Then, for each subsequent
server to be installed, first add it and all
necessary checks (process checks for
Apache, MySQL server status checks etc)
to your monitoring software.
Then you can begin building it. At first,
all the checks will be red. But as you boot
it, and then run your configuration
management recipes, you’ll see check
after check turn green. If any stay red by
the time Puppet etc has finished, you
know you need to tweak your recipes.
Creating a btrfs filesystem is just like any other – easy. In this tutorial, we’ve used loopback
mounts to experiment, but this would all work just as well on a real disk .
66 www.linuxvoice.com
SYSADMIN
device, and then create a new Btrfs
filesystem:
dd if=/dev/zero of=/home/jon/btrfs1 bs=1024
count=3072000
losetup /dev/loop0 /home/jon/btrfs1
mkfs.btrfs /dev/loop0
That’s all there is to it. You can then mount
/dev/loop0 as you would any other
filesystem, examine it with tools like df etc.
As with any filesystem, there are a host of
options you can specify at mount time to Some of the tools you’ve used in the past, such as df, won’t take into account metadata and other
change the way that it works. With Btrfs, one features of Btrfs, so it has its own tools, such as btrfs filesystem df /path (the substitute for df).
useful option is compress, which enables
you to turn on compression using either zlib changes, making them fast to create and striped across a pair of drives, which is in
or lzo: remove as well as extremely space efficient. turn mirrored to another pair of drives.
mount -o compress=lzo /dev/loop0 /mnt/btrfs What really makes subvolumes useful, Aims to give the benefits of RAID 0 and 1.
While compression brings the obvious however, is that you can mount individual RAID 5 and 6 Stripe data, as in RAID 0, but
advantage of letting you store more data on subvolumes without mounting their parent. sacrifice some space for ‘parity’
disk, in some circumstances it can also First, list all of the subvolumes in your Btrfs information. This parity information allows
bring a performance benefit too. On most volumes to find out their ‘subvolume IDs’: the array to lose one disk in RAID 5 or two
systems without solid state storage, there btrfs subvolume list /mnt/btrfs disks in RAID 6.
are often CPU cycles to spare, while disk I/O Then, assuming the ss-images snapshot To set up a multi-device Btrfs filesystem
can be a real bottleneck. By asking the disks created above has volume id 258, umount like this, first create a second loop device:
to pull back less data, but asking the CPU to the Btrfs filesystem before remounting with dd if=/dev/zero of=/home/jon/btrfs2 bs=1024
do some more work uncompressing that the following options: count=3072000
data, you can improve your performance. mount -o subvolumeid=258 /dev/loop0 /mnt/btrfs losetup /dev/loop1 /home/jon/btrfs2
When you list the contents of /mnt/btrfs, Then use the mkfs.btrfs command again,
Subvolumes you’ll only see the contents of that but with the following options:
Now that you have a Btrfs filesystem subvolume. This feature is particularly mkfs.btrfs -d raid0 /dev/loop0 /dev/loop1
available, let’s look at the second (after important because it means, for example, You can check the man page for mkfs.
transparent compression) feature of you can snapshot your root volume before btrfs to see other options for the -d switch.
interest: subvolumes. A Btrfs filesystem can
be divided into multiple roots that can each
be treated as a filesystem in its own right
“A Btrfs filesystem can be divided into roots that
(unlike logical volumes, these independent can each be treated as a filesystem in its own right.”
roots are not separate block devices):
btrfs subvolume create /mnt/btrfs/images an upgrade, and if things go awry, remount
If you inspect the mounted filesystem at the snapshot as your root and get back to a Self healing
this point, you’ll see what appears to be a working state straight away. We’re close to the end of this month’s
new directory. You can cd in to it, you can overview, and there’s so much we haven’t
create files within it etc. What happens, Multiple volumes touched on – file cloning, filesystem
however, if you try to create a hard link As well as having these LVM-like features, mirroring with send/receive, online
between a file in this subvolume and the Btrfs also shares features with traditional rebalancing (aka changing RAID levels) and
parent btrfs file volume? RAID, too. A Btrfs filesystem can be spread much more. Before finishing this month’s
ln /mnt/btrfs/images/screen1.png /mnt/btrfs/ across multiple devices, and you can section, there’s one other aspect of Btrfs
screen1.png configure it to distribute the data across the that I’d like to draw to your attention: Btrfs
That operation fails, just as if you’d tried to devices according to one of several aims to be self healing.
create a hard link between two different common RAID levels: Btrfs records checksums for each block
mount points. RAID 0 Striping, in which data is striped that it writes. When it reads the data, it
OK, so what can you do with subvolumes? across disks, leading to improved read compares the data to its checksum, and if
Well, when creating a subvolume, you can and write speeds. Btrfs also supports an there’s a difference, it automatically tries to
make it a snapshot of another Btrfs volume: extension of RAID 0 in which disks do not re-read the data from one of your redundant
btrfs subvolume snapshot /mnt/btrfs/images /mnt/ have to be the same size, known as copies or parity information – eg if you’re
btrfs/ss-images ‘single’. using RAID1/10, 5 or 6 and Btrfs reads a bad
Because Btrfs is a copy-on-write RAID 1 Mirroring, in which data is block, you’d never know it happened unless
filesystem, this snapshot could be an exact mirrored across two or more disks of the you were to take a look in the logs.
replica of a 300GB filesystem and it would same size. Can be faster for reads, but That’s all we have space for, but I hope
still have been created instantly. Btrfs only will slow down writes, as data has to be you’ll start thinking about all you could do
needs to copy data when information in the written twice. with Btrfs when it does eventually hit your
snapshot or the original volume actually RAID 10 Mirrored striped, in which data is favourite distribution.
www.linuxvoice.com 67
CLOUDADMIN
CLOUDADMIN
Running make-believe boxes is virtually compulsory, suggests Nick Veitch.
Virtualisation: the options
There are many shades of hypervisor.
V
irtualisation is a key technology that included in the mainline kernel. The software
helped give birth to the modern relies on kernel modules to interface with the
cloud as we understand it. It helps host CPU’s virtualisation extensions – as
run the services on the cloud and often such it will only run on CPUs that support
helps build clouds too. But virtualisation is (for example) Intel VT or AMD-V extensions
also important to developing tools to run (there is also an ARM port).
clouds. As our foray into the ‘dev’ part of Popularity of KVM has not been driven by
devops has already led us to look at how the desktop – it still lacks a lot of the snazzy
continuous integration is used (see LV002) configuration tools of VirtualBox – but it is
we should also take a look at the very very popular for ‘serious’ use due to
virtualisation technologies commonly in use, factors such as kernel integration and the
their alternatives, and how they may differ unambiguous open source nature of the A popular choice for desktop users, Oracle’s
from your experience on the desktop. code (not to mention that it works very well). VirtualBox has some good things going for it in
Although it lacks somewhat in terms of the developer space too.
KVM graphical tools, VMs are controllable from
KVM works on top of Qemu, so for the the command line (and therefore, also easily could ever want. As well as being a great
purists, when we talk about KVM here we by scripts and other software which uses tool for development, it is also widely used
mean KVM/Qemu. KVM is a Linux-only the libvirt API – see our tutorial on page 94) for spinning up VMs within clouds (eg
virtualisation technology, parts of which are to a greater degree than pretty much anyone OpenStack).
VirtualBox
VirtualBox came to prominence by virtue of
it being a very featureful, well performing VM
hypervisor that worked cross-platform and
had an easy to understand management
interface. The software has a colourful
history – the original company that created
it, Innotek, was acquired by Sun
Microsystems, before many parts of the
disintegrating Sun empire were snapped up
by Oracle. As a largely open source project
(there is a non-open source version, which
makes use of proprietary device drivers for
VMWare
Virt-manager is a useful graphical front-end for KVM, but you should really familiarise yourself with No, we didn’t forget about VMWare.
the virsh commandline tools, especially if you need tricky network setups. Although it has been in the vanguard of
virtualisation technologies for some time,
VMWare is not open source. Although that
“Vagrant was originally developed to work with doesn’t exclude it from consideration in
the world at large, it does tend to make
VirtualBox, but a system of plugins enable it to it less relevant to the emerging cloud
platforms, and certainly a little out of the
work with numerous hypervisors.” scope of this FLOSS-loving publication.
68 www.linuxvoice.com
CLOUDADMIN
VirtualBox (or Qemu/KVM if you use that as
the back-end). Further reading
The real difference is in provisioning. If you Why Vagrant? https://docs.vagrantup.
spend your life testing software, bringing up com/v2/why-vagrant/index.html
a clean VM is only part of the day-to-day Stephane Graber’s LXC primer
grind. You then have to prepare that system https://www.stgraber.org/2013/12/20/
for use. This ranges from the mundane lxc-1-0-blog-post-series
installation of dependency packages to the Using KVM with Ubuntu https://help.
more annoying repeatedly setting up options ubuntu.com/community/KVM
like host configuration or adding SSH keys VirtualBox homepage
so you can access the VM you created. https://www.virtualbox.org
Yes, you can do this once in something
Vagrant is an effective tool for provisioning like VirtualBox and create a snapshot image.
VMs and working collaboratively. Before you know it though you have half a control containers as you may use with VMs
dozen different snapshots that all differ in (though to be fair, there are some
graphics, and the open source version subtle ways, and aside from taking up loads peculiarities of LXC that aren’t adequately
seems to be stuck on an LGPLv2 licence) it of disk space, it can get pretty confusing. By addressed by libvirt, but you can also use the
sits a little ill at ease in the Oracle stable. using Vagrant to provision systems from a comprehensive LXC command line tools).
Nevertheless it is a mature and common set of boxes, you can reduce As there is no CPU or hardware
competent environment for running VMs. It changes to your install to just changing virtualisation, there is a much lower overhead
relies a lot on paravirtualisation – special some options in the Vagrant file that the to running containers than VMs – there are
drivers that allow a more efficient software uses to bring up the VM. Of course, no virtualisation layers to go through, so
throughput of data to and from the host OS. you can still create your own boxes, and things like file access are much faster, and
These do bring performance benefits, but there is a new service specifically for sharing the scalable resources also mean that more
rely somewhat on the co-operation of the those images in the cloud, so collaboration efficient use can be made of hardware.
guest OS, so if you are running custom is much easier than trying to shift gigabytes There are of course, disadvantages to
kernels on strange distros you may not reap of VM filestorage around. using containers. For a start, you can only
the full benefits. run Linux-based containers. It can even
It does have the huge advantage of also Linux containers (LXC) sometimes be tricky to run completely
running on Mac OSX and Windows (and LXC is not a hypervisor for virtual machines. different distributions without additional
even Solaris), which can be beneficial in It is better than that; well, at a lot of things tinkering. Added to that, the lack of
some collaborative environments. anyhow. LXC uses some very useful virtualisation also means no virtual
user-mode kernel features to containerise an hardware – which can be a pain when it
Vagrant implementation of a Linux OS – think chroot, comes to configuring networking. For
Vagrant isn’t a virtualisation engine, but it is but taken to extremes. Like a virtual machine, simple networks, LXC makes use of a
most definitely worth talking about. The idea the container is able to carry out its business bridged driver, which means the container
behind vagrant is that it becomes a sort of independently of the host OS, even to the can access an external network through the
meta-manager for virtualised instances. point of running a different OS entirely. What host’s network setup, but complicated VLAN
Vagrant was originally developed to work you get is a self-contained running instance topologies become more troublesome.
with VirtualBox, but a system of plugins that is separate from the host OS, but which There can also be some nagging suspicions
enable it to work with numerous hypervisors. can dynamically share resources – there is that what may work in a container could
Once you have installed Vagrant, you can no need to pre-allocate RAM and disk space behave differently on real hardware. Gosh,
fetch virtual machine images (which in for example, because the LXC container will not that anyone has real hardware!
Vagrant terms are known as ‘boxes’) and use simply consume what it needs just like any LXC arguably has the most mature
them to bring up virtual machines. other process. LXC also plays nicely with support on Debian and derivative distros,
You may ask yourself “What on earth is libvirt, so you can use the same tools to and is well worth experimenting with.
the difference between this and just creating
a machine in VirtualBox)?”. The answer, at The virtual future
least at the system level, is “not much”. Start It sometimes seem mad that we run an OS
up your box, and it behaves pretty much like on virtual machines through cloud software,
any other VM you have initiated with which itself can be running on virtual
machines, which themselves can be running
on the very same OS. Don’t think about it too
Docker much, it hurts. The point is that VMs (and
Missing from this VM get-together containerisation) provide the essential
is Docker. Like LXC, Docker is a flexibility of cloud implementations, and as
containerisation solution, and we have the overhead associated with them gets
left it out because we will be having a very
Linux containers are not a VM, and that is the smaller, they become more and more
detailed look at it next issue!
whole point! important enablers of future technologies.
www.linuxvoice.com 69
FOSSPICKS
FOSSpicks Sparkling gems and new
releases from the world of
Free and Open Source Software
Mike Saunders has spent a decade mining the internet for free
software treasures. Here’s the result of his latest haul…
Create images from ASCII diagrams
Asciidia 0.3.2
P
lain text is excellent, and the resulting directory, and there
much more versatile than a you’ll see the program: asciida.php.
lot of people give it credit for. The best way to learn how Asciida
Take Markdown syntax, for one works is with an example file, and
simple example: fortunately a few are supplied in the
Heading test directory. Have a peek at test/
======= diagram.txt, for instance – it looks
Some **bold** text like classic ASCII art (see the
* This screenshot), but Asciida is clever
* is a enough to work out the shapes and
* list signs contained therein.
Although this is good old plain text,
the extra formatting here is easy to Words and pictures
understand, and the Markdown To convert test/diagram.txt into a
tools convert this text into decent vector (SVG) image, enter this: Here’s diagram.txt being viewed in a plain text terminal, and
HTML with just one command. ./asciidia.php -t diagram -i test/diagram. Asciida’s SVG conversion shown in Firefox. Nicely done.
Asciida does a similar job, but it txt -o svg:diagram.svg
focuses on creating diagrams from Asciida doesn’t provide much in
plain text files. In other words, you the way of feedback, but its silence open diagram.svg in a vector
create images in a plain text editor at the command line shows that graphics editor such as Inkscape
using regular characters, run the conversion has worked. Now – or you can even open it in Firefox
Asciida, and get a proper vector (or if you don’t have a vector editor to
bitmap) version.
As Asciida is written in PHP, you’ll
“Asciida does a similar job to hand. And voilà: there’s a fancier
version of the ASCII art diagram,
need the php5-cli package installed Markdown, but focuses on creating with everything in its right place.
to run it. Extract the tarball, cd into diagrams from plain text files.” Asciida can also generate bitmap
images providing that the convert
tool from ImageMagick is installed.
For some reason, on our Ubuntu
13.10 test box Asciida complained
that the MAGICK_HOME
environment variable wasn’t set, so
we had to run the program like this:
export MAGICK_HOME=`which convert`
./asciidia.php -t diagram -i test/diagram.
txt -o png:diagram.png
Note the -o png option here to
produce PNG output. Asciida can
generate files in other formats too
– see README.md for the details.
Asciida can convert
other types of plain
PROJECT WEBSITE
text diagram, such as https://github.com/aurora/asciidia
directory trees.
70 www.linuxvoice.com
FOSSPICKS
Image manager
Phototonic 0.93
Z
awinski’s Law of software At first glance, Phototonic looks
development, from Mozilla somewhat like a regular file
and XEmacs hacker Jamie manager, with a tree view of the
Zawinski, states: “Every program filesystem down the left, and a pane
expands until it can read mail.” containing thumbnails on the right.
While this law is used in jest to Navigate into a directory containing
mock programs like Emacs that images, and you’ll see them on the
have stretched way beyond their right-hand side. You can right-click
original purposes, it makes a good on directories and images to
point: bloat and feature creep are rename them; this is how you’re
everywhere in free software. meant to organise your images in
In contrast, we love it when a Phototonic. It doesn’t try to do
program has a very clear goal, as in anything fancy with tags or
the case of Phototonic. It manages metadata, but trusts that you can
your images – nothing else. It achieve what you want with a good
doesn’t try to link to social media old-fashioned directory tree. Use the plus and minus magnifying glass buttons in the top-right
websites, or provide advanced Click on an image to highlight it of the window to change the thumbnail sizes.
editing facilities, or wash your car. (11 file formats are supported), and
All it does is help to view and information about the image’s file Phototonic includes basic image
organise your pictures, and format, file size and dimensions is editing facilities (rotating, flipping
consequently it’s fast and reliable. displayed in the bottom status bar. and cropping) along with a
Phototonic is written in C++ with Double-click a picture to view it slideshow view that shows a new
Qt 4 as the front-end, so you’ll need close-up, and press Escape to go image every five seconds. This
the libqt4-dev and qt4-qmake back to the main screen. default duration, along with other
packages installed (that’s in Debian Under the View menu you’ll find aspects of the program including
and Ubuntu – in other distros they options to change the sizes of the default keybindings, is configurable
may have different names). After thumbnails along with the sort in the Preferences panel. In all, it’s
extracting the tarball and cding into order, while the toolbar at the top of exactly what a standalone image
the new directory, enter: the window lets you navigate like in manager should be: simple, fast,
qmake-qt4 a web browser. stable and not overloaded with
make buggy features that should be
This builds the source code, and
you can enter sudo make install to
“Photonic is exactly what a implemented in separate apps.
copy the binaries into your standalone image manager
filesystem. Then just enter
phototonic to start the program.
should be: simple, fast and stable.” PROJECT WEBSITE
http://oferkv.github.io/phototonic
How it works: Editing an image
1 Select 2 Transform 3 Save
Double-click on an image to display it in full. Right-click on the image and go into the Right-click again and choose Save, then press
In this view, use the Page Up and Page Down keys to Transform menu. There you’ll find options for Esc to return to the thumbnail view. Hit F5 to refresh
navigate through images. rotating, flipping and cropping the image. the thumbnails to reflect your changes.
www.linuxvoice.com 71
FOSSPICKS
Vi-like hex editor
Bvi 1.4.0rc
N
obody forgets their first shows the addresses (ie locations)
encounter with the Vi(m) of bytes in the file, in hexadecimal
text editor. Compared with (base 16) format. The middle panel
most “normal” editors, where you shows the contents of those bytes
can simply type in text and press a in hexadecimal format, while the
key combination to save your work, right-hand panel shows the ASCII
Vi initially seems bizarre, with its representations of those bytes.
arcane system of modes and Finally, a status line at the bottom
commands like :wq. Yet after shows the filename along with the
spending a while with Vi, many currently highlighted byte in binary,
people find it to be incredibly octal, hex and decimal formats.
It’s not pretty, but it’s
efficient and powerful – hence its Bvi has many more commands
extremely lightweight
huge army of dedicated fans. Vi-like commands (68k for the executable) taken from Vi, along with a few
If you’re one such Vi supporter, Move around using the cursor keys and very useful when useful extras such as the ability to
you might like Bvi: it’s a similar (or in more traditional Vi style, you need to poke edit a specified range of bytes in a
editor geared towards working with H/J/K/L), and hit Tab to switch around inside binary file, instead of the whole file. Its
binary files. To install it, you’ll need between the hex and ASCII panels. files. minimal requirements mean that,
GCC and the ncurses development To replace a byte, hit R. By default like Vi, it will run almost everywhere,
files (eg the libncurses5-dev you can’t insert or delete bytes - use so it’s on our list of “things to install
package in Debian/Ubuntu). After the :set memmove command to by default in a new distro” now.
you’ve built the source code you enable these operations, and then i
can open a file with bvi filename. and d to do them. Saving a file and
Now, Bvi splits the screen into PROJECT WEBSITE
quitting is just like in Vi as well, with
http://bvi.sourceforge.net
four sections: the left-hand panel :w and :q respectively.
PNG file compressor
OptiPNG 0.7.5
M
any of the new Free is, it tries to reduce their file sizes
Software programs that using various compression
get released are easy to algorithms and without removing
ignore, performing piffling little jobs any pixel data. The end result looks
that perhaps only the developer exactly the same as the original
finds useful. At first glance, one image. Using it is very simple:
such is OptiPNG. Wow, so it optipng file.png
reduces PNG file sizes by 10–15%; OptiPNG spits out some
who cares? In this day and age of information as it works, overwrites
terabyte hard drives and blazingly the original file with the smaller one,
fast internet connections, do such and shows you the reduction
Here’s the FOSSpicks
trivial reductions really matter? percentage. We did a bunch of tests While the default options do a
screenshot from the
Well, they do in some using screenshots from this very Pybik review, now decent job, OptiPNG has some
circumstances – and they matter a FOSSpicks section, as generated by 14% smaller thanks to extra settings for choosing the
lot. If you’re hosting a very popular Gimp. Occasionally we saw OptiPNG. optimisation level and PNG delta
website serving up thousands of impressive reductions of 25–30%, filters. The program’s website also
PNG images every minute, even the but by and large the shrinkage was has an excellent explanation of how
smallest reductions can add up in the 10–15% range. PNG optimisation works under the
over time, making your website hood: http://tinyurl.com/a9wprt.
faster and ultimately reducing your
bandwidth costs.
“Even the smallest reductions can
OptiPNG performs lossless make your website faster.” PROJECT WEBSITE
http://optipng.sourceforge.net
compression on PNG images; that
72 www.linuxvoice.com
FOSSPICKS
Internet suite
SeaMonkey 2.25
I
f you were around on the web in That’s it – you don’t need to install it
the late 90s, you’ll certainly system-wide if you don’t want to.
remember Netscape, a suite of (Note that the program stores its
programs including a browser data in .mozilla/seamonkey/ in
(Navigator), email client and web your home directory.) Prepare for a
page editor. After Netscape’s blast of nostalgia when you first
demise, much of its source code start the app, because the interface
was refactored by the Mozilla has hardly changed since Netscape
project, and today we see the 4. A few things have been removed
results most famously in the form or clumped together, but otherwise
of Firefox. But while Firefox is a it’s quite similar.
Here’s SeaMonkey
standalone browser, the internet Because SeaMonkey shares the from 2014, showing a integrating every questionable
suite project has also continued same underlying HTML and screenshot Netscape change from self-styled “user
under the name SeaMonkey. In JavaScript engines as Firefox, it 4.04 from 1997. Not a experience designers” (ugh).
recent years it looked like works largely the same for web lot has changed, has it? New features in version 2.25
SeaMonkey development was browsing, albeit with a more include VP9 video decoding,
stagnating, but as more users traditional interface. But we like the support for Opus audio in WebM,
become dissatisfied with Firefox fact that it has been consistent over and the Gamepad API (so that web
the suite is getting more attention. the years, not whimsically games and apps can access USB
And it’s really easy to try: grab the or Bluetooth joypads).
33MB .tar.bz2 file from the
SeaMonkey website, extract it, jump “We like the fact that SeaMonkey
into the resulting directory and run
the seamonkey executable inside.
has been consistent over the years.” PROJECT WEBSITE
www.seamonkey-project.org
Editor reborn “for the 21st century”
Neovim 2014-Mar-23
T
here’s something of a Vi(m) to fund his work on Neovim – an
theme to this month’s impressive sum, given that his
FOSSpicks, what with Bvi’s original goal was $10,000.
appearance on the facing page.
Now we have Neovim, a fork of the Plus ça change…
regular Vim editor. But given that Although there’s still a huge amount
Vim is under active development, of work to be done on the editor,
has masses of fans and a well you can try it out right now to get a
respected lead developer, what kind feel for it. To get the dependencies
of madman would want to fork it? on Debian/Ubuntu:
So far there’s not much
Well, that madman is Thiago de sudo apt-get install libtool autoconf the important work will take place
to distinguish Neovim
Arruda Padilha from Brazil, and he automake cmake libncurses5-dev g++ from the original under the hood. Padilha wants
has some compelling arguments: Then grab the master .zip file version, apart from an Neovim to have a simpler build
Vim’s codebase is old, complicated from GitHub (https://github.com/ extra line on the startup system, more platform-independent
and full of cruft that could be neovim/neovim), extract it and run screen. code, and a more versatile plugin
removed, he says. It’s difficult for make cmake && sudo make install system. It should also be easier
new contributors to get involved. So in the resulting directory. After to embed the editor into other
it’s time for Vim to undergo a major compilation, you’ll be able to run the programs, and create GUI front-
source code overhaul. editor with nvim. ends for it on multiple platforms.
This isn’t an easy task, and Right now it looks, feels and
Padilha has set up a crowdfunding smells like regular Vim – and that’s
PROJECT WEBSITE
project to get started. At the time of the intention. Neovim won’t look
www.neovim.org
writing, he had raised over $32,000 too different on the surface, as all of
www.linuxvoice.com 73
FOSSPICKS
Programming language
Python 3.4
M
aintaining a handle Windows paths as well,
programming language including the drive letter and colon
is a tricky business. combinations at the beginning.
Python 3 was a bold step, breaking Another new module is asyncio,
compatibility with Python 2 which provides asynchronous I/O
programs, but it was regarded as a via a pluggable event loop and
necessary move to clean away a lot coroutines. Then there’s enum
of cruft that had built up. There was (provides support for enumerated
plenty of controversy at the time, data types), tracemalloc (a
but Python 3 is maturing well, and debugging tool to trace memory
now we have the 3.4 release. A allocation) and ensurepip (a
bunch of new modules have been cross-platform way to install the
Many Python features
included, such as pathlib, which PIP package manager into an features in 3.4, and lots of work has
begin life as PEPs, or
provides an object-oriented API for existing Python setup). “Python Enhancement been done on other modules to
filesystem paths. For instance: Many security improvements Proposals”, which are squish bugs and add general
p = Path(‘/home/mike/foo/bar.py’) have been implemented as well: for discussed and reviewed improvements. The changes have
With this, p.name contains bar. instance, there’s now TLS 1.1 and by the community. been very well documented too –
py, p.suffix contains .py, and p. 1.2 support in the SSL module. something that’s often lacking with
parts contains a tuple with every These are just the main new new language release, so kudos to
element in the path. You can join, the Python team.
split and compare paths, and query
them (eg to find out if a path is “Python 3 is maturing well, and now
relative). If you’re doing cross-
platform coding, there are ways to
we have the 3.4 release.” PROJECT WEBSITE
www.python.org
Information organiser
TreeLine 1.9.4
A
t the start of this issue’s TreeLine 1.9.4 is a development
FOSSpicks we heaped release on the road to 2.0, and is a
spoonfuls of praise on plain complete rewrite of the earlier 1.4
text, but sometimes it can get out series. It’s written in Python with Qt
of hand. Take notes.txt for instance, providing the interface, so you’ll
the text file used for planning this need PyQt installed to run it. When
section of the magazine: it started you start the app, you’re presented
off well, with clearly defined with a two-pane view: the left-hand
sections and tidy presentation. But side contains the tree of items, and
after a while it ended up as a the right-hand side shows the data
morass of ideas, links, compilation for individual items.
TreeLine stores its data
instructions and other random bits TreeLine supports custom data
in (optionally encrypted)
and bobs. What we really need is a It’s in the trees! It’s coming! XML format, and can types with a range of fields (eg text,
souped-up note taking and list The best way to understand export to HTML and numbers, dates) so you can easily
compilation app – and thank TreeLine is to open the plain text. customise it for nigh-on any type of
$DEITY, TreeLine provides it. documentation, which, brilliantly, is information. It’s hugely configurable
Essentially, TreeLine could be made in TreeLine itself. Click Help > and didn’t exhibit any major bugs in
described as an outliner, note-taker Full Documentation in the menu, our testing, so from now on it’s our
or PIM program. It’s hugely versatile and a new TreeLine window will go-to app for FOSSpicks planning.
and isn’t designed to work with open. Click the arrows on the
specific types of information; it will left-hand side to open up nodes in
PROJECT WEBSITE
handle anything you can put in a the tree, and green or red items to
http://treeline.bellz.org
tree-like structure. read them on the right.
74 www.linuxvoice.com
FOSSPICKS
FOSSPICKS Brain Relaxers
https://launchpad.net/pybik/
Flappy Bird-like game
Openflap 1.0
F
rontier: Elite II provided a a free clone: Openflap. The
giant universe to explore, gameplay is equally as minimal,
together with open-ended and compiling it actually takes
gameplay where you could more brainpower (see the README
trade, mine, fight or work for the file for instructions). The only
military. It provided months of dependencies you need are SDL
fantastic entertainment – and all and its various bolt-on libraries – so
on the Amiga. That’s an incredibly once you have it installed, just enter
rich game running on a 7MHz openflap to play.
CPU backed with 1MB of RAM.
Today, people carry mobile Tapping tedium
phones that are several thousand If you’ve never seen Flappy Bird (or
Bounce the ball, miss
times more powerful than the its million clones) before, here’s how playing, but what really prompted
the gaps – that’s it.
Amiga 600, and yet the most you play: tap Space. A ball is falling But the code is useful us to include Openflap is the
popular mobile games are so from the top of the screen, and for learning how to do source code. It’s clear and easy
utterly trivial it makes us rage. tapping space bounces it upwards. graphics, sound and to read – a good resource for
Take Flappy Bird, for instance: But! The ball is also moving to the input in SDL. snippets and ideas if you want to
it’s brain-shutdowningly tedious, right, and you have to tap space to make your own C++/SDL game.
and yet it was making its author help it through gaps in pipes. And
$50,000 a day at its peak. that’s all there is to it. PROJECT WEBSITE
Anyway, in true FOSS style, Your high score is shown on https://github.com/jazztickets/
openflap
someone has come up with the right, as an incentive to keep
Rubik’s Cube game
Pybik 1.1.1
S
ome people find Rubik’s detail to show the plastic parts onto
Cubes maddenly which the coloured labels are stuck.
frustrating; others find OK, you might argue that visual frills
them a good form of grey-matter are unimportant in a game like this,
stimulation. If you enjoy the odd but if you’re going to be staring at
session of “cubing” (as the cool the cube for a while as you solve it,
kids call it) but you don’t want to why not make it look good?
have a cube by your desk in case
your boss thinks you’re wasting Pretty colours3
time, then you can get by with a Click and drag on the cream area
computerised version. around the cube to rotate it, and
The lighting effects are
Pybik is written in Python, with hover the mouse cursor over a moves along with some solving
a nice touch, although
its interface provided by Qt. So piece to see how it will rotate when at some angles the glare algorithms. It’s a remarkably
you’ll need PyQt4 to install it – you click it (the mouse pointer is a bit over the top. good substitute for a real cube,
see the INSTALL file in the tarball changes direction). although you can’t throw it
for full instructions. A number of challenges are against the wall when you get
Once you’ve built it, you can run available, eg prompting you to solve annoyed with it. Oh well.
it in place with ./pybik. The a cube in under 10 moves, while the
presentation is gorgeous: the “Pretty patterns” list generates
PROJECT WEBSITE
cube is rendered in shiny 3D, with funky-looking cube layouts for you https://launchpad.net/pybik
lovely light effects and impressive to solve. There’s also a library of
www.linuxvoice.com 75
Email andrew@linuxvoice.com to advertise here
TUTORIALS INTRO
TUTORIALS
Dip your toe into a pool full of Linux knowledge with eight
tutorials lovingly crafted to expand your Linux consciousness.
In this issue…
78 80
Ben Everard
has his first batch of alcoholic ginger ale
bottled and ready to drink.
F
ree software is a ideal close to
many of our hearts, but it’s not
an isolated cause -- it’s under the
wider umbrella of digital rights. After
LXDE Wearables
all, what advantage is having control of Bored with the default LXDE desktop? The Jean Paul Gaultier of Linux,
the software on your computer if the Beautify this lightweight environment Ben Everard, sews electronics into
authorities block the content you want by following Ben Everard’s easy steps. clothes to make himself super cool.
to see? This is exactly the issue facing
internet users in Turkey and China.
What good is a free office suite if the 86 90 94
documents you need to access are in
an obfuscated proprietary format?
Free software is booming, but other
areas of digital freedoms aren’t doing as
well. There have been some successes
in open document standards, and the
Snowden revelations have shocked a Hunt Commets Pi Beacon Libvirt
few people, but they still haven’t had as
Using Python and public Les Pounder, the BA Valentine Sinitsyn masters
much attention as FOSS. Now is the
data, Andrew Conway Baracus of Linux, escapes his virtual machines using
time for the weight of the free software
chases down comets. trouble with a Ras Pi. Python scripts.
movement as a whole to come down
on the forces that try to restrict our
freedoms, whether that’s in closing off
our ability to modify software, or closing PROGRAMMING
off other basic digital rights.
Linux succeeded despite some of the Ruby Genetic algorithms Google script
largest companies in the world trying to 98 Everything is an object! It’s 104 Programming involves 106 The cloud offers loads of
stop it, so there’s no reason to think that a popular saying amoug breaking a problem down options for running
object-orientated programmers, into its constituent parts, then software. EC2 or VPSes allow you
we can’t get similar levels of success
but what does it mean, and how assembling a step-by-step method to run virtual machines almost
with other digital freedoms. However, does it affect the way you of finding the answer. Wouldn’t it anywhere in the world, but
we have to fight for them. If we just program? We delve in and find the be much easier if you could just sometimes you want something a
focus on free software and not on other answer, or at least the Ruby say what answer you wanted and bit lighter. Google Apps Scripting
digital rights, we may end up winning version of the answer, and then let the computer work it out? With is a way of running simple
set you readers a challenge. genetic algorithms, you can. programs on Google’s servers.
one battle but losing the war.
ben@linuxvoice.com
www.linuxvoice.com 77
TUTORIAL LXDE
CUSTOMISE THE
TUTORIAL
LXDE DESKTOP
Get a fantastic desktop environment without
BEN EVERARD
overloading your system’s hardware.
T
he Lightweight X11 Desktop Environment – or
LXDE as it’s more commonly known – is
popular for its ease of use and low use of
system resources. It’s the desktop of choice for the
Raspberry Pi, and is an excellent option for replacing
Windows XP on older machines. However, in its
default form it is a little ugly. Everything works as you
expect it to, but it doesn’t show off the Linux desktop
experience as well as it could. Fortunately, it’s quite
easy to whip the default configuration into something
that looks good and is a little more user friendly. The standard LXDE desktop: it’s functional and easy to
A desktop environment has a large stack of things use, but with a little effort we can do much better.
that are really just images. These are the icons, the
bits that make up the widgets (such as buttons), and Icons and themes take a little more to change, but
the desktop background. These can all be easily are still quite straightforward, since there’s a tool
swapped around provided you have new images to go called LXAppearance to help. First you need to
in their place. download the theme. We started with the Elementary
icons at www.gnome-look.org/content/show.php/
Get new wallpaper elementary+Icons?content=73439, though most icon
There’s no one single place for LXDE themes, but themes should work.
there is for Gnome, and they’re mostly compatible. Follow the download link to DeviantArt, then
Head to www.gnome-look.org to see a fantastic download the Zip file. In principal, it is possible to
range of user-submitted work. There are some install the icon theme with LXAppearance, but in
great-looking things on there, and there are some truly practice it’s a little awkward since it only supports tar.
terrible ones too, so take a little time to find ones you gz and tar.bz files. We found it quite unstable when
like. By default, the website shows the most recently installing anything. All installing does, though, is place
added items, and the quality is variable. You usually the files in the appropriate directories, so it’s quite
need to switch to Highest Rated or Most Downloaded easy to do it without an automatic installer.
This is our LXDE desktop
to find the good choices.
after tweaking. You may
notice we’ve also changed
To switch desktop wallpapers, just save the image Install new icons
the menu icon. This is file that you want to use, then right-click on the Icon themes should be placed in a folder called
done by right-clicking on desktop and choose Desktop Preferences in the .icons in the user’s home folder. The easiest way to do
the old icon and selecting menu. This will then give you the option to browse to this is with the PCManFM file manager that comes
Menu Settings. the image file you want. with LXDE. Just open up your home folder and make
sure hidden folders are displayed (you should tick the
box in View > Show Hidden). If there isn’t already a
folder called .icons, you need to create it (right-click >
Create New > Folder). Then just unzip the icon theme
that you’ve downloaded (right-click it in the file
manager, then select Extract To and in the folder path
enter /home/ben/.icons – with your username
instead of ben).
To activate the icons, you’ll need to use
LXAppearance. Depending on your setup, you might
find this in the Applications menu under Preferences >
Customise Look And Feel. If it’s not there, you’ll have
to run it by typing lxappearance in the terminal. In the
Icon Theme tab, you should now find the Elementary
theme (or whichever Icon theme you installed).
78 www.linuxvoice.com
LXDE TUTORIAL
The same basic method can also be used to add
new widget themes. In gnome-look.org, these are
under the GTK 2.x menu in the left-hand column of the
screen. We went for BSM Simple (www.gnome-look.
org/content/show.php/BSM+Simple?content
=121685) These have to be downloaded and
extracted into the folder .themes, and then they’ll
appear in the Widget tab in LXAppearance.
The eagle-eyed of you may notice that after
installing, it looks a little different to how the theme
looks on the main website. We’ll come back to that in
a minute, but for now, we’ll go on with adding a dock.
Building a dock
We think that the nice-
LXDE comes with a panel along the bottom that holds On gnome-look.org, you’ll see that most themes
looking Metacity windows
most of the basic desktop utilities, such as the have rounded corners on the windows, but when you
are well worth the extra
applications menu, window list and system tray. It can install them, you get square corners. This isn’t a huge few clock cycles they take
get a little cluttered, so we like to have an application deal, but you’ll also find a few other things that don’t to render.
launcher on the side of the desktop to provide quick quite look as well as they could. The reason for this is
access to the programs we use most frequently. the window manager.
This is really just another panel, but we’ll use a few
tricks to make it function better for our needs. First, Under new management
right-click on the bottom panel and select Create New By default, LXDE uses the Openbox window manager.
Panel. This will add the new panel and open the Panel This is lightweight, and serves most purposes quite
Preferences window. The first thing to do is get it in well. Openbox looks its best with very minimal
position on the left side. We put ours in the middle of windows, and a very clean design. A lot of people like
the left-hand edge of the screen, taking up 40% of the this, but there’s also a place for slightly more
edge, 54 pixels wide with icons 50 pixels big. substance to the windows. For this, a better look can
In the Panel Applets tab, add an Application be achieved with other window managers.
Launcher Bar, then double-click on the entry in the list Our favourite is Metacity. This is the Gnome 2
to open Add Applications To The Launcher. Once window manager. Of course, there’s a trade off to this.
you’ve selected your favourites, you can set the Metacity will use a little more screen space than
appearance. In Appearance, select Solid Colour (with Openbox, and a little more CPU and memory. The
Opacity), then click on the colour and scroll the opacity difference shouldn’t be much though: we tested both,
down to 0. The final thing to keep it out of the way is and Openbox used about 0.5–1 % of the CPU time,
to select Minimise Panel When Not In Use in the and 1% of the memory, while Metacity used 2–3% of
Advanced tab. the CPU and 2% of the memory. By comparison, in
This means it won’t take up any screen space both cases, the underlying X Windows System used
normally, but you can just move the mouse to the left 10–15% of the CPU and 6% of the memory, so while
edge of the screen when you want to open up an Metacity does increase the window management
application, enabling you to have nice big application overhead, in most cases it won’t be significant.
launcher buttons without spoiling the look of the To switch to Metacity, first make sure it’s installed.
bottom panel with loads of clutter. On Debian-based systems, this is done by typing the
following at the terminal:
sudo apt-get install metacity
Configuration files You can then make the change. Go to the
Applications Menu > Preferences > Desktop Session
Almost all of the configuration we’ve done has been either Settings, and in the Advanced tab, change Window
by installing work other people have done, or via point-
Manager to Metacity. You’ll need to log out and back
and-click settings. This is a simple way of getting access
to a huge range of settings, and you can create wonderful in again (or reboot) for the changes to take effect.
desktops doing just this. However, the ultrageeks among As you’ve seen, there are loads of things you can do
you may be itching to exert ultimate control over everything to improve the default look of LXDE. None of these
on your desktop. Fortunately, you can. things really change the way you use the system, but
If you want to change the appearance of the windows,
they can make it a little more pleasant. We’ve shown
you’ll need to dive into the theme. Creating a new
theme from scratch is a daunting task, but it’s pretty you how we like it, but with a bit of experimentation,
straightforward to modify an existing one. The Gnome wiki you should find a setup that works well for you.
has details of what the various bits are (https://wiki.gnome.
org/Attic/GnomeArt/Tutorials/GtkThemes), and you’ll find
everything in text files in the folder that you extracted into Ben Everard is a Pi enthusiast and the co-author of the
the .themes directory. best-selling Learning Python With Raspberry Pi.
www.linuxvoice.com 79
TUTORIAL ARDUINO
MAKE SMART CLOTHES WITH AN
TUTORIAL
ARDUINO LILYPAD
Add a microcontroller to your cycling jacket and take one more
BEN EVERARD
step along the road to pervasive computing.
O
ver the last decade, it has become much
WHY DO THIS? easier to make electronic gadgets. The
• Be the best-dressed Arduino revolution has made the micro-
cyclist in town
controllers easier to use, and at the same time, much
• Learn how to program
clothing more hardware and software has been created. You
• Get started with the can now plug a few shields into an Arduino and get a
neopixel and add mobile phone, or a GPS navigator with a touchscreen,
colourful LEDs to your or, well, almost anything you can imagine.
projects
Most of the time, these gadgets use traditional
circuit-making methods, such as PCBs, breadboards Fig 1: The first row of neopixels can be attached entirely
and strip boards. However, that doesn’t have to be the with conductive thread.
case. With a little ingenuity, you can create circuits in
all sorts of ways – such as by sewing conductive The connections tend to be too close together (thread
thread into clothes. As an example, we’ll create a is less precise than soldered wire) and they have
cycling jacket that has some LEDs to make it a bit smaller contacts, which can be troublesome for use
more visible than most, but the techniques we use with e-textiles.
could easily be used to make all manner of items such There are two lines of microcontroller boards that
as light jewellery, or digital art. are designed to correct these problems, and both are
There’s nothing to stop you stitching any circuit perfect for wearable projects: the Lilypad and the
board into clothing. In fact, you could be forgiven for Flora, from Adafruit Industries. They’re both based on
thinking that a small headerless microcontroller board the Arduino, and are mostly compatible with each
such as an Arduino Pro is ideal. However, there are a other in terms of code and hardware. The biggest
few disadvantages to using general-purpose boards. difference between them from a Linux user’s
perspective is that the Lilypad boards work on Linux
with the official Arduino IDE, while the Flora (and the
smaller Adafruit Gemma board) don’t. There is some
guidance on the Adafruit website that may help you
get the Flora working under Linux, but it’s known to
have some problems (particularly the Gemma
variant). Because of this, we opted to base our project
on the Lilypad.
Choose your controller
There are a few different types of Lilypad. Most don’t
Input pin
R2 come with USB integration, and need an external FTDI
6.2k board in order to program them. The original Lilypad is
R2 Ohms the largest. There is also the smaller Lilypad Simple,
32k and the Lilypad Simplesnap, which can easily be
Ohms removed to allow the clothing to be washed. The
Lilytiny is the smallest, though it is a little harder to
program. The easiest to get started with is the Lilypad
USB, which has everything onboard, and this is the
-ve one we’ve used in our project.
The Lilypad USB is supported by the Arduino IDE
+ve from version 1.0.2 onwards, though we used version
Fig 2: These two resistors 1.5 in this project. If your distro comes with an earlier
make the switch work, and version, you’ll need to download the latest from
they’re the most fiddly bit www.arduino.cc. Once you’ve got it, you just need to
to fit into the jacket. unzip the archive, then run the arduino script in the
80 www.linuxvoice.com
ARDUINO TUTORIAL
all manner of switches available, but we needed some
Power supplies that are on-off (that is, you press them once to go on,
and a second time to go off), and suitable for
The easiest way to power the Lilypad USB is through the
wearables. The best ones we found were from
JST connector. This can take a lithium polymer (LiPo)
battery with an output of 3.7V, and run everything off that. Adafruit at www.adafruit.com/products/1092.
There’s even a charging circuit built into the Lilypad USB, so You can’t just put a switch between positive voltage
you can recharge the battery by plugging the Lilypad into and an input pin on the microcontroller and use it as
your computer. This means you can tuck the battery into an input. When it’s on you’ll get too much current
some inaccessible place and not worry about it.
flowing into the input pin, and you could damage the
There are other batteries that can connect via JST; for
example, you can get holders for three AA or AAA batteries, microcontroller. When it’s off there’s no input to the
or for two CR2032s. pin. You may think that no input is the same as an off
A third option is to use a USB power source. You can get input, but it’s not. No input is a sort of floating state
battery packs designed to give mobile phones extra power, that can go either way, and while it’ll usually go to off,
and these should work when plugged into the USB port. It’s
it’ll flash on, and create all sorts of problems. The
probably only worth doing this if you happen to have one of
these lying around, as they’re bigger and more expensive solution to both of these problems is a resistor,
than the alternatives without having any real advantages. though in slightly different ways.
Wire up the switch
PRO TIP
new directory, and everything should work as long as Take a look at figure 2 for details of how to wire up a
A multimeter will make
you’ve got Java installed. switch. When the switch is open R1 stops too much your life a lot easier when
The microcontroller is the brains of the project, but current damaging the input pin. R2 allows a little testing the integrity of
it’s useless without additional components for input current to leak away, but since it’s quite a large your circuit.
and output. We’re going to use a few extra pieces to resistor, this isn’t too much. When the switch is closed,
give us the functionality we need. R2 connects the pin to ground, and this is enough to
Flora neopixels from Adafruit give us light. As you make sure that the input always reads off.
may have guessed from the name, they’re designed to The final piece of input and output hardware we’ll
work with the Flora board, but you can equally use use is a piezo buzzer. This will buzz to let the wearer
them with the Lilypads (or, for that matter, other know when there’s an indicator on, so they don’t forget
Arduino-compatible boards). Neopixels are chainable to turn it off. You can get sewable buzzers, but we
RGB LEDs, which means that one pin on the controller used an ordinary piezo element. It’s not very loud, but
board can drive many lights – an especially useful it doesn’t need to be, because it’s just there to remind
feature on sewable boards, as these tend to have the cylist that the indicator’s on.
fewer pins than most. The most unusual thing about wearable electronics
Neopixels take power separately from the data isn’t the hardware, it’s how they’re connected together.
input. See figure 1 for details of how to wire them up. You could use wires, and sew them onto the fabric,
In order to use them you’ll need the library from but the downside to this is that it’ll make the fabric
Adafruit. You can find details of how to install this on stiff, particularly if there are a lot of wires. Most
the official website (http://learn.adafruit.com/ wearable projects use some form of conductive
adafruit-neopixel-uberguide/arduino-library). sewable. There are sewable ribbon cables and
The best way to prototype wearable projects is with conductive fabrics, but by far the most popular option
alligator clip leads – these are the breadboards of the is conductive thread.
wearables world. In order to make sure everything’s Sewable thread comes in different grades, and
working properly, you can connect up your neopixels most should work with this project. This is a really
as shown in figure 1, and run the strand test example small wire of twisted stainless steel strands. You don’t Fig 3: The blue wires are
conductive thread sewn in;
sketch that comes with the neopixel library. You’ll need any special equipment to use it, as it can be cut
all others are wire.
need to adjust the number of neopixels, and the pin
that they’re on in order to run it. It’s best to use just
two neopixels in a test, for reasons we’ll explore later.
You’ll see in a bit that we actually split the neopixels
up into two strips of two. This is just to make the
sewing a little easier.
Connecting the circuit
The purpose of this project is to create a cycling jacket
with improved visibility. We used four neopixels sewn
into the back of the jacket to flash red. In addition, we
added switches to enable the outermost of the pixels
to be turned into indicator lights. In order to do this, we
need a way to tell the microcontroller that we want to
turn. The easiest way to do this is switches. There are
www.linuxvoice.com 81
TUTORIAL ARDUINO
to have components symmetrically laid out over both
sides, we opted to put it in the middle. The four
neopixels are in a line across our upper shoulders.
This makes them more visible to drivers, and also
shows the width of the cyclist. There’s a very bright
light on the front of our bike, so we didn’t add any
additional LEDs to the front, though you could easily
do this. The buttons are on either side of the chest
making them easy to press with either hand.
You could put the buzzer anywhere on the jacket,
but we added it to the collar so it is close to the
Lilypad and easy to hear.
Assemble the wearable circuit
The full circuit can be built up bit by bit. The first step
is to get the lights working properly, and to do this you
need to decide where the LEDs should be. This may
The first neopixels sewn
with scissors and sewn with ordinary needles. We sound simple, but it can be surprisingly confusing to
in. We got the alignment
a little wrong so the used three-ply and got through about 30 feet work out what goes where when the jacket isn’t being
conductive thread takes a (including wastage and mistakes). worn. It’s easiest to put the jacket on, and get an
longer path than it needs Perhaps the biggest consideration when laying out assistant to mark the right places with a pen or pencil.
to, but it still works. a wearable circuit with conductive thread is that none Because we’ve arranged the neopixels in two strips
of the connections can cross, because the wire isn’t of two, the wiring gets a little convoluted right from
insulated. If you’re using thick fabric you could try the start. If you want, you could simplify this by having
crossing on opposite sides of the cloth, but there’s a a single strip, and have the Lilypad on one side of the
pretty good chance that you’ll run into problems. Good jacket, though this may cause complications with the
circuit design should minimise the number of times buttons. See figure 3 for details of how we laid it out.
that two threads need to cross, and in simple circuits, The sewing itself is straightforward. If you’re feeling
it may not have to happen. fancy, you can alternate the lengths of the stitches so
We solved the that those on the outside are shorter than those on
problem by using short the inside, to make the conductive thread less visible.
“The circuit can be built up bit lengths of insulated However, we wear our electronics like a badge of
by bit – the first step is to get wire when paths had to honour. Similarly, we’ve mounted all the circuitry on
cross. In principal, you the outside; this could go inside, but it could chafe if
the lights working properly.” could probably get you weren’t careful with placement.
away with lengths as The tricky parts of sewing is making the
short as an inch just to act as a bridge if flexibility is connections at either end – the key is to loop through
critical, though we used lengths a few inches long to the hole several times, and make sure it’s tight. We
make it simpler. used a drop of glue on to stop the thread coming
In terms of circuitry, our design is simple. Perhaps loose, but better stitchers may not need this. Be
the most important decision for layout is where to careful not to use too much glue, as it can get
place the Lilypad itself, because this will affect how between the thread and the contact and be counter-
everything else connects together. Since we’re going productive. On the neopixel positive and negative
points, you need to continue the rail after the first
pixel. It’s easiest to do the full rail in one thread, and
Introducing Arduino
continue after sewing in the first neopixel. This is
If you’ve not heard of the Arduino, then The real innovation of the Arduino system because the holes are quite small, and it can be hard
you’re missing out on a revolution in was in making them really easy to program. to sew in a second time. We did manage to sew in
microcontrollers. They’re simple boards that There’s a huge library of code that you can
again when we needed to, so it’s not too big a problem
allow a wealth of input and output options. use to quickly build quite advanced projects,
The exact options depend on the board, but and they can be programmed directly from to do it in two threads.
range from 20 IO pins on the Uno and Micro USB with no special hardware. Make sure that you trim the ends quite short, as it
to over 50 on the Due and Mega. Arduinos are programmed in a dialect will cause problems if two threads touch each other.
They don’t have full CPUs, but instead of C++. All programs have at least two Beyond these minor points, it’s no different from
AVR microcontrollers. You can think of these functions: setup() and loop(). setup() is
sewing anything else, so if you know a good sewer,
a bit like really simple System On Chips called at the start, then loop() runs in, well,
(SoCs). They have a bit of flash storage a loop. If you’re at all familiar with C or you may wish to ask for a little help as they will be able
for programs, and a bit of RAM to hold C++, you should find it easy to pick up from to keep it neat.
variables, and a simple processing core. It’s looking at the examples that come with the Already there are sections that need wire, and we
not enough to run an operating system, so IDE. If you’re not, then there are loads of have a few options: you could solder the wires onto
instead you program them directly with no great books and online resources to help you
the Lilypad before you start sewing, or you could
OS underneath. get started.
always take thread off the Lilypad, then loop into the
82 www.linuxvoice.com
ARDUINO TUTORIAL
wires later. We chose to sew the wires onto the board. The complete setup with
This was easy to do and gave the wires more flexibility the battery hanging down.
than if they’d been soldered on. First we stripped about This lights the cyclist
half to three-quarters of an inch of the wire, then we higher up than traditional
looped this through the hole on the Lilypad, making bike lights and make the
sure that the end of the wire poked away from the rider much more visible at
night.
person wearing the jacket. Then we took some thread
and looped it through to make sure there was always a
good contact between the wire and the Lilypad.
To keep the wire in place, we then sewed it in with
some cotton (non-conductive) thread along its whole
length. We bent one end of the wire into a circle (you
could add a drop of solder to help it stay in shape), and
stitched in the thread. These were the most
troublesome contacts, so make sure you loop the
thread around the wire a few times as well as sewing it
in. If you find your circuit isn’t working at any point, use
a multimeter to make sure all the contacts are good.
Programming your jacket
A word of warning before we get started. There are
three LEDs in a neopixel (for red, green and blue). Each
of these can draw 20mA on full brightness. So, for full
white light, that’s 60mA per pixel or 240mA altogether.
The regulator on the Lilypad can cope with a peak
current of 500mA, but a continuous current of only
200mA, and this has to supply the microcontroller,
buttons and buzzer. This means that if you put all the
pixels on white, there’s a good chance you’ll burn out With that warning in place, let’s get started
the controllers. There are two solutions to this. Either programming the jacket. If you’ve not used an Arduino
you can power the neopixels separately with another before, take a look at the boxout on the facing page.
battery (or separate leads from the same battery that The following code will simply test that everything’s
don’t go into the Lilypad), or you could program the working properly, and cycle through a few colours.
Arduino to not have too many of them on at once. #include <Adafruit_NeoPixel.h>
We’ve gone for the latter approach to keep the design
as simple as possible, and we’ve kept our code quite Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(2, 2, NEO_GRB +
cautious. If you want to experiment with brighter NEO_KHZ800);
lights, either power the neopixels separately, or be Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(2, 3, NEO_GRB +
careful not to blow your regulator. NEO_KHZ800);
void setup() {
strip1.begin();
strip1.show();
strip2.begin();
strip2.show();
}
void loop() {
strip1.setPixelColor(0,50,0,0);
strip1.setPixelColor(1,50,0,0);
strip2.setPixelColor(0,0,50,0);
strip2.setPixelColor(1,0,50,0);
strip1.show();
strip2.show();
delay(1000);
strip1.setPixelColor(0,0,50,0);
strip1.setPixelColor(1,0,50,0);
strip2.setPixelColor(0,50,0,0);
The wires coming off the Lilypad make it a little messy, strip2.setPixelColor(1,50,0,0);
but you can’t feel this when you wear the jacket. strip1.show();
www.linuxvoice.com 83
TUTORIAL ARDUINO
solder them. Other than that, it’s just a case of sewing
Washable and weather-proof them in place. It’s best to position them in such as
None of the parts we’ve used are officially housing for the battery and buzzer.
way that the resistors won’t get bent repeatedly, as
weather-proof or washable. That means if Waterproof switches are available, or you this could lead to metal fatigue and breakage.
you get them wet, and they break, you can’t could put the ones we’ve used inside some Once this is done, you can upload the final code.
return them. That said, there’s nothing that flexible plastic cases. Even though the hardware isn’t quite finished yet (we
should get into much trouble if it gets a bit With this done, you would still need to haven’t added the buzzer), the rest of the code will
damp (the piezo buzzer may not fare too power it off during rain because the water
well, and the battery should be kept as dry as could short out some of the connections.
work, and the buzzer will start working as soon as it’s
possible). If you do encounter a spot of rain, The Lilypad and neopixels should stand put in place.
just turn it off, and hopefully, it will survive. up to a dunking (though there aren’t any The code is fairly simple, though a bit long-winded:
Let it drip dry fully (including the inside of guarantees). Adafruit is working on making #include <Adafruit_NeoPixel.h>
the switches) before turning it back on. fully waterproof wearables (see a test here:
Waterproofing isn’t easy, but it should be www.youtube.com/watch?v=P42MzjuEPig)
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(2, 2, NEO_GRB +
possible to make it at least stand up to some though at the time of writing, there isn’t
rain. The first stage would be waterproof anything available for purchase. NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(2, 3, NEO_GRB +
NEO_KHZ800);
strip2.show(); int count;
delay(1000);
You’ll find it this code at www.linuxvoice.com/code/ void setup() {
wearable.tar.gz as jacket_test. strip1.begin();
To upload the code, first plug the Lilypad into your strip2.begin();
computer, then go to Tools > Boards and select strip2.show();
Lilypad Arduino USB (It must have USB at the end). If strip1.show();
that’s not an option, it means you don’t have the latest pinMode(10, INPUT);
version of the Arduino software. You’ll need to update pinMode(9, INPUT);
this before continuing. pinMode(11, OUTPUT);
The first line of the code just includes the library count = 0;
(make sure you’ve installed this first – instructions }
above). You then need to set up the strips with a call void loop() {
to Adafruit_NeoPixel(). The first parameter is the
number of pixels in the strip, the second parameter is if(digitalRead(9)){
the pin number they’re on, and the final parameter is if(count < 8){
set depending on the version of the neopixels you’re analogWrite(11,100);
using. The above is for version two, which are the only #left indicator on
ones currently available. }
There are three methods that you can call on the else {
strips that you’ve set up: begin() has to be called at analogWrite(11,0);
the start to set everything up; show() has to be called #left indicator off
any time you make }
“Once you’ve got everything a change to a
pixel’s colour,
}
else if(digitalRead(10)){
working, it’s time to move on to otherwise the if(count < 8){
the second stage: adding buttons.” change won’t
be sent to the
analogWrite(11,100);
#right indicator on
pixel; and }
setPixelColor() is used to change the colour of the else {
pixel. This last method takes four parameters: the analogWrite(11,0);
pixel number (starting with 0, the closest to the #right indicator off
Lilypad), and the R,G and B values respectively. }
At this point, we found that our board emitted a }
high-pitched hum due to a noisy power supply. It if(digitalRead(9)==LOW && digitalRead(10)==LOW){
wasn’t a huge problem, but it was a little annoying. We analogWrite(11,0);
added a 220μF capacitor between the positive and if(count < 4){
negative rails to stop this. #flash one red light
}
Add buttons to the circuit else if(count < 8){
Once you’ve got everything working, it’s time to move #flash next red light
on to the second stage: adding buttons. These are }
slightly more difficult because you need to solder on else if(count < 12){
the resistors first. See figure 2 for details about how to #flash next red light
84 www.linuxvoice.com
ARDUINO TUTORIAL
} The author has yet to be
else { hit by a car when wearing
#flash final red light the jacket despite cycling
} around the mean streets of
Gloucester at night.
} NB: Linux Voice strongly
recommends wearing
a helmet while cycling,
if (count < 16) {
as brains are soft and
count++; squishy.
}
else{
count = 0;
}
delay(100);
}
Some of the code has been replaced with comments
for brevity. You can find the full code at
www.linuxvoice.com/code/wearable.tar.gz as
jacket_final. Each of the sections with comments is
replaced by a section of setPixelColour() and show()
calls to the various strips.
The loop uses the variable count to keep track of
things flashing. The two new pieces in this are the
digital inputs and the analog writes. You should be
able to see what’s going on here. You have to first set
the pinMode() in setup with the pin number and the
mode you want the pin in. This allows you to read or
write to the pins.
You should now have a working cycling jacket!
Make some noise The analogWrite() function that we’ve used to
The buzzer was simple to attach. We used a drop of control the buzzer is a bit misnamed. It’s not really
glue to attach it to the collar of the jacket, then sewed setting an analogue value, but a digital pulse width
the positive lead onto pin 11 and the negative lead modulation (PWM) value. This means it emits a
onto a ground thread. Sewing onto an already stitched square wave that’s on for the proportion of time you
thread is just like sewing onto a wire loop or a resistor. set it to be (out of 255). So analogWrite(11,0) sets pin
11 to be off. AnalogWrite(11,1) sets pin 11 to switch
on for one 255th of the cycle. analogWrite(11,100),
Equipment
then, sets pin 11 to be on for almost half of the cycle.
You need surprisingly little equipment to produce wearable The frequency of the PWM is dependent on the timers
computers. In fact, it’s possible that you could do it with of the Arduino. These can be changed, but it’s a little
nothing but a needle and conductive thread. We only used complicated and can have effects on other functions.
two pieces of electronics equipment in producing the
Since we just want to make a noise to alert the
tutorial: a soldering iron and a mulitmeter.
There’s a wide range of soldering irons available in a cyclist to the fact that the indicators are on, we won’t
wide range of price brackets. The soldering in this project bother interfering with it. The code as written should
is about as simple as it comes, so any old iron should do produce a high-pitched beep. If you want something a
the job. If getting a soldering iron for the first time, it’s little more tuneful, there are some example of coding
well worth getting a stand and tip cleaner as well. They
melodies in Files > Examples > Digital in the Arduino
shouldn’t cost much, and make soldering a lot easier.
Usually in electronics tutorials, you’ll see multimeters IDE. The buzzer makes it much easier to check you
listed as useful but not essential equipment. However, in haven’t accidentally left the indicator on.
wearable projects using conductive thread, getting contacts We’ve created a cycling jacket, but exactly the same
is far more problematic than in most projects. Without a techniques could be used to produce all sorts of
multimeter, trying to find what’s causing the problem would
wearable designs. If you’re a pop star embarking on a
have taken us a long time. Because of this, we’re inclined to
say that a multimeter is an essential tool for wearables. A world tour and need something to wear, or feel like
good multimeter will have a continuity indicator that beeps making your own Tron constume, this project is an
if there’s a connection between two points. This enables excellent place to start.
you find the problems with contacts without having to keep
looking at the screen. This isn’t essential, as you can use the
resistance meter to do the same job, though the latter way Ben Everard cycled across Somalia once, and says it wasn’t
requires you to look away from the circuit to get a reading. as dangerous as the time he cycled across Wales.
www.linuxvoice.com 85
TUTORIAL PYTHON
HUNT COMETS WITH
TUTORIAL
PYTHON AND OPEN DATA
Hunt for celestial bodies from the comfort of your own home,
ANDREW CONWAY
with the SOHO satellite and the power of Python.
W
ould you like to discover a comet? Of domain, as with almost all NASA data, and although
course you would. But perhaps the it’s only looking at a few degrees of the sky around the
thought of staring into the void with giant Sun, this is a good place to find comets, as explained
binoculars or a telescope, night after freezing night, for in the Sungrazers boxout, right. LASCO actually has
years on end, to find just one, tiny smudge might be several cameras, but we’ll be using its C3 camera, as
less appealing. How about discovering a comet while its smaller field of view makes it easier to work with.
sitting in a warm room wearing only your underwear, In a typical LASCO image, there’s a circle in the
or better still, getting your computer to do it? centre representing the disk of the Sun (called
It may surprise you, but we cannot predict when the photosphere in astronomers’ lingo) but that’s
comets will appear in our skies. Halley’s Comet, and deliberately blotted out by a larger disk so we can see
a few others, are exceptions to the rule. Most comets fainter objects around the Sun. The fuzzy stuff is the
are spotted by chance as faint specks moving through corona, the outer atmosphere of the Sun and the start
the stars, and that’s what we’ll be looking for using of the solar wind – LASCO’s main purpose is to study
a proven source of images: the LASCO instrument that. The SOHO spacecraft is in orbit around the Sun,
on the SOHO satellite (SOlar and Heliospheric and LASCO keeps it in the centre of its view, which
Observatory). Its image data is released under public means that stars, planets and comets will all be seen
moving across the image.
MY GOD… IT’S FULL OF STARS Spot the difference
Finding a comet does not involve frightening physics
– it’s more like a game of spot the difference using
many images. It’s tricky because there are lots of
objects that can be confused with a comet.
1
6 The easiest objects to rule out are planets. Mercury,
Venus, Mars, Jupiter and Saturn are all very bright and
so easy to spot, as shown in the blue LASCO C3
image (left). Uranus and Neptune and a host of other
objects such as Pluto and asteroids are much fainter,
5
but they too can be ruled out because we know where
2
they are going to be at any time. The Earth doesn’t
make an appearance in SOHO images because it is
always behind the satellite.
4
Stars can be easily identified because their
3
movement over time is predictable: they march
across the image in formation from left to right, at
about three pixels per hour in LASCO C3. Comets
usually move diagonally, and at a different rates.
So once stars and planets are ruled out, anything
that’s left must be a comet, yes? Unfortunately not.
There are many comet-like smudges on all SOHO
images that are caused by cosmic rays. These are
high energy particles from anywhere in the cosmos
that strike the detector and fool it into thinking that
light has been detected. Fortunately, these are easy to
A view from SOHO’s LASCO C3 camera that shows many stars, including the Pleiades star rule out because they only affect one image. If the
cluster (1) along with four planets, which are overexposed with horizontal lines running smudge is present in one image, but completely gone
through them. From left to right: Mercury (2), Saturn (3), Jupiter (4) and Venus (5). Also, the
Sun is blowing off a Coronal Mass Ejection (CME) to the top left (6). Most of the blobs are
in the next, then it’s a cosmic ray.
not stars or planets or comets, but are in fact cosmic rays striking the detector. Before automating any task, it’s informative to try it
manually. Thankfully that’s easy to do here because
86 www.linuxvoice.com
PYTHON TUTORIAL
some test examples are available at the sungrazer
comet page at the US Naval Research Lab (yes, the Comets and sungrazers
US military let their staff research comets… but why is
a long story!). If you go to http://sungrazer.nrl.navy. Comets are often described as dirty It’s thought that a big comet broke up back
snowballs. They are lumps of loosely in the year 1106 AD and fragments of that
mil/index.php?p=guide and scroll down you’ll find a bound ice, rock and dust, left over from the have provided us with many great sungrazing
section called Strategy And Tips and in that is a list of formation of the Solar System. Most of them comets over the centuries. This group is
Zip files that you can download so you can hone your hang around in what’s called the Oort cloud, called the Kreutz sungrazers, and 85% of
comet-hunting skills. Inside each Zip file you will find a which is well beyond the orbit of all the Sun’s comets found by SOHO are in this group.
series of LASCO images, and a cheat-sheet telling you planets. Once in a while, something disturbs
the cloud and a comet is sent into the inner
where the comet is (you’re not going to peek first, are
Solar System, and then we might see it.
you?) Download the Zip file and open up the first Some comets, called sungrazers, pass
image in the series using your image viewer. Click on very close to the Sun, which has a surface
the Next button (the default image viewers in Ubuntu/ temperature of about 5500°C and is chucking
Unity and Slackware/KDE both have one) and look at out energy in the form of electromagnetic
radiation (ie light) with a power of about
the sequence of images. Unless you have the visual
3.8×1026W (yes, that W means watts, the
acuity of Robocop, you will not see a comet, but same unit used for lightbulbs!) Each square
instead gain an appreciation for how difficult it can be metre of the solar surface emits energy at
to find one, even when you know it’s there! a rate equal to 62,000,000 W – think 62,000
bars of an electric fire. Even if these numbers
boggle your mind, I’m sure it’s clear that
Manual experience this is going to cause a problem for an icy
Take a deep breath. Pour yourself a relevant beverage object like a comet. In fact, many comets
(I like coffee or Raspberry Pi brewed beer) and read don’t survive a close encounter with the
the instructions on the sungrazer page more carefully. Sun. In December 2013, Comet ISON looked
There’s one important clue that will narrow down your promising, but it perished in the intense solar
radiation. Other sungrazers fare better, but
search: most comets approach the Sun from a are much disrupted, such as comet Lovejoy
particular direction that depends on time of year. Have in 2011, pictured. Luckier ones will be Kreutz sungrazer comet Lovejoy only
a look at this page to get an idea of where to look and fragmented into many small pieces, and each just survived its close encounter with
when http://sungrazer.nrl.navy.mil/index. one will become a comet in its own right. the Sun in late 2011.
php?p=comet_tracks. Even with this information, you
might still find yourself tearing your hair out, because
some comets are very faint. Try the example named You should now be able to appreciate our plan: 1)
soho1264, because that comet is relatively bright. If load a pairs of images; 2) difference them; 3) clean the
you flick back and forth between the images taken at differenced image; 4) identify objects; 5) repeat and
1718 and 1742, you should be able to see the comet track objects in subsequent images. We’ll concentrate
PRO TIP
in the bottom-left corner moving towards the centre of on 1–4, because if these are done right, step 5 is
These techniques are
image. (Did you have to peek in the cheat-sheet? It’s relatively easy.
useful for things besides
OK, I did too first time round.) comet hunting, such as
Automating with numpy, scipy and matplotlib image processing.
First, install the new Python modules we’ll need. On
Debian-based distros:
sudo apt-get install python-numpy python-scipy python-
matplotlib
Numpy is a numeric library for Python that provides
lots of new ways to work with arrays. Scipy is a library
that performs all kinds of science-related data
processing, and Matplotlib will make short work of
displaying the images. We’re going to use numpy and
Scipy to load up an image file and turn it into a 2D
array of numbers. You can put the following
commands in a file called comet.py, save it and enter
python comet.py on the command line, or you can
just enter python on the command line and type them
in line by line. First, we’ll load up the first image of the
soho1264 that shows the comet:
import scipy
This image shows the difference between images taken at
image1=scipy.misc.imread(‘full_soho1264_070205_1718.gif’,
17.18 and 17.42 on 5th Feb 2007 by SOHO LASCO/C3. Red
blobs show features present at 17.42 but not at 17.18 and flatten=1)
vice versa for blue blobs. The broad line in the top-right of import matplotlib.pyplot as plt
the image is the pylon holding the central coronagraph disk imgplt=plt.imshow(image1)
in place. The inset shows the area around the comet. imgplt.set_cmap(‘gray’)
www.linuxvoice.com 87
TUTORIAL PYTHON
plt.show()
You should now see a LASCO C3 image in a
Matplotlib window. We’ve loaded the image using
imread and flattened it, which means each pixel
becomes a brightness value with no colour
information. Each value will be a float between 0.0
and 255.0 inclusive and is stored in the Numpy array
called image,1 which has dimensions 1024 by 1024.
We then display the image with the ‘gray’ colour map.
Next, we’ll take a difference of two images. Close
the first image window and enter the following in the
same interactive Python session (or into your .py file):
image2=scipy.misc.imread(‘full_soho1264_070205_1742.gif’,
flatten=1)
import numpy as np
diff=np.subtract(image2,image1)
imgplot=plt.imshow(diff) Comet Lovejoy (officially C 2011 W3) nearing the Sun, as
imgplot.set_cmap(‘bwr’) seen by SOHO LASCO’s C2 camera.
plt.show()
We’ve loaded the image taken 24 minutes later at towards the Sun is strongly suggestive of a comet,
17.42, then used Numpy’s subtract function, which but based on two images alone we can’t be sure that
takes each pixel in the second image and subtracts it’s not just a happy coincidence of cosmic rays.
the value of the pixel at the same co-ordinates in the
first image and returns the result to a new array we Clean and identify
call diff. We then display diff using the colour map Starting with the diff image we obtained above, we’ll
bwr, which stands for blue-white-red. This means that now produce a cleaned image containing only objects
features that only appear in the second image show that showed up blue:
as red; features that only in the first image show as x=diff[824:924,100:200].astype(int)
blue; and areas of no difference are white. xt=np.where(x<-50, x,0)
If you look closely at the difference image, you’ll see d1=np.where(xt==0, xt,-1)
that there are many isolated blue or red blobs that First we convert the diff array to type int and select
correspond to cosmic ray artefacts only present in a 100 by 100 square in the lower-left corner. This may
one or other image. In a few places there is a red spot seem like a cheat, but the sungrazer site tells us that’s
immediately to the right of a blue spot – these are where a Kreutz sungrazer would enter the image in
stars. If you look very carefully at the bottom-left of February. On the next line we use Numpy’s where
the image, and if your monitor is very clean, you might command to set all pixels that are greater than -50 in
just see the comet: a faint red smudge above and to value to zero. It works by testing each pixel for the
the right of the a similar blue smudge. The fact that condition specified in the first argument, x<-50: if true,
this smudge is moving diagonally across the image the second argument is used to fill the value in new
pixel array, and if not, the third argument is used. The
resulting array will only contain strong blue blobs, that
Scipy’s label function
is, features prominent in image1 but not image2. We
Left: A 4 by 4 image, in which three pixels containing the top left two pixels and the one then use the where command again to set all
(shown in cyan) have the same value, is at bottom right, so label will return a 4 by 4 remaining non-zero pixels to -1, which will make
given to label to be scanned with a 3 by 3 array labelling them as two separate blobs,
identifying the blobs much easier. We are being rather
grid. Right: No 3 by 3 grid can be drawn here labelled as 5 and 6.
brutal here and throwing away a lot of data, eg
assuming pixels between -50 and 0 are uninteresting
noise, but we can fine-tune parameters later if we
suspect we’re missing comets.
We now have an image d1 in which each pixel is
either 0 or -1. Next, we use Scipy’s cunning label
function to identify all blue blobs, which are just
groups of pixels with value -1:
from scipy.ndimage import label
l1, n1 = label(d1, scipy.ones((3,3)))
There’s a lot going on in that second line. We give
the label function the cleaned differenced image d1
and also scipy.ones((3,3)), which is a 3 by 3 array in
which all elements are 1. This is asking label to look at
The label function groups adjacent pixels with the same value into numbered blobs.
all possible 3 by 3 grids within the image, and if it finds
88 www.linuxvoice.com
PYTHON TUTORIAL
two pixels with the same non-zero value inside a 3 by Tracks of objects for
3 grid, it assigns them to the same blob. LASCO C3 images on 5 Feb
Next, we repeat all of the above to label red blobs, 2007. Dots shown show
positions starting at 17.18
except with a threshold of +50:
(light red) and ending at
xt=np.where(x>50, x,0)
20.42 (white). The time
d2=np.where(xt==0, xt,1) intervals vary, eg there’s an
l2, n2 = label(d2, scipy.ones((3,3))) hour between the fourth
The end result is that n1=11 (11 blue blobs) and and fifth image. The comet
n2=15 (15 red blobs). The l1 array is a 100 by 100 is moving diagonally, and
array in which each element is zero (nothing there), or stars horizontally.
is a number between 1 and 11 indicating which blue
blob that pixel belongs to, with the l2 array being
similar except that it contains 15 blobs.
Great success
We’ve now narrowed down our search from many
thousands of blobs to about a dozen. That’s pretty
good going!
It’s worth visualising our cleaned difference images
to appreciate how good (or brutal) our clean-up has cosmic ray coincidences should be ruled out and we’ll
been. To do this, add together the cleaned red and be left with tracks of stars and, hopefully, comets.
blue images with imshow(d1+d2) and use the bwr With just a few more lines of code it’s possible to
colour map, as described above. You should be able produce the tracks shown based on seven images
to see a few pairs of red and blue blobs that are stars, from 17.18 to 20.42. The comet is now pretty obvious
and another pair moving diagonally – our comet! because of its diagonal motion. The code we’ve
We now need to pair red and blue blobs that are outlined above could do with a lot of refining because
within a certain radius of each other. The sungrazer it’s probably doing too good a job of rejecting false
website says that Kreutz group comets typically move positives, to the point where it might be missing real
less than 10 pixels per hour in C3 images, and we comets. The best way to improve it is to try it out on
know that stars move even more slowly than that, so other image sequences with known comets in them
let’s set our search radius to a little more than that, at and experiment with some choices we’ve made, such
15 pixels per hour. There’s a 24-minute time difference as the noise threshold of 50, the 3 by 3 label search
between our two images, so our search radius will be grid and the 100 by 100 sub-image.
(24/60)*15=6. Next we’re going to look at all pairs of
blobs and see which red and blue blobs are within our Go discover comets, and more…
search radius: You can download SOHO data from here
import scipy.ndimage.measurements http://sohowww.nascom.nasa.gov/data/realtime-
pairs=list() images.html for any time period, including near
centres1=scipy.ndimage.measurements.center_of_ real-time images. Images are now provided as JPEG
mass(d1,l1,range(1,n1+1)) files rather than GIFs, but all the code above will still
centres2=scipy.ndimage.measurements.center_of_ work. If you do think you’ve spotted a comet, read the
mass(d2,l2,range(1,n2+1)) instructions on the sungrazer comets page on how to
for c1 in centres1: report it. In the same way that a well-constructed bug
for c2 in centres2: report is more likely to get attention from a developer,
if (c1[0]-c2[0])**2 + (c1[1]-c2[1])**2 < 6*6: professional scientists are more likely to accept your
pairs.append((c1,c2)) discovery if it’s presented to them in a way that shows
print len(pairs) you know your stuff.
This code uses Scipy’s center_of_mass function to Don’t stop at comets; you can apply the principles
calculate the centres of all the blobs. Then it loops introduced here to look in other data sets, to hunt for
through all possible pairs and if two blobs are within a asteroids or sunspots, for example. You could also
circle of radius 6 pixels they’re appended to the pairs analyse satellite images of the Earth’s surface, or even
list. The result is that there are 10 pairs. turn your attention to medical images. The human
To investigate further we’d need to repeat the above race is drowning in data, especially image data, and so
procedure for the next two images in the sequence, there’s every chance that, with a bit of hard work, you
generating a new list of pairs. Since our new image1 could make a real contribution to research by honing
is just our old image2, we can expect the new blue and applying basic image processing skills.
blobs to have the same centres as our old red blobs.
In this way, we can match up new and old pairs and
track objects as they move from image to image. Andrew Conway is interested in computers, science, writing
and humans, and has been a happy Linux user since 1995.
After we’ve tracked them over several images, all
www.linuxvoice.com 89
TUTORIAL PiBEACON
RASPBERRY PI: BUILD
TUTORIAL
AN EMERGENCY BEACON
Combine simple Python modules with hardware
LES POUNDER
programming to build your own emergency distress beacon.
T
he background to this project is that I’ve been prototype stage the best solution was every
WHY DO THIS?
working with a class at Mereside Primary Raspberry Pi hacker's best friend, a plastic lunchbox.
• Keep relatively safe from School in Blackpool. The children were The PiBeacon was entered into PA Consulting's Pi
natural disasters.
learning about natural disasters such as tsunamis Awards event on 2 April 2 2014. I am proud to say that
• Program components
connected to the and earthquakes. During the course of their lessons my team came second in their year group and really
Raspberry Pi's they learnt that one of the first issues faced by the proved how far they had come in such a short time. I’d
GPIO pins. victims was a loss of communication as mobile like to say a very big “well done” to the hackers from
• Learn code concepts phone towers were quickly damaged. The children Mereside Primary School.
including loops, data
storage and conditional worked as a team to understand the impact that this
statements. would have and how they could make a difference. Pin reference
Their idea was to create a beacon that attracts help Throughout this tutorial, I will refer to the GPIO pins of
in three ways. the Raspberry Pi via their board reference. With pin 1
YOU WILL NEED: An FM radio transmitter, that can be tuned to work being the top-left pin, nearest the SD card slot, and pin
• Raspberry Pi (Model A on many different frequencies. 2 being directly to pin 1’s right. Please refer to the
or B can be used). An LED unit, to visually attract people to the beacon. guide, right, for the location of 3.3V, 5V and ground
• Battery with integrated A buzzer, to attract people using audio output. pins. Don't use use these pins unless instructed to do
solar cell (or you could
use the Pi powered from
The beacon must be completely self supporting so, but you can use any other pin in your program.
the mains). and have its own self-charging power source. To The only user with permission to use the GPIO pins
• PiGlow (Available from accomplish this we found a cheap USB battery pack in Raspbian is root, so in order for you to use the GPIO
Pimoroni.com). with a built-in solar cell on Amazon, but for the in Idle, open a terminal and type
• Buzzer/piezo speaker. purposes of this tutorial you can just plug into the sudo idle
• Soldering iron (optional mains. Type in your password (by default in Raspbian this
– I’ve breadboarded the
example diagram for To keep the project as simple as possible we'll use is raspberry) and press Enter. In a few seconds the
this tutorial). only one method of input, which is a single push editor for our Python code will be on the screen. By
• Jumper wire (female button that when pressed will launch the Python code. launching Idle in this manner you will be able to
to male, from Pi to Finally, the project must be weatherproof, and at this access the GPIO pins – just remember to open any
breadboard and male
to male for breadboard Python programs using the File > Open menu option.
connections.
• 100 ohm resistor Building the project
• Momentary switch This build is not complex but it does have four areas
(push button). that need to be carefully wired together. If you are
• Breadboard. unsure about your wiring, please ask someone to
• Insulation tape. check before you connect any power to your Pi or
• Micro USB to USB lead attached components.
(to power the Pi).
Antenna This is the most simple section of the
• 20cm of wire (shielded,
but you could use a build. All you will need to do is attach a maximum of
female to male jumper 20cm of wire to pin 4 of your Raspberry Pi. The
wire). greater the length of wire, the larger your antenna,
• An FM radio tuned in to but also the greater your signal may become.
103.3MHz.
Please refer to the section on radio transmissions
for safety instructions.
Button I used a momentary switch, attached to pin
8 to act as the only method of input. The switch is
attached to 3V power from pin 1 and a resistor is
used inline with Ground to ensure that the switch
does not accidentally trigger from a slight press.
The finished PiBeacon Buzzer A simple buzzer is attached to pin 26 and
project encased inside its Ground (pin 20). This buzzer is used as an audio
protective lunchbox shell. output that will send a message in Morse Code.
90 www.linuxvoice.com
PiBEACON TUTORIAL
PiGlow Rather than use just one LED, we used 18 Pin diagram for Model B
super-bright LEDs courtesy of Pimoroni’s tiny board. Raspberry Pi.
Normally this board covers all the GPIO pins, but
thanks to a phone call with Jon and the team we
worked out the minimum number of pins necessary,
and these are as follows:
Pin 1 3V3 Logic level voltage.
Pin 2 5V LED source current.
Pin 3 SDA i2c Communications.
Pin 5 SCL i2c Communication.
Pin 14 Ground (GND).
Pin 17 Logic level voltage.
Remember when inserting the wires into the PiGlow
that you will need to work out where each pin should
be inserted. When the board is attached to the GPIO, For this project, piglow.py will need to be in the
the “P” of PiGlow should be near the SD card slot. same directory as our beacon.py code. With these
Once you have located Pin 1 of PiGlow, insert a red files downloaded, try out some of the examples to
jumper wire to help you remember that Pin 1 is 3.3V ensure that your PiGlow board is working correctly.
power, and refer to the diagram for more information. Our final requirement is PiFM, a library of code
that we can easily drop in to our project to add an
Set up PiGlow, i2c and PiFM FM transmitter. You can download the library from
PiGlow uses something called i2c to control the 18 www.icrobotics.co.uk/wiki/index.php/Turning_the_ PRO TIP
onboard LEDs, and by using i2c PiGlow is able to use Raspberry_Pi_Into_an_FM_Transmitter. Extract the Project files for the
PiBeacon are available at
far fewer wires than a conventional series of 18 LED files to the same directory as your beacon.py and https://github.com/lesp/
would require. I2c was developed by Philips in the piglow.py files. I kept the example audio file – the Star PiBeacon .
1980s as a means to send data to multiple devices Wars theme – as the audio to play over the airwaves.
using the a minimal number of wires. It's useful, but You could also use any 16-bit mono WAV file.
the Raspberry Pi does not have i2c set up by default.
To set up i2c on your Raspberry Pi, download a Coding the project
copy of Michael Rimmican’s excellent setup script You can download the code for this project from my
from GitHub: https://github.com/heeed/pi2c. GitHub repository: https://github.com/lesp/PiBeacon.
Open a terminal, navigate to where you downloaded We coded this project in Python 2.7 due to its
the file and then used chmod to make it executable: mature collection of libraries and documentation.
chmod +x pi2c.sh Libraries enable us to reuse code that other people
Then run the script using sudo or as root: have written. I used four libraries in my code: PiFM to
sudo .pi2c.sh control the radio transmitter; RPI.GPIO for GPIO
After a few minutes your Pi will be reconfigured to access; time to add a delay function to my code; and
use i2c; at this time it would be prudent to reboot your PiGlow to control the PiGlow LED board.
Pi to ensure that the configuration is complete. Import the libraries into our code like so:
Now you will need to download the Python library import PiFm
for PiGlow, and luckily Jason Barnett has created a import RPi.GPIO as GPIO
great library for us to use, which is available here: from piglow import PiGlow
https://github.com/Boeeerb/PiGlow. from time import *
Diagram of the completed
setup. Remember to pay
careful attention to the
GPIO pins for PiGlow.
www.linuxvoice.com 91
TUTORIAL PiBEACON
Next I created two variables: button_pin and buzzer, So now that we have a conditional statement, what
and in each one I stored the value of the GPIO pin do we want it to do if the condition is true? Well firstly I
used for each, respectively 8 and 26. Variables are want it to print “Button Pressed”, for debugging
great, as they enable our program to retain purposes, so that I can see that the code has worked.
information and act as a data storage system. Then I want the code to start PiFm and play the Star
Variables are used to replace hard coded values in our Wars theme. The code is as so:
code. For example I could’ve used the integers 8 and print(“BUTTON PRESSED”)
26 throughout my code, but if I wanted to change PiFm.play_sound(“/home/pi/sound.wav”)
those numbers to something else, then I would have Once PiFm has finished playing the audio I want to
to go through every line of code to make the change. then start a loop that iterates three times. Inside this
Because we're using a variable, we can simply loop I want the buzzer and PiGlow to provide output in
change the value of that variable once and that the form of Morse code – more specifically the
change is reflected internationally recognised SOS message (… - - - …).
whenever we refer to To create the iterated loop I used a 'for' loop with a
“Variables enable our program the variable name. range that starts at zero and ends before three, so it
to retain information and act as In order to use the
GPIO we need to tell
goes 0,1,2. A 'for' loop is a loop that will iterate through
a list, range or tuple until complete, giving us a the
a data storage system.” Python how we want to limited number of loops that we require. This gives us
use it: the three iterations that we require. Here's the code:
GPIO.setmode(GPIO.BOARD) for i in range(0,3):
This tells the Pi that I wish to use the numbering as You might be wondering where the i came from?
per the earlier diagram. Well, this is a variable that we've declared “on the fly”.
GPIO.setup(button_pin , GPIO.IN) You could replace i with x, y or z if you wished. The
GPIO.setup(buzzer , GPIO.OUT) range(0,3) bit instructs the for loop to start at 0 and
These two lines tell the Pi that our button, attached count to 2, as 3 is the limit of our range. By counting
to pin 8, is an input and that our buzzer on pin 26 is an from 0 to 2 we have 3 loops.
output. Remember that the variables button_pin and
buzzer both contain the pin reference for each. Send signals
To make it easier for me to use the PiGlow function, Now to make the buzzer and PiGlow come to life. We
PiGlow(), I next create a variable called piglow: have to tell the GPIO to send electricity to the buzzer,
piglow = PiGlow() and to do that we use the Boolean term “True” to say
Later on I use the code that we want to turn the power on. Remember I earlier
piglow.all(128) set up the GPIO pin 26 as an output and used a
to set all of the LEDs to half brightness, but I’ll cover variable called buzzer to represent this. So now to
that in more detail later. send the power to the pin I use the following code.
Now we come to the main part of the program. In GPIO.output(buzzer, True)
order to control the program we use an infinite loop, To turn the buzzer off I change the True to False.
which in Python is 'while True:'. This is the simplest For PiGlow it is a little bit different but by no means
kind of loop, and for the purpose of this project, is the a challenge. To illuminate all of the LED on the board I
most practical. Any code contained in this loop will use piglow.all. Now as you will see in the code there is
run over and over until it is stopped. a number contained in brackets. This number is the
The next line is a conditional statement that checks brightness of the LED, with 0 being off and 255 being
to see if the button has been pressed. This, coupled full brightness. I used 128, which is the halfway point
with our infinite loop, enables the program to between the two. A word of warning: PiGlow is
constantly check for user input via the button: extremely bright, so be careful with your eyes. Here's
while True: how to turn the LED on.
if GPIO.input(button_pin)==1: piglow.all(128)
Radio transmissions
This project uses a Python library called PiFM, on any frequencies that are reserved for emergency localised. The use of SOS audio messages or SOS
which is available from www.icrobotics.co.uk/wiki/ services or aviation, otherwise you will get in Morse code is also not to be broadcast on the radio
index.php/Turning_the_Raspberry_Pi_Into_an_ trouble with the authorities. Please refer to the spectrum, so please just play the theme from Star
FM_Transmitter. This library is what powers the official guidance available from http://stakeholders. Wars or Transformers and save the emergency for
PiBeacon’s radio transmissions. It's very versatile, ofcom.org.uk/enforcement/spectrum-enforcement/ the real thing.
with extra functionality such as broadcasting in law, as there are certain regulations that must be If you are still unsure then the best resource to
stereo and using a microphone connected to your followed when using radio transmitters. use is your local amateur radio group (basically a
Pi to broadcast live audio over the airwaves. The FM transmitter is also very powerful – so LUG for those interested in radio related topics). A
Transmitting radio signals is not to be taken powerful in fact that if used incorrectly it can cause quick Google search will find your local group, who
lightly, and great care should be taken when using interference. Best practice would be to reduce the will be able to answer any questions that you may
this project. Make sure that you are not operating length of wire used in the build so that the effect is have. Remember: hack responsibly.
92 www.linuxvoice.com
PiBEACON TUTORIAL
And to turn off the LED we create a new line, which is
identical to before but with the (128) changed to (0).
To control which letter is being communicated in
Morse I used a delay function, which in Python is
called sleep(). To create a dot, which is a short beep in
Morse I kept the delay to a minimum and set it to 0.5,
which is half a second. To create a dash, which is a
longer sound, I used a delay of 1, which is 1 second. In
code the delays look like this.
sleep(0.5) # For a DOT
sleep(1) # For a DASH
The last section of code is the else statement.
When using a conditional such as if, we can use an
else statement to capture any unexpected conditions.
In this case the else statement is used when no user
Assembling the final
input is detected, it will print “Waiting for input” over piglow.all(0)
prototype and soldering
and over. As soon as user input is detected, the else #End of DOT, now a 1 second pause the connections was
condition is no longer true and the if condition, when sleep(1) essential to qualify for the
the button is pressed, is now true. #DASH PA Consulting competition.
Before you test your project it would be prudent to GPIO.output(buzzer, True)
check all of the connections and wiring before you piglow.all(128)
start the program. Once you're happy that everything sleep(1)
is as it should be, run your code. You can do this in Idle GPIO.output(buzzer, False)
via the Run > Run Module menu item. piglow.all(0)
Grab your radio and tune in to 103.3MHz FM, which sleep(1)
is the default frequency that we will be using for this #End of DASH, now a 1 second pause
project. You should now see the shell printing “Waiting #DOT
for input” so go ahead and press the button. A GPIO.output(buzzer, True)
moment later you should hear the theme from Star piglow.all(128)
Wars playing through your FM radio. A few minutes sleep(0.5)
later, once the music has finished, your buzzer and GPIO.output(buzzer, False)
PiGlow will start emitting a message in Morse code. piglow.all(0)
Congratulations: you have built a working PiBeacon! #End of DOT, now a 1 second pause
sleep(1)
Bonus points – change your message #DOT
In this project we use sleep() to control the delay for GPIO.output(buzzer, True)
our beeps and flashes, with half a second for a dot piglow.all(128)
and one second for a dash. So using just dots and sleep(0.5)
dashes we can communicate text and numbers. GPIO.output(buzzer, False)
Instead of broadcasting SOS, let's say “Linux Voice”. piglow.all(0)
First of all we'll refer to a chart of Morse Code. #End of DOT, now a 1 second pause
L DOT DASH DOT DOT sleep(1)
I DOT DOT So what have we accomplished here?
N DASH DOT We have built the hardware that powers our project.
U DOT DOT DASH Using Python and libraries from external sources
X DASH DOT DOT DASH we have created the code that controls the
V DOT DOT DOT DASH components in the beacon.
O DASH DASH DASH We also used programming concepts such as Loops,
I DOT DOT to control the flow of our program and to repeat
C DASH DOT DASH DOT repetitive tasks; variables, to store the values of GPIO
E DOT pins in one section of code, enabling us to quickly
Why don’t you try altering the example code to output make changes to one value that are reflected
this message instead? throughout the program; and conditionals to control
Here’s how to write L in Morse using Python the flow of our program by using logic. The next step
#The letter L in Morse code. is to play with the lights on the PiGlow – you could
#DOT even create an animation.
GPIO.output(buzzer, True)
piglow.all(128) Les Pounder is a maker and hacker specialising in the
sleep(0.5) Raspberry Pi and Arduino. Les travels the UK training
teachers in the new computing curriculum and Raspberry Pi.
GPIO.output(buzzer, False)
www.linuxvoice.com 93
TUTORIAL PYTHON & libvirt
CONTROL VIRTUAL MACHINES
TUTORIAL
WITH PYTHON AND LIBVIRT
Learn ways to automate VM management when GUIs
VALENTINE SINITSYN
and simple shell scripts aren’t enough.
I
f you read Linux Voice, you are probably a Linux or alike) and open an interactive Python shell (>>>
WHY DO THIS? user. And if you use Linux, you most likely know denotes prompts in the listings below). No root
• Automate virtual what virtualisation is. Many mainstream privileges are initially required, but you may be asked
machine maintenance
and management distributions include KVM and virt-manager these to obtain them when needed.
processes. days, and you can easily install Oracle VM VirtualBox, $ python
• Batch-create virtual Xen or such like. Usually, they provide some form of >>> import libvirt
appliances for clouds, GUI, so why on the Earth would you want to try >>> conn = libvirt.openReadOnly(‘qemu:///system’)
integration testing and
so forth. virtualisation from a Python script? Here, we import the libvirt module and open a
• Get to know the de-facto If you just want to try out a new distro, you probably connection to the hypervisor specified by the URI (note
standard virtualisation wouldn’t. However, if you use several virtual machine the three slashes). In this tutorial we’ll work with
toolkit for Linux. managers (VMMs, or hypervisors) in parallel, or create Qemu/KVM, which is probably the most ‘native’ VMM
pre-configured virtual machine appliances (say, for a for libvirt. /system means we connect to a local
cloud deployment), Python may come in handy. system-level hypervisor instance. You may also use
qemu:///session to connect to the local per-user
Meet libvirt Qemu instance, or qemu+ssh:// for secure remote
Born at Red Hat as an open-source project, libivrt has connections. We are not going to define new domains
become an industrial-grade toolkit that provides a now, so the restricted read-only connection will suffice.
generic management layer on top of different For starters, let’s check what your host is capable of
hypervisors, using XML as a mediation language. when it comes to the virtualisation:
It’s been adopted by many Linux vendors (if you have >>> xml = conn.getCapabilities()
virt-manager, you have libvirt) and has bindings for >>> print xml
many programming languages, including Python <capabilities>
(version 2 and, starting with libvirt-python 1.2.1, <host>
Python 3). Libvirt can create (or “define”, in its <uuid>20873631-dad7-dd11-885a-08606eda31ae</uuid>
parlance), run (“create”) and destroy virtual machines <cpu>
(called “domains” here), provide them with storage, <arch>x86_64</arch>
connect them to virtual networks that are protected <model>Westmere</model>
by network filters, migrate them between nodes and <vendor>Intel</vendor>
do other smart things. <topology sockets=’1’ cores=’4’ threads=’1’/>
However, libvirt has no convenient tools to work <feature name=’vmx’/>
with XML, so you’ll need to know the format ...
(described at libvirt’s website, www.libvirt.org) and </capabilities>
use xml.etree or similar. Let’s see it in action. Install You see how the XML is used to describe the host’s
libvirt’s Python bindings (usually called python-libvirt capabilities. Libvirt identifies objects (hosts, guests,
networks etc) by UUIDs. My host is a 64-bit quad-core
Intel Core i5 with hardware virtualisation (VMX)
support. Your results will likely be different.
The XML is quite long (note the ellipsis). Here’s how
you can use xml.etree to get supported guest domain
types and corresponding architectures from it:
>>> from xml.etree import ElementTree
>>> for guest in tree.findall(‘guest’):
... arch = guest.find(‘arch’).get(‘name’)
... domain_type = guest.find(‘arch/domain’).get(‘type’)
My stock Ubuntu 13.10 supports Qemu domains
Depending on the settings, only. However, since Qemu is a generic emulator, I can
you may be asked to enter virtualise almost anything including s390x or SPARC
the root password to use a (albeit at a performance penalty). x86_64 and i686 are
system connection. of course supported, too.
94 www.linuxvoice.com
PYTHON & libvirt TUTORIAL
It’s good to know that you can create a domain for host is restarted. Persistent domains last forever and
any conceivable architecture, but how do you actually must be defined before start. A transient domain will
do it? First of all, you’ll need some XML to describe the do for now, but as we are going to create something, a
domain. For simple cases, it may look like this: read-only connection is no longer sufficient.
<?xml version=”1.0”?> import libvirt
<domain type=’qemu’> xml = “””domain definition here”””
<name>Linux-0.2</name> conn = libvirt.open(‘qemu:///system’)
<uuid>ce1326f0-a9a0-11e3-a5e2-0800200c9a66</uuid> domain = conn.createXML(xml)
<memory>131072</memory> Yeah, that’s all. However, if you try to execute this
<currentMemory>131072</currentMemory> script, you may get this response:
<vcpu>1</vcpu> libvirt: QEMU Driver error : internal error: Network ‘default’ is not
<os> active.
<type>hvm</type> This is because the XML references the “default”
<boot dev=’hd’> network, which won’t be active unless there are
domains using it already running, or you have marked
</os> it as autostarted with virsh net-autostart default
<devices> command. Insert the following code just before
<disk type=’file’ device=’disk’> conn.createXML() call to start the network if it is not
<source file=’/path/to/linux-0.2.img’/> already active:
<target dev=’hda’> net = conn.networkLookupByName(‘default’)
</disk> if not net.isActive():
<interface type=’network’> net.create()
<source network=’default’/> First, we get an object representing the “default”
</interface> network. libvirt can look up objects by names, UUID
<graphics type=’vnc’ port=’5900’/> strings (ce1326f0-a9a0-11e3-a5e2-0800200c9a66)
</devices> or UUID binary values (UUID(‘ce1326f0-a9a0-11e3-
</domain> a5e2-0800200c9a66’).bytes). Corresponding method
names start with the object’s type (except for domains)
Speak the domain language followed by “LookupByName”, “LookupByUUIDString”
Here, we create a Qemu/KVM (hvm) virtual machine or “LookupByUUID”, respectively.
with one CPU and 128MB of RAM. It has a hard disk at Network objects provide other methods you may
IDE primary master (hda), from which it boots (I’ve find useful. For instance, you can mark a network as
used the tiny Linux 0.2 image from the Qemu Testing autostarted with net.setAutostart(True). Or, you can
page). It is connected to the “default” network get an XML definition for the network (or any other
(NAT-enabled 192.168.122.0/24 attached to virbr0 at libivrt object) with XMLDesc():
the host side), and you can use VNC at port 5900/tcp >> print net.XMLDesc()
to access its screen (try vinagre localhost:5900 or <network>
similar). Note that the <source file=”...”/> must contain <name>default</name>
an absolute path to the image, and the image format <uuid>9d3c0912-6683-4128-86df-72f26847d9d3</uuid>
must be supported by the hypervisor. libvirt is not a ...
tool to create disk images, however you can use </network>
pyparted, ubuntu-vm-builder or similar to automate If we were going to create a persistent domain, we’d
this process with Python. change conn.createXML() to:
Domains in libvirt are either transient or persistent. domain = conn.defineXML(xml)
The former exist only until the guest is stopped or the domain.create()
There and back again
libvirt is essentially a sophisticated translator from some VM configuration in XML, or you may have the <name>Linux-0.2</name>
<uuid>ce1326f0-a9a0-11e3-a5e2-0800200c9a66</uuid>
a high-level XML to low-level configurations specific configuration autogenerated by another front-end. <memory unit=’KiB’>131072</memory>
to hypervisors. Sometimes you may want to see libvirt can convert a native domain configuration to <currentMemory unit=’KiB’>131072</currentMemory>
what libvirt generates from your definitions. You the XML with: <vcpu placement=’static’>1</vcpu>
<os>
can do this with: >>> argv=”LC_ALL=C PATH=... QEMU_AUDIO_DRV=none /usr/bin/
<type arch=’x86_64’ machine=’pc’>hvm</type>
qemu-system-x86_64 -name Linux-0.2 ... -m 128 ... -smp
>>> print conn.domainXMLToNative(‘qemu-argv’, xml) </os>
1,sockets=1,cores=1,threads=1 -uuid ce1326f0-a9a0-11e3-a5e2-
LC_ALL=C PATH=... QEMU_AUDIO_DRV=none /usr/bin/ ...
0800200c9a66...”
qemu-system-x86_64 -name Linux-0.2 ... -m 128 ... -smp </domain>
>>> print conn.domXMLFromNative(‘qemu-argv’, argv)
1,sockets=1,cores=1,threads=1 -uuid ce1326f0-a9a0-11e3- a5e2- You can also use virsh domxml-to-native and virsh
0800200c9a66 ... -vnc 127.0.0.1:0 -vga cirrus... <domain type=’qemu’ xmlns:qemu=’http://libvirt.org/schemas/ domxml-from-native commands for the same
Other times, you may be unsure how to express domain/qemu/1.0’> purposes.
www.linuxvoice.com 95
TUTORIAL PYTHON & libvirt
(remember that persistent domain creation is a
two-phase process). To gracefully reboot or shutdown Your mileage may vary
the domain, use domain.reboot() and domain.
You may expect libvirt to abstract all hypervisor details
shutdown(), respectively. However, the guest can
from you. It does not. The API is generic enough, but
ignore these requests. domain.reset() and domain. there are nuances. First, you’ll need your guest images
destroy() do the same, albeit without guest OS in a hypervisor-supported format (use qemu-img(1) to
interaction. When the domain is no longer needed, you convert them). Second, hypervisors vary in their support
can remove (undefine) it like this: level. Qemu/KVM and Xen are arguably the best supported
options, but we had some issues (like version mismatch or
try:
inability to create a transient domain) with libvirt-managed
domain = conn.lookupByUUIDString(‘ce1326f0-a9a0-11e3- VirtualBox on our Arch Linux and Ubuntu boxes.
a5e2-0800200c9a66’) The bottom line: libvirt is great, but don’t think you can
domain.undefine() change the hypervisor transparently.
except libvirt.libvirtError:
print ‘Domain not found’
lookup*() throws libvirtError if no object was found; four entries in the cpu_stats array. dom.
many libvirt functions do the same. If the domain is getCPUStats(True) aggregates the statistics for all
running, undefine() will not remove it immediately. CPUs on the host:
Instead, it will make the domain transient. It is an error >>> print dom.getCPUStats(True)
to undefine a transient domain. [{‘cpu_time’: 10208067024L, ‘system_time’: 1760000000L,
When you are done interacting with the hypervisor, ‘user_time’: 5830000000L}]
don’t forget to close the connection with conn.close(). Disk usage statistics are provided by the
Connections are reference-counted, so they aren’t dom.blockStats() method:
really closed until the last client releases them. rd_req, rd_bytes, wr_req, wr_bytes, err = dom.blockStats(‘/path/
to/linux-0.2.img’)
Get’em all The returned tuple contains the number of read
A libvirt system may have many domains defined, and (write) requests issued, and the actual number of bytes
there are several ways to enumerate them. First, transferred. A block device is specified by the image
conn.listDomainsID() returns integer identifiers for the file path or the device bus name set by the devices/
domains currently running on a libvirt system (unlike disk/target[@dev] element in the domain XML.
UUID, these IDs aren’t persisted between restarts): To get the network statistics, you’ll need the name
for id in conn.listDomainsID(): of the host interface that the domain is connected to
domain = conn.lookupByID(id) (usually vnetX). To find it, retrieve the domain XML
... description (libvirt modifies it at the runtime). Then,
If you need all domains regardless of state, use the look for devices/interface/target[@dev] element(s):
conn.listAllDomains() method. The following code tree = ElementTree.fromstring(dom.XMLDesc())
mimics the behaviour of the virsh list --all command: iface = tree.find(‘devices/interface/target’).get(‘dev’)
print ‘ Id Name State’ rx_bytes, rx_packets, rx_err, rx_drop, tx_bytes, tx_packets, tx_err,
print ‘-’ * 52 tx_drop = dom.interfaceStats(iface)
for dom in conn.listAllDomains(): The dom.interfaceStats() method returns the number
print “%3s %-31s%s” %\ of bytes (packets) received (transmitted), and the
(dom.ID() if dom.ID() > 0 else ‘-’, number of reception/transmission errors.
dom.name(),
state_to_string(dom.state())) A thousand words’ worth
For domains that aren’t running, dom.ID() returns Imagine you are making a step-by-step guide for an
-1. dom.state() yields a two-element list: state[0] is a OS installation process. You’ll probably do it in the
current state (one of libvirt.VIR_DOMAIN_* virtual machine, taking the screenshots periodically. At
constants), and state[1] is the reason why the VM has the end of the day you will have a pack of screenshots
moved to this state. Reason codes are defined that you’ll need to crop to remove VM window
per-state (see virDomain*Reason enum in the C API borders. Also, it’s pretty boring to have to sit there
reference for the symbolic constant names). The pressing PrtSc. Luckily, there is a better way.
custom state_to_string() function (not shown here) libvirt provides a means to take a snap of what is
returns a string representation of the code. currently on the domain’s screen. The format of the
Domain objects provide a set of *stats() methods image is hypervisor-specific (for Qemu, it’s PPM),
to obtain various statistics: however, you can use the Python Imaging Library (PIL)
cpu_stats = dom.getCPUStats(False) to convert it to anything you want. To transfer image
for (i, cpu) in enumerate(cpu_stats): data from the VM, you’ll need an object called stream.
print ‘CPU #%d Time: %.2lf sec’ % (i, cpu[‘cpu_time’] / This provides a generic way to exchange data with
1000000000.) libvirt, and is implemented by the virStream class.
This way, you get a CPU usage for the domain (in Streams are created with the conn.newStream()
nanoseconds). My host has four CPUs, so there are factory function, and they provide recv() and send()
96 www.linuxvoice.com
PYTHON & libvirt TUTORIAL
methods to receive and send data. To get a stream
containing the screenshot, use:
stream = conn.newStream()
dom = conn.lookupByUUID(UUID(‘ce1326f0-a9a0-11e3-a5e2-
0800200c9a66’).bytes)
if dom.isActive():
dom.screenshot(stream, 0)
Here, we lookup the domain by a binary UUID value,
not a string (the UUID class comes from the uuid
module). We check that the domain is active
(otherwise it has no screen) and ignore other possible
errors. Now we need to pump the data to the Python
side. virStream provides a shortcut method for this
purpose:
buffer = StringIO()
You can take a screenshot
stream.recvAll(writer, buffer) specifies the event “family” to subscribe to. Here, we
of the VM as early as you
stream.finish() are interested in lifecycle events (started, stopped, etc), want, even before a guest
Here, we create a StringIO file-like object to store but there are many others (removable device changed, kernel is booted.
image data. stream.recvAll() is a convenience power management occurs, watchdog fired, and so
wrapper that reads all data available in the stream. on). The last argument is an arbitrary value to be
writer() function is defined as: passed to the event_callback() function (remember
def writer(stream, data, buffer): stream.recvAll() and writer() we saw earlier?).
buffer.write(data) Event handler is defined as follows:
Its third argument is the same as the second def event_callback(conn, domain, event, detail, opaque):
argument in recvAll(). It can be an arbitrary value, and print ‘Event #%d (detail #%d) occurred in %s’ % (event, detail
here we use it to pass the StringIO() buffer object. domain.name())
All that remains is to save the screenshot in a event and detail are integer codes describing what
convenient format, like PNG: happened. For lifecycle events, they are defined in the
from PIL import Image virDomainEventType and virDomainEvent*DetailType
buffer.seek(0) enums; the constants (libvirt.VIR_DOMAIN_EVENT_
image = Image.open(buffer) STARTED etc) are named the same as enum fields.
image.save(‘screenshot.png’) while True:
PIL is clever enough to autodetect the source image libvirt.virEventRunDefaultImpl()
type. However, it expects to see the image data from This is the main loop. In a real application, you will
byte one, that’s why we use buffer.seek(0). probably run it in a separate thread. The call blocks
You can easily wrap this screenshotting code into a until a subscribed event (or a timeout) occurs, so even
function and call it periodically, or when something exiting with Ctrl+C takes some time.
interesting happens to the VM. When the subscription is no longer needed, you can
terminate it with:
You’ve got a message conn.domainEventDeregisterAny(cb_id)
When something happens to a domain, for example it Events notification opens many interesting
is defined, created, destroyed, rebooted or crashed, possibilities. For instance, you can start domains in
libvirt generates an event that you can subscribe to the particular order (one after another), or use the
and act appropriately. To be able to receive these Tornado framework to create a lightweight web-based
events, you’ll need some event loop in your code. virt-manager alternative.
libvirt provides a default one, built on top of the
blocking poll(2) system call. However, you can easily And there’s more…
integrate with Tornado IOLoop (LV1) or glib MainLoop This concludes our quick tour of the features of libvirt.
(LV2), if needed. We’ve barely scratched the surface, and there is much
Default event loop is registered at the very more than we’ve seen so far: storage pools,
beginning, even before the connection to libvirt encryption, network filters, migrations, nodes, Open
daemon is opened: vSwitch integration and the rest. However, the APIs
libvirt.virEventRegisterDefaultImpl() you’ve learned today form a solid foundation to build
conn = libvirt.open(‘qemu:///system’) more advanced libvirt skills for your next project. Let
Next, you subscribe to the events you are interested the computer do the repetitive work for you, and have
in. Let’s say we want to receive events of any type: fun with Python in the meantime!
cb_id = conn.domainEventRegisterAny(None, libvirt.VIR_
DOMAIN_EVENT_ID_LIFECYCLE, event_callback, None) Dr Valentine Sinitsyn has committer rights in KDE but spends
The first argument is the domain we want to his time mastering virtualisation and doing clever things
with Python.
monitor; None means any. The second argument
www.linuxvoice.com 97
CODING RUBY
EVERYTHING IS AN
CODING TUTORIAL
OBJECT IN RUBY
Everything in Ruby is an object. Even procs, includes, lambdas,
JOHN LANE
classes, singleton classes, superclasses and everything else…
R
uby is an interpreted object-oriented => 24750480
programming language that has gained > 0.object_id
popularity in recent years, perhaps due to => 1
the popularity of the Ruby on Rails web application Inside Ruby the object ID is a pointer to the location
framework. Its basic syntax is easy to learn and in memory where the object is stored. Following
programmers adopting the language quickly become a pointer has more overhead than accessing data
comfortable writing Ruby code. directly so, for performance reasons, there are a few
As a new Ruby programmer (Rubyist), however, kinds of object that encode their data within their
you’re immersed in a world of classes, objects, object ID. They’re explained in the Small Objects
methods and class methods, instance variables and boxout on page 100. For most objects, however, the
class instance variables, class variables, singleton and ID refers to a location in memory that contains some
proxy classes, procs, lambdas and blocks. You can be internal flags, a table of variables and a pointer to the
forgiven for appearing dazed and confused. class that the object is an instance of.
Some of the basic concepts are easy to understand: Ruby variables contain object IDs, and this means
terms like classes and instances are easily that they behave like pointer variables in other
understood by anyone with some object oriented languages, as the following example illustrates:
programming experience. But all this terminology a = “abc”
boils down to one basic model, and understanding b=a
that model can bring clarity and understanding of a.upcase!
everything else, making you a better Rubyist. puts b # => “ABC”
We’re going to focus on one key fact about The object’s state is represented by its table of
Ruby – that everything is an object – and learn variables. You can peek into any object and see these
what this means for us as Ruby programmers. By instance variables:
understanding what an object is we can unleash puts myobject.instance_variables
Ruby’s power and understand some of those The object’s class pointer points to the class that
concepts that might at first appear confusing. the object is an instance of. You can ask an object
If you have done your homework you will know what its class is:
about two kinds of object: an instance and a class; the puts “abc”.class # => String
latter being like a blueprint used to create the former. An object receives a message when a method is
called on it. In this sense, we talk about the object as
The four freedoms the receiver and express the message as a method
All objects have four characteristics in common: call like this:
identity, state, being an instance of some class and myobject.a_method(parameters)
the ability to receive messages. We’ll explain each of But our object definition didn’t mention methods.
these in turn. What happens when an object receives a message is
Each object has a unique identity, it’s object ID, that it follows its class pointer to find the method.
which you can reveal it with its object_id method. The method is defined on the class so that all its
> “hello”.object_id instances can use it. Despite this, it is usual to say that
“myobject has a method called my_method “instead
of “MyClass has a method called my_method” even
my_object though that’s the reality.
To clarify that methods defined on a class are called
MyClass on an instance, we call them instance methods and
an instance of this can be expressed in Ruby:
MyClass “my string”.methods == String.instance_methods
an instance of
We can summarise our understanding of an object
Class as being an instance of a class with its own instance
Instances and classes are objects and variables and the use of the instance methods defined
all objects are instances of a class. by its class.
98 www.linuxvoice.com
RUBY CODING
Going back to our ‘everything is an object
philosophy’, it follows that a class is an object too. Animal Class
This means that everything that we have said so an instance of an instance of
far also applies to classes: a class is an instance of Class Class
another class. It can, therefore, have its own instance
variables and can also use instance methods defined
instance variables instance variables
by its class. instance methods instance methods
A class is an instance
Ruby allows a class to be derived from another: it
supports single inheritance. Such a class is a
subclass of the one it inherits, which is its superclass.
my_cat
Its upward chain of superclasses is called its an instance of Cat
ancestors and you can peek into a class to see them: Class an instance of
puts String.ancestors
The chain of ancestors is used to locate a method instance variables Class
when an object receives a message. It looks first in its an instance of
class and, if it finds nothing in there, iterates through Class
its ancestors until it is found. Thus, a class can define
instance variables
new methods or redefine methods already defined by
one of its ancestors. If no method is found then the instance methods
object is sent a new message called method_missing.
When a method executes, it does so in the context A class can be a subclass as well as an instance. They can have instance variables and
of the receiver, which we call the current object, and instance methods. An object’s accessible instance variables and instance methods
uses its instance variables (as you would expect). The are shown in the same colour as its name. If a method isn’t defined by its class, move
current object has a special name in Ruby: self. upwards through its ancestors to find it.
Summarising our understanding of classes, we can
say that a class is an object that can be instantiated b = “def”
and can have instance methods and a superclass. But b.rot13 # => NoMethodError: undefined method `rot13’ for
there’s another very important kind of class that you “def”:String
need to understand – the Singleton class. So, where is it? Well, it’s in a singleton class. What
Ruby does is create a new anonymous class that
In a class of its own becomes the object’s class and its actual class
We explained that a class can define new methods or becomes the superclass of the anonymous class. The
redefine those already defined by its ancestors. The singleton class is invisible, however:
singleton class enables an instance to do the same, a.class # => String
allowing it to have methods that other instances of its Singleton classes are everywhere in Ruby; just very
class do not have. You can do this: well hidden. It’s common practice to create class
a = “abc” methods using a construct like this:
def a.rot13 class MyClass
tr ‘A-Za-z’,’N-ZA-Mn-za-m’ def self.class_method
end “hello”
a.rot13 # => nop end
We just defined a method called rot13 on an object, end
a, which is an instance of the String class. We know MyClass.class_method # => hello
that the methods accessible to an object are in its This is exactly the same as our rot13 example PRO TIP
class, which is String. But if we defined the method in – a method called class_method is created in the You can try the code
the class then it would be accessible to its instances, singleton class for the object, MyClass, which lies snippets yourself in irb or
try http://rubyfiddle.com.
which isn’t the case: between that object and its visible superclass, Class.
The singleton class is sometimes referred to as a
metaclass, virtual class or eigenclass; Eigen being
Everything is an object
a German word meaning one’s self. That fact helps
Some experienced Rubyists may prefer to say that almost explain the way we just used the self keyword.
everything is an object because you can’t define something We already mentioned that self refers to the current
entirely in terms of itself. Ruby’s syntax is not an object object. We now extend our definition to say that the
and variables aren’t objects. So while it may technically current object becomes the class being defined when
make more sense to say that every value is an object, for
inside a class definition. In the example above, self
the purpose of understanding objects, this fact can be
overlooked. ruby-lang.org says that everything is an object refers to the class, MyClass, that is being defined.
so that’s good enough for us. Another common idiom in Ruby is to open a
singleton class and code directly inside it. We could
www.linuxvoice.com 99
CODING RUBY
For a class, the superclass object, the one that the method was called on. It uses
Object Object singleton class << self to open the current object’s singleton
of its singleton class is
the singleton class of its class, and the second use of self is inside that and,
superclass! therefore, the method returns the singleton class.
MyClass My Class Ruby 1.9 introduced a new method called singleton_
instance variables singleton class class into the Object class that does this.
class instance
instance methods variables The magic of modules
There is another kind of object that is very similar to a
class methods class; so similar in fact that the only real difference is
my_object class method that it cannot be instantiated: the Module. Everything
singleton class we’ve said about instance variables and instance
my_object methods apply equally to modules, but they differ
instance variables
instance variables from classes in the way they are used.
instance methods You don’t inherit modules – you include them, and
you can include many modules.This is how you can
have written the above example like this: achieve the effect of multiple inheritance in Ruby.
class MyClass When a module is used within a class, it is called a
class << self mixin, because it is mixed in to the class.
def class_method class MyClass
“hello” include UsefulModule
end include AnotherUsefulModule
end ...
end end
which you may prefer when defining lots of class Including a module is another occasion when Ruby
methods together. And an example that really shows creates an anonymous class that, in this case, is
off self’s changing persona is this eigenclass method: known as an include or proxy class. It is inserted into
class Object the ancestor chain of the including class, becoming
def eigenclass its superclass. The proxy class points to the module’s
class << self instance methods. Proxy classes enter the ancestor
self chain in the order that modules are included into the
end class, so this ordering is significant in the event that
end modules contain methods with the same name.
end The fact that we said instance methods is
It adds a new method to the Object class, an important – when you include a module you don’t
ancestor of all classes and a good place to define get class methods, because although, like any other
methods that should be available everywhere. Inside class, a module has a singleton class, it does not get
the eigenclass instance method, self is the current included. That is to say, if you do
module MyModule
def self.class_method
Small objects
end
Some kinds of objects are not represented a 64-bit machine this means a 63-bit signed end
by an object structure, because the data they integer). The reserved bit is used as a flag and include that module in a class, the method will not
contain takes up less space than a reference that tells Ruby what the object is. The value
be available. Any object can, however, include a
to an object structure would. Instead, they is stored bit-shifted left and with the least-
encode their data within their object ID, and significant bit set to 1. In this way, all object module’s instance methods into its singleton class.
they do so for performance reasons. IDs that are odd numbers represent integer When a class does this they become class methods.
Because memory addresses are always objects. In Ruby, these numbers are the module MyModule
aligned with the word length of the CPU FixNum class. Ruby 2.0 introduced a similar def class_method
(32-bit systems have a 4-byte word length, encoding on 64-bit architectures for some
“hello”
and it’s 8 bytes on 64-bit systems), all the small Float values that it calls Flonums.
least significant bits of a pointer are always Another small object is the symbol. end
zero. Ruby uses this space to identify small These are used every day in Ruby, as keys end
objects, which is demonstrated nicely by to hashes among other things. They are class MyClass
small integers: immutable strings, meaning that they cannot class << self
> 20.object_id be modified once created.
include MyModule
Ruby creates symbol objects whenever
=> 41 end
new symbols are referenced. Variables and
> 20.object_id >> 1 other references to the same symbol all end
=> 20 refer to the same symbol object. Comparing puts MyClass.class_method # => hello
By small integer, we mean any signed symbols is more efficient than strings, Because this is a common idiom, Ruby provides the
integer that can be held in the space because it’s only necessary to compare their
extend method to do just that. This is more succinct.
reserved for an object ID, less one bit (so on object IDs.
class MyClass
100 www.linuxvoice.com
RUBY CODING
extend MyModule
Object Object singleton
end
If you want both class and instance methods in the
same module then you have to resort to some trickery MySuperClass MySuperClass
singleton class
that uses callbacks and a sub-module. The idea is
that you create a sub-module and put the to-be class Module Proxy MyModule
methods there. You then rely on an included callback Module Proxy
include MyModule instance_method
(a method in your code that is invoked when the
extend MyModule
module is included in a class) to extend the class with instance_method ClassMethods (includeClassMethods)
the sub-module: class_methods
module MyModule
class_method
def self.included(including_class)
including_class.extend ClassMethods my_object MyClass MyClass
end singleton class
methods: include MyModule
module ClassMethods instance_method extend MyModule
def class_method
methods:
“class method” class_method
end Proxy classes point to
end module methods.
def instance_method simple example:
“instance method” def my_method
end yield if block_given?
end end
class MyClass; include MyModule; end my_method { puts “I’m a block!” }
puts MyClass.class_method # => class method We use block_given? to ensure we have a block
my_object = MyClass.new before we yield to it. If we didn’t do this, Ruby would
puts my_object.instance_method # => instance_method raise a LocalJumpError if the method was invoked
Another use for modules is name-spacing, which without one. The block must be given after, and
allows classes or modules with the same names to be outside, the method’s argument list. It can optionally
used without conflict. The :: scope resolution operator take arguments.
allows constant definitions (classes and modules A block is not an object, but it can be converted
have object IDs that are constants) to be nested. into one called a Proc. This happens if the method
module Custom specifies a last parameter that is preceded with an
class String ampersand (&). This assigns the block to a variable,
end which requires that it is an object. Proc objects may
end be assigned to variables but blocks can’t, hence the
puts Custom::String == String# => false conversion. Because they aren’t converted to objects,
You may also see modules used to implement the blocks enjoy a slight performance advantage. They
singleton pattern, which is often confused with the respond to yield, whereas a Proc must be called:
singleton classes we’ve previously explained, but just def my_method(&proc)
means a class that can only be instantiated once. proc.call
Modules can be used to model these, and a typical end
example is a logging object. my_method { puts “I’m a block!” }
module Logger You can explicitly create Proc objects and pass
def self.log(msg) them as regular parameters.
@@log ||= File.open(“log.txt”, “a”) def my_method(proc)
@@log.puts(msg) proc.call
end end
end proc = Proc.new { puts “I’m a proc!” }
You can then include Logger wherever logging is my_method(proc)
needed and get a log method at your disposal. A neat feature of a block or Proc object is that
it’s a closure – a fancy term which means that it
An object you can call remembers the environment that existed when it was
The last group of objects that we need to cover are created, even if that environment no longer exists.
callable objects. You’ve seen this construct before: That means that the state of all variables in scope
(0..10).each { |n| puts n } when it was created are remembered, even if they
The bit between the braces is a block (you can also have since ceased to exist.
use do and end) – a chunk of Ruby code that can be A variation on a Proc is the lambda or anonymous
passed into a method. A method can take one block method, created like this:
that can use the mystical yield to execute it. Here is a l = lambda { |n| puts “Hello #{n}, I’m a lambda” }
www.linuxvoice.com 101
CODING RUBY
Or, since Ruby 1.9, with an alternative syntax: The final object we’re going to mention is one we’ve
l = ->(n){puts “Hello #{n}, I’m a lambda” } been using all along. Methods are objects too. You
The one you use is a matter of personal taste. can get any method as an object and use it in place of
Although still Proc objects, there are a couple of a proc or lambda.
behavioural differences to be aware of. def foo() “foo” end
First, you will notice that a Proc is not sensitive to def bar(m) m.call end
the number of arguments given – if insufficient are m = method(:foo) # => #<Method: Object#foo>
given, the missing ones become nil. Lambdas, on the puts bar(m) # => foo
other hand will raise an error in this scenario (as any And that’s the object of Ruby. Understanding what
method would). Ruby’s objects are and how they work will help to
The other difference is how they behave when clarify what makes the language tick and, hopefully,
called. A Proc behaves like it has been inserted into will lead to some wonderful coding experiences. Here
the calling method and, so, a return in a Proc will be no dragons!
cause the surrounding method to return. Because the
lambda is a method, a return inside one will just return
control to the surrounding method.To summarise John Lane is a technology consultant with a penchant for
their differences, remember that “Proc” behaves like a Linux. He helps new business start-ups make the most of
open source.
block and “lambda” behaves like a method.
Challenges
Test your skills by writing Ruby code to solve the following puzzle
This is a small Ruby program to test knowledge of my_object_a1.var = “this is an instance variable in
the Ruby Object Model. It creates one superclass,
my_object_a1 = MyClassA.new my_object_a1”
two subclasses and two instances of each of
those. The superclass includes a module that my_object_a2 = MyClassA.new my_object_a2.var = “this is an instance variable in
defines instance variables and their accessors. In my_object_b1 = MyClassB.new my_object_a2”
total there are eight objects and eight variables. my_object_b2 = MyClassB.new my_object_b1.var = “this is an instance variable in
All the variables have the same name, @var, and my_object_b1”
accessors called var and var=.
Show default values my_object_b2.var = “this is an instance variable in
The variables are
Module instance variable. dump(MyModule,MySuperClass,MyClassA,MyClas my_object_b2”
Class instance variables. sB,my_object_a1,my_object_a2,my_object_b1,my_
Instance variables. object_b2) Show assigned values
The module assigns default values to each dump(MyModule,MySuperClass,MyClassA,MyClas
variable. There is a different default value for each
Test default values sB,my_object_a1,my_object_a2,my_object_b1,my_
of the three types. This program refers to those
defaults as DEF_MIV, DEF_CIV and DEF_IV and different(MyModule::DEF_MIV,MyModule::DEF_ object_b2)
tests their assignment. CIV,MyModule::DEF_IV)
The program uses the accessors to assign same(MyModule::DEF_MIV,MyModule.var) Test assigned values
values to the variables and applies a series of same(MyModule::DEF_CIV,MySuperClass. different(my_object_a1.var,my_object_a2.
tests to check which variables are the same
var,MyClassA.var,MyClassB.var) var,my_object_b1.var,my_object_b2.
or different. The test methods are coded in a
separate file, tests.rb. same(MyModule::DEF_IV,my_object_a1. var,MyModule::var,MySuperClass.var,MyClassA.
The module is coded in my_module.rb. It is var,my_object_a2.var,my_object_b1.var,my_ var,MyClassB.var)
your challenge to write this module. Extra brownie object_b2.var) same(my_object_a1.class.var,my_object_a2.class.
points can be scored if the program still works var)
after changing the superclass to use extend
Assign values same(my_object_b1.class.var,my_object_b2.class.
instead of include (line 35) without modifying
anything else, including your module. MyModule::var = “this is a module instance var)
Ruby 1.9 or later should be fine. This was variable” different(my_object_a1.class.var,my_object_b1.
written with ruby-2.0.0-p353. MySuperClass.var = “this is a class instance class.var)
require_relative ‘my_module’ variable in MySuperClass” different(my_object_a2.class.var,my_object_b2.
require_relative ‘tests’ MyClassA.var = “this is a class instance variable in class.var)
MyClassA” same(my_object_a1.class.superclass.var,my_
class MySuperClass; include MyModule; end MyClassB.var = “this is a class instance variable in object_a2.class.superclass.var,my_object_b1.
class MyClassA < MySuperClass; end MyClassB” class.superclass.var,my_object_b1.class.
class MyClassB < MySuperClass; end superclass.var)
102 www.linuxvoice.com
RUBY CODING
LINUX VOICE ISSUE 1
COMPETITION RESULTS
The fastest and smallest solutions to our
crossword-solving puzzle from Linux Voice issue 1
W
hen we set a competition in this program gets around this by using scripts, so why not Python? It’s within the
Linux Voice issue 1, we had no the -o flag. This means it just outputs the spirit of Bash programming to include other
idea what would happen. While section of the text that matches the regular tools in this way.
it seemed like a good idea to us, there was expression, and not anything else. This entry ran in a little under 0.1 seconds
always the chance we’d get no entries, and on our machine. This was more than 2,000
have to sheepishly admit that here instead The fastest times faster than the shortest entry, and a
of announcing results. These fears were There was one script that ran faster than the couple of times faster than its nearest rival.
quickly assuaged when the first entry rolled rest. Much faster. It was: The panel of expert judges were delighted
in the same day the issue first arrived with #!/bin/bash to see two very different approaches to the
subscribers (Thanks Jose!). for line in `cat | python gen_regexs.py`; do problem solve it in two very different ways,
To refresh your memory, the competition egrep “^$line$” /usr/share/dict/words and get very different results because they
was to write a Bash script that used grep done were optimised for different things.
to solve a crossword. There were two exit 0 Congratulations to Richey Delaney for
categories: the smallest script, and the This needs the file gen_regexs.py, which winning this aspect of the competition.
fastest execution. The best entry in each is here: In future competitions, feel free to e-mail
category wins an exclusive Linux Voice import sys us if you’re unsure about a point on the rules,
winner’s T-shirt. and we’ll give a ruling.
def get_regex(word): We’ll end with a massive thank you to
The smallest regexs = [] everyone who entered, with such diverse
The prize for the shortest solution goes to for i in range(0, len(word)-2): approaches to the problem. We hope that
Steve Engledow, creator of this ingenious for j in range(i+3, len(word)+1): everyone had some fun and learned a bit
one-liner. regexs.append(word[i:j]) along the way.
s=`cat -`;for i in `cat /usr/share/dict/words|grep return regexs
^...`;do echo $s|grep -o “$i”;done
To make it a bit more readable, here it is def make_regex(word):
with some white space: return “(%s)” % (“|”.join(get_regex(word)))
s=`cat -`
for i in `cat /usr/share/dict/words|grep ^...` if __name__ == “__main__”:
do for word in sys.stdin:
echo $s | grep -o “$i” print make_regex(word.strip())
done This is obviously not just a Bash script;
The first line concatenates all the input lines it’s a Bash script and a Python script. This
into a single string. Then the for loop goes is certainly stretching the rules quite a bit,
through every line in the words file that’s so we had to decide whether or not to allow
longer than three letters. it. The rules stated that the program had to
The grep match is a little different to how be a Bash script that matched using a form
most people solved the problem. Rather of grep. There’s no denying that this is what
than create a regex based on the text in the this does. The Python code only generates
wordsearch and try to find a match in the the regular expression against which the
words file, it uses the words file and tries to Bash script looks for matches.
This could be yours! The exclusive Linux Voice
find a match in the wordsearch. Normally After much deliberation, we decided leet T-shirt is only available to the winners of
this wouldn’t work, since grep would output that while this stretched the rules, it didn’t the Linux Voice challenges. Take a look at the
the line in the wordsearch, which would actually break them. After all, sed, perl and opposite page for details of how to enter this
include text either side of the word. However, awk scripts are regularly included in shell month’s competition.
www.linuxvoice.com 103
CODING CONCEPTS
GENETIC ALGORITHMS:
CODING TUTORIAL
CREATE LIFE WITH PYTHON
Everything’s easy in Python. Even things that aren’t easy to solve
BEN EVERARD
can be evolved with a little generic magic.
C
omputers follow a series of instructions step To model this computationally, the key thing we
by step until they get to the end. This series of need is a fitness selector. This is the test that we’ll
instructions is called a program. However, apply to the data to see if it should pass on its
what if something can’t be calculated with a series of characteristics to the next generation, or if it should be
step-by-step instructions? Or what if the series of pruned from the evolutionary tree leaving stronger
step-by-step instructions would take so long to data to go forward.
complete that running them is impractical? Essentially, it’s this function that defines your
In these cases, we need a method that side-steps genetic algorithm and what data it will search for – it
the main problem, but still attempts to find an answer. turns programming around, so that you write a
One way to do this is to use genetic algorithms. This program specifying what the solution should look like,
mimics the natural process of evolution to attempt to then leave the computer to work out what it is.
solve a problem through a combination of
randomisation, selection and combination. Genetic square roots
The basic method goes like this: Let’s take a look at an example. There isn’t actually an
Create a random set of data in the right format to easy way to calculate square roots, however, it is very
solve the problem. easy to go the other way around and calculate the
Apply some test to see which of the data solve the square of a number. So, this is the sort of problem that
problem best. genetic algorithms are good at. We’ll program it in
Combine the best pieces of data, throw in a little Python using the pyevolve module. This may be in
randomness and go back to step two. your distro’s repositories in the python-pyevolve
In the real world, this is how we became us. Initially, package, or you can get it with
there were some primeval organisms with some DNA pip install stallion
and not much else. The evaluation function for our square root finder is:
“Genetic algorithms mimic the This was step 1. The
weakest of these
def eval_func(chromosome):
score = 0.0
natural process of evolution to organisms died off for value in chromosome:
solve a problem.” leaving only the
strongest. This was
score += 100000000-abs(((square_root_of-(value*value))))
return score
step 2. These This function will be passed a list of data that
remaining organisms reproduced. This is step 3. The represent the organism that you’re evaluating. In the
final two steps have been repeating ever since life on case of our square root calculator, this will have just a
earth started, and we are the result, as are all the other single value, but in other cases, it could hold many
living things. values representing different aspects of the organism.
It returns a value that the genetic algorithm will
attempt to maximise. In this case, it will try to
maximise 100000000-abs(((square_root_of-
(value*value)))). abs() returns the absolute value of a
number – this means that it just removes the negative
sign on negative numbers, so abs(10) is 10, and
abs(-5) is 5. The abs() call in this function, then, will
return a larger number the further the value is from
the actual square root. However, our algorithm will try
to maximise the result, so we want this number to get
smaller the further it is from the square root. To do
this, we take the result away from 100000000.
NASA use genetic We said that this function effectively defines the
algorithms to find the genetic algorithm, and this is true. However, we do
best antenna designs for need a bit more code to define the environment that
spacecraft. the evolution will take place in. Since genetic
104 www.linuxvoice.com
CONCEPTS CODING
algorithms rely on a certain amount of randomness to
find the right values, there’s no guarantee that they will
ever find the right value. You can increase the chances
of them working correctly by tweaking the
environment for the particular problem you’re trying to
solve. The full code we’ve used is as follows:
from pyevolve import *
square_root_of = 1000
def eval_func(chromosome):
score = 0.0
for value in chromosome:
score += 100000000-abs(((square_root_of-(value*value))))
return score
genome = G1DList.G1DList(1)
genome.evaluator.set(eval_func)
genome.setParams(rangemin=0, rangemax=int(square_root_
of/2))
genome.crossover.set(Crossovers.G1DListCrossoverUniform) If you want to experiment further with genetic algorithms, the pyevolve module is well
documented at http://pyevolve.sourceforge.net.
ga = GSimpleGA.GSimpleGA(genome)
ga.setPopulationSize(square_root_of) of values in the range is larger. Therefore, we set the
ga.setGenerations(50) population size to be the number of which we’re trying
ga.evolve(freq_stats=10) to find the square root. There wasn’t any clever
calculation that drew us to this setting. We just tried a
print ga.bestIndividual() few different options, and this one seemed to work
This code will attempt to find the square root of 1000, out the best.
which is a little unfair since the software only works You can also change the number of generations.
with integers. If it works correctly, it should find the This is, pretty obviously, the number of times you
closest whole number to the square root of 1000. repeat the selection and recombination. Again, we
The variable genome holds an instance of G1DList. came across the setting for this after a bit of trial and
The parameter we gave when creating this is the error. When you run the code, you’ll see that it outputs
number of items in the list. Once this variable is the fitnesses every 10 generations, so you can easily
created, you can set certain attributes about it. The see how quickly it’s getting to the solution (or getting
only thing that has to be there is the call to evaluator. stuck at the wrong solution).
set(). This tells the genome what function to use to
test the fitness. Now go and clone some dinosaurs!
The other two things we’ve set aren’t essential for it That’s all there is to it! This code is quite general-
to work, but make it much more efficient. We’ve purpose, and you should be able to adapt it to your
limited the range to between 0 and half of the number own problems. There is a certain amount of science/
we’re trying to find the square root of. The smaller we art/luck/witchcraft in finding the right values for the
can keep the range, the less work the genetic environment to produce a good result, and even with a
algorithm will have to go in order to find the square good environment, there’s no guarantee of getting the
root. Since we’re dealing with integers, and this rounds right answer. In fact, if you run this a few times, you’ll
up, it doesn’t stop us getting the right answer. probably get the wrong answer occasionally.
The crossover is the way in which strong pieces of Genetic algorithms aren’t great at every problem,
data are combined. There are quite a few options in but they can produce surprisingly good results to very
pyevolve, but not all of them work with lists containing complex problems as long as a good fitness function
just one element. can be created. Essentially, it’s a method of searching
The final block of code creates a genetic algorithm through a data set that’s too large to exhaustively
that takes this genome and evolves it. Again, there are search, and where a simpler search (like binary
some settings we can tweak to make the environment search) won’t work. Incidentally, binary searches do
conducive for getting the right answer. The key value work well for finding square roots, and we’ve only
here is the population size. This is the number of used genetic algorithms here as an example.
organisms we create each cycle by combining the
most successful from the previous cycle (and adding
some mutations). We found that larger square roots Ben Everard is the best-selling co-author of the best-selling
Learning Python With Raspberry Pi.
required larger population sizes because the number
www.linuxvoice.com 105
CODING GOOGLE SCRIPT
GOOGLE SCRIPT YOUR
CODING TUTORIAL
GROCERY BUDGET
Forget boring accounting software. Code your own
GRAHAM MORRISON
cloud-enabled budgeting script instead.
W
e’re the first to admit we feel using. The first is that the scripts themselves are easy
uncomfortable with the amount of data to write. The language is very similar to JavaScript,
that Google is gathering on every aspect of and while we accept that JavaScript is just as difficult
our lives. Many of us on the team are making a as any other language if you want to become a
concerted effort to move away from some of their master, for casual use it can be straightforward, quick
services – especially when it comes to location and easy. It’s widespread enough that many people
tracking, context searches and personal information will have come across it while hacking their own
(facial recognition, social interaction and profile websites, and Google has also done a good job at
analysis). But we’re also not the types to throw babies documenting the various APIs that allow its scripting
out with their bath water. Google has done, and still engine to access and process your data.
does, many good things for Free Software, and many The second redemptive excuse we’re offering is that
of its services are genuinely useful. you can schedule scripts to run automatically at any
And one of the most useful is its scripting engine, time, and unlike your network attached storage box,
known colloquially as Google Apps Script, and there your Raspberry Pi or low-end-Linux machine, Google’s
are two reasons why we think it’s worth the effort of servers rarely suffer outages and come for free.
1 PROJECT ORIENTATION
To help illustrate what Google’s Apps Script is capable
of, and how you might best be able to use it, we’re
going to create a budgeting system for managing
grocery expenditure. The idea is simple; set yourself a
budget for each month, and whenever you go to the
shops and buy something from your budget, you log
the amount. The remaining budget is calculated and
is sent via a weekly report telling you how much
you’ve spent and how much you’ve got left to spend.
Thanks to Google, lots of the complexity is
handled for us. To log spending we’ll use a Google
spreadsheet. These work extremely well from most
smartphones, and from any Android device in
particular, so it’s no hassle adding totals as you go
along. As it’s a Google spreadsheet, you can also
share it with other people, who will then be able to add
and manage spending themselves. This is a great
solution for a typical household.
We’ll construct the spreadsheet in such a way
that the data we place into it is easily accessible
(through Google’s APII) to the script we’ll write to tie
everything together. We’ll then write the script to take
the important parts of this data, such as the total,
the budget, when the cash was spent and how much
you’d like to spend, and then write some simple logic
around the calculation before outputting a verdict
on your spending. The whole script can then be
scheduled to run and email one or more people with
the results at a specific time.
We feel bad writing this, but you’ll need a Google You can keep on top of your finances from your phone,
account first. From there, you’ll need to click on your your tablet or your laptop with equal ease.
106 www.linuxvoice.com
GOOGLE SCRIPT CODING
Google Drive button or go to http://drive.google.com. so this shouldn’t be too much of an issue, but we
This is Google’s shared storage service that is now the promise to revisit the subject if enough people would
central repository for Google Docs too. We imagine like to see a solution using an open source service,
most readers will have a Google account already, such as OwnCloud, rather than a Google service.
2 CREATING THE SPREADSHEET
From the Google Drive page, click on the large Create Use the ‘show help’ field
button at the top-left and select ‘Spreadsheet’. A few to give your friends a little
moments later, a blank untitled spreadsheet will clue about what you want
appear in your browser window. We’ve called ours entered.
simply lv_groceries by clicking on the unnamed value
at the top. Our solution has two sheets – one for
logging day-to-day expenditure and the other for
making the various calculations and for holding our
budget values. The first sheet is very easy to create,
and the best place to start is by giving the first three
columns a title each – ‘Date’, ‘Amount’ and ‘Where’.
You might also want to highlight these cells by
changing the justification, using a bold font or perhaps showing the cell range you’ve selected so you can
a different background colour. This is the page you’re make sure the selection is correct (the first column is
going to use to enter your expenditure, sometimes ‘A’, and beneath this you need to select your criteria for
from your laptop and sometimes from your phone or validation). Click on the first pop-up menu button and
tablet, so a clear layout will help you to be accurate. select Date from the short number of input formats
that can be validated. Secondly, in the second pop-up
Arrange your data menu, make sure that ‘Is A Valid Date’ is the logical
As you can tell from the three column names, the first operation automatically set for you. On the following
PRO TIP
column is going to hold the date of the purchase. line, you can now choose to either show a warning if a We used the new version
of Google’s spreadsheet
Google spreadsheets have a data validation feature value isn’t a date, or reject the input. We went for the for this tutorial – released
that does two things for you. first option, as the second can be a little restrictive, early March, but it should
It will only allow a valid date to be entered. This especially if you just want to delete a date completely, also work on the older
version.
stops any rogue data creeping into our scripts, as this isn’t accepted as a standard date.
obviating the need to write code to handle the We don’t make any formatting constraints for the
subsequent errors. other two columns, although theoretically we could for
The convenience of date formatting as you get a the second column, which is going to hold the value of
pop-up calendar from which you can choose your each expenditure. We don’t use the third column,
date. This is much easier to use than typing in a date ‘Where’, but we find this information is useful for
manually, and avoids any confusion over how a date monitoring where you spend the most money and for
should be formatted. problem solving if you need to cross-check a purchase
To enable data validation, Shift+select every cell in against a bank statement. This is only the first sheet,
the first column beneath the title, and either right-click however, and we’re going to create a lot more
and select Data Validation or select the Validation functionality in the second sheet, which you can create
option from the Data menu. A window will appear by clicking on the ‘+’ symbol at the bottom of the page.
3 DATA PROCESSING
Before moving on to creating the second sheet, we and monthly spending. To make sure everything
need to give them both names that are going to make works, we’d highly recommend creating some dummy
moving between them easier. We called our first sheet data back on the first sheet so that when we add
Receipts, as the values were mostly read off grocery some calculations (and eventually the script), they’ll
receipts after buying something, and Budget for the have some real numbers to work on and you can
second sheet, which is what we’re going to explain judge on the feedback whether everything is working
now. You rename sheets by right-clicking on the tab at correctly. After you’ve done that, switch back to the
the bottom of the current spreadsheet. second sheet. The first two columns will hold a
We’re going to create four columns in the second reformatted month string and the total expenditure
sheet, all of which are going to be for the convenience during that month, and we can create both using a
of our script rather than for direct use – although formula. Double-click on the A1 cell (the first one on
they’ll also provide a good overview of your annual the sheet), and enter the following:
www.linuxvoice.com 107
CODING GOOGLE SCRIPT
Google doesn’t provide
=query(index(Receipts!A:B), “select group by year(A)+(month(A)+1)/100 label
much error feedback, so
you need to make sure all year(A)+(month(A)+1)/100,sum(B) where A is not null group by year(A)+(month(A)+1)/100 ‘Month’,sum(B) ‘Total’ “)
brackets and quotation year(A)+(month(A)+1)/100 label year(A)+(month(A)+1)/100 This is the remainder of the query. The group by
marks are correct when ‘Month’,sum(B) ‘Total’ “) makes sure that the same months are grouped
entering a query. If you’re familiar with spreadsheets, and Google’s in together and with a label that’s the same as the
particular, you’ll know that you can access data calculation – this will be the value itself. And to the
contained within its sheets using a ‘select’ statement, right of this we place the total sum(B) for all the
just as you would a database. And that’s exactly what expenditure from that month, along with two titles for
we’re doing here. The reason why we’re doing it this the two columns that are created. If you’ve created
way is because it gives us greater flexibility in how we dummy data on the first sheet, you should see an
handle the return values. Here’s what it does, broken entry in the first column for each month of
down into chunks of functionality: expenditure, along with a total for that month in
=query(index(Receipts!A:B), column B.
This basically grabs an array of values from both We now need to add three extra columns. In
the A and B columns of the ‘Receipts’ sheet on your column 6, or ‘E’ on the sheet, we’re going to type the
spreadsheet. ‘Receipts’ need to be the same the name word for each month starting with January in E2 and
of your first sheet. The data from the two columns, A ending with December in E13. This is a cheat, so we
and B, is then passed on to the ‘select’ statement, for can email the word for the month from the script. In
PRO TIP first part of which we’ll tackle next: the column to the left of this, ‘D’, enter the budget you
You can show all select year(A)+(month(A)+1)/100,sum(B) where A is not null want your spenders to adhere to for each month.
formulae running on a
spreadsheet by selecting We’ve done this for each month separately in case
the option from the ‘View’ Date formatting you wanted more budget for Christmas or birthdays.
menu, making problem For our eventual script to work without any extra Finally, to the left of the budget column, we’re going to
solving a little easier.
effort, we need the month to be formatted in a specific enter a calculation to work out how much money
way: 2014.05, for May 2014, for example. Not only you’ve got to spend in each month. This is as simple
does this help with sorting, but it’s easier to process as subtracting the contents of the cell to its left (the
as it appears as a floating point number. total for the month), from the contents of the cell to its
The above command creates that formatting by right (the overall budget for that month). To do that,
taking the year and month from the first column (A), double-click in the second cell in column C and type
and pushing the numeric value for the month through =SUM(D2-B2). You can easily copy and paste the
a division by 100 to push the two digits to the right of formula so that it changes to reflect the left and right
the decimal place. We’re also selecting the cells of each new position by dragging the blue border
corresponding value in the adjacent column. surrounding the cell down the column.
4 WRITING THE CODE
The final step is to write the JavaScript-like code to fairly obvious within your spreadsheet’s URL:
take the data from our spreadsheet and email it to https://docs.google.com/spreadsheets/d/****/
ourselves. To create a script from the spreadsheet, edit#gid=1426067592
choose ‘Script Editor’ from the Tools menu. This The next few lines of code are going to make a few
opens a new editor window containing a simple assignments to get the current date and implement
template function called ‘myFunction’. Here’s the first an offset. We’re assuming your budgeting starts in
bit of code – place all this code between the curly January, but if it doesn’t, change the first startmonth
brackets of the function: value to your start month number. You’ll also need to
var sheet = SpreadsheetApp.openById(“1dWqQha3E”); offset the word list on the spreadsheet.
var budget = sheet.getSheetByName(“Budget”); var startmonth = 0;
All this code is doing is opening the spreadsheet we var date = new Date();
opened earlier. The value within the double quotes is var month = date.getMonth();
the reference to the spreadsheet, and you need to get month = (month - startmonth) + 2;
this from its URL – it’s the value that appears where We’re now going to grab some data from the
the **** is in the following line, but this might depend spreadsheet, first by using the getRange method with
on the version of sheets that you’re using. Either way, the month variable to specify the row and ‘3’ for the
the unique identifier for your spreadsheet should be ‘Remaining’ column. This value will then be appended
108 www.linuxvoice.com
GOOGLE SCRIPT CODING
to a string we’ll use as the subject line in the email, as Google’s script editor has
well as within the body of the email later: syntax highlighting and an
var dataRange = budget.getRange(month,3); effective debugger, which
var data = dataRange.getValues(); can help if you find any
var remaining = parseFloat(data);
errors.
remaining = remaining.toFixed(2);
var subject = “Grocery Budget Remaining: “ + remaining;
We’ll cheekily use the same trick to add the text
string for the month, taken from the fifth column in
the spreadsheet:
dataRange = budget.getRange(month,5);
data = dataRange.getValues();
var message = “Month: “ + data + “\n”;
Add to the body of the message by grabbing the
total spend value and putting this in along within the
message before adding the total budget for the month:
dataRange = budget.getRange(month,2);
data = dataRange.getValues();
var total = data;
dataRange = budget.getRange(month,4);
data = dataRange.getValues();
message = message + “Total spend: “ + total + “\n\n”;
message = message + “Budget: “ + data + “\n\n”; email address to be your own, entered carefully, PRO TIP
Now we’ve got all the variables together, we can because the nightmare of being blacklisted for mail Use the ‘Share’ button to
write a quick conditional expression that changes bombing your budgets from Google’s servers isn’t allow other people to add
expenditure, and don’t
the text of the message depending on whether worth the potential embarrassment:
forget to add their emails
you’re under or over budget, leaving the final step to if (total < data) to the script if you want
be the sending of the email itself. This is remarkably message = message + “Great work! We’re under budget!\n”; them to get a notification.
simple from Google App Script, as you simply call else
the sendEmail method from MailApp, using an email message = message + “Oh no! We’ve gone over budget!!\n”;
address with both the subject and message variables MailApp.sendEmail(“graham@linuxvoice.com”,subject,
to handle everything else. Obviously, you’ll want the message);
5 RUNNING THE SCRIPT
You’re now at the point where you can run the script. You’ll need to give your
To do this, just click on the small black ‘Play’ button in script permission to
the script editor toolbar. The first time you run the access your spreadsheet
script, you’ll be asked to authorise its access to the and to use your email
spreadsheet and to your email account, which is account.
where the email will appear to originate from. With a
bit of luck, a few moments after validation the script
will execute and you should see an email like this:
Subject: Grocery Budget Remaining: 217.50
Month: April
Total spend: 182.5
Budget: 400
Great work! We’re under budget!
Congratulations! It works! All that’s now left to do is
schedule the script to run at a time that makes best
sense for you. This is accomplished through Google’s
trigger system, which can be enabled by going to the You can even use a trigger to send an email whenever
script editor, clicking on the ‘Resources’ menu and the spreadsheet is opened or changed, giving you
selecting ‘Current Project’s Triggers’. A wide window the awesome cloud control for your budget, and
will include the text ‘Click Here To Add One Now’, and ultimately, more money to spend on beer.
when you click on that, you can select a ‘Time-driven’
event to run on a ‘Week Timer’, ‘Every Sunday’ at a Graham Morrison left eBay off this budget spreadsheet
to hide the amount he spends on vintage synthesizers.
specific time, or whatever day/time work best for you.
www.linuxvoice.com 109
MASTERCLASS INKSCAPE
MASTERCLASS
Essential Linux tools explained – this month, say hello
BEN EVERARD to the Inkscape vector editor and the ImageMagick suite.
GET TO KNOW INKSCAPE
Get into scalable vector graphics with the best of its class on Linux.
T
o quote its website, Inkscape is professional-
JOHN LANE quality vector graphics software that is
used by design professionals and hobbyists
worldwide to create a wide variety of graphics such
as illustrations, icons, logos, diagrams, maps and web
graphics. Inkscape uses the W3C open standard SVG
(Scalable Vector Graphics) as its native format, and is
free and open-source software.
Let’s unravel that. Scalable Vector Graphics is an
alternative to raster (also called bitmap) graphics,
in which images are composed from dots, or pixels.
source:http://en.wikipedia.org/wiki/File:VectorBitmapExample.svg
SVG’s main advantage is that it is scalable, meaning
that enlarging a drawing does not reduce its quality,
unlike raster images that become blocky and lose
focus and sharpness as their size increases.
A vector image is defined in terms of geometrical
elements such as lines, curves and polygons that are
themselves based on mathematical expressions that
can be rendered at any size without loss of detail.
Open file format
The name SVG also refers to a file format and mark-
up language for describing two-dimensional graphics. What enlargement does to an image – Vector vs Bitmap.
The XML-based file format is royalty-free, vendor-
neutral and defined as an open standard by the World When launched, Inkscape presents a single window
Wide Web Consortium (W3C). It is Inkscape’s primary with the ubiquitous menu and toolbar across its top
file format. Inkscape is an open-source alternative to and the canvas, where you will draw, presented in the
Adobe Illustrator and it’s available in the repositories of centre between further toolbars on the left and right-
most distributions. hand sides as well as the status bar at the bottom. All
of these areas are optional – anything that you don’t
Learn more need can be hidden with View > Show/Hide. It’s worth
keeping the status bar, because it often displays hints
Inkscape’s drawing tools create paths: a arriving at the node lined up with the control that can make the many tools easier to use.
series of two or more nodes connected line (geometrically, the control line is the You can zoom the canvas in and out and, when it’s
by Bézier curves. The Pencil (F6) and curve’s tangent line at the node).
zoomed larger than the window, you can move it (or
Calligraphy (Ctrl+F6) tools allow you to do Intermediate nodes can be smooth,
this with a free hand but the Pen (Shift+F6) making curves flow together, or cusp, which pan) around, either using the scroll bars, dragging with
is somewhat different because, instead of gives a hard corner. When a node is smooth, the middle mouse button or, using the keyboard, with
drawing, you place nodes and use handles to its control lines form one straight line. Ctrl+arrow keys.
shape the curves. Getting to grips with Bézier curves will The Toolbox is displayed down the left-hand side
Handles are the points at the end of control take a little experimentation and practice. If
of the main window and contains the main drawing
lines that extend from a node. There is one you really want to understand the underlying
handle for each curve connected to the node. mathematics, http://bit.ly/bezcurve uses and editing tools. The Tool Controls toolbar displays
The curve bulges towards the handle before interactive examples that explain it well. the controls for the selected tool beneath the menu
bar. You’ll find the usual tools for drawing shapes
110 www.linuxvoice.com
INKSCAPE MASTERCLASS
and lines, adding text, filling and erasing, but the way
Inkscape does text, and
they work will feel strange if you’re new to this way not always in straight
of drawing. Hover the mouse over each one to reveal lines. And straight lines
a descriptive tooltip and the associated keyboard can be reshaped with
shortcut. We’ll mention the keyboard shortcuts as we Bézier handles.
tour the application.
In addition to the toolbars, you can display various
sub-windows (or modeless dialogs, meaning that you
can do other things while they are visible). You can
leave the ones that you frequently use on the screen
so they are accessible and you can quickly toggle all
of those on or off with the F12 key.
Cutting shapes
Let’s start by creating some shapes with the rectangle
(F4), circles and ellipses (F5), stars and polygons (*) and shear. In each case, holding down Ctrl restricts
and spirals (F9) tools. They all work in a pretty intuitive certain movements (eg to lock on to horizontal or
way: click on the canvas and drag the mouse to the vertical). You can use the Controls toolbar to fine-tune
size of shape that you want. The shape has handles the object’s size and position.
that you can drag to resize or alter its appearance; you All of these transformations can be applied to a
can easily round a rectangle’s corners or reduce a group of objects that have been selected together. A
circle into a segment. Each shape that you lay down is Shift+click adds an item to those already selected. PRO TIP
a separate object with its own attributes, like colour. You can drag the selected objects to move them or The notifications area
displays hints as you edit
Use Fill and Stroke (Shift+Control+F) to work with use Align and Distribute (Shift+Ctrl+A) to control their paths.
colour. Fill is the colour inside an object and Stroke relative positioning.
is the colour of its outline. You can specify colours
in various ways including RGB and CMYK and there Group objects
are tools for gradient-fill and stroke styling that allow As a drawing becomes more complex, it can be useful
control over stroke thickness, style (solid or broken to logically separate or combine related objects. You
lines) and end-points like arrow-heads. can Group (Ctrl+G) and work them as one or you can
Use the Text (F8) tool to create text objects. These use layers to separate related objects – imagine the
enable you to type text onto the canvas and select canvas as a stack of transparencies. You can control
fonts, sizes and effects. You can manually kern, which the stacking, or Z-order, of layers, groups and individual
is to adjust the spacing between characters, and objects, moving them above or below others.
move them vertically too. You can also make text flow Inkscape is packed with features – so many that
along a path or within a bounding box. you can be perfectly productive without even knowing
The pencil and pen are the tools for drawing lines, half of them. But if you ever find yourself wanting for
PRO TIP
which Inkscape calls paths. Start by drawing freehand more, there are many extensions available (http://bit.
There are keyboard
with the pencil (F6) using the same click-and-drag ly/inkext) and, if they aren’t enough, you can always shortcuts for just about
action that worked for shapes. Alternatively, click two write your own or even edit your drawing’s underlying every action. See
points to get a straight line between them. Each path XML directly. Shift+Ctrl+X opens a live XML editor - http://inkscape.org/doc/
keys.html.
is a separate object. any changes made, either via Inkscape’s tools or by
A Path is actually a series of nodes connected by editing the XML by hand, are reflected in the other.
Bézier curves, and you can see these nodes with That is the ultimate flexibility, albeit a little more than
the Edit Paths By Nodes (F2) tool. You can click and most users would ever need.
drag each node to adjust the line or simplify (Ctrl+L)
it, reducing the number of nodes. You can edit paths
with F2, and it’s also possible to convert non-path Inkscape’s main window
objects, even text, into paths and gain better control showing some basic
shapes.
over them.
Once you’ve laid down some objects, be they
shapes, text or paths, you will probably want to tweak,
adjust and otherwise edit them. Inkscape comes
to the rescue and places a number of tools at your
disposal, the most useful probably being Select and
Transform (F1 or Space).
Click any object with this tool selected and you’ll see
it highlighted by a bounding box with handles at its
corners that you can drag to resize the shape. If you
click again, the handles change to enable you to rotate
www.linuxvoice.com 111
MASTERCLASS IMAGEMAGICK
GET TO KNOW IMAGEMAGICK
Who said you need a GUI to edit images…
W
orking with images is a task that you’d devices. We’ll see some of these in action as we look
naturally expect would require a graphical at various commands.
user interface. But there are some tasks Another useful command is identify. It displays
that can be completed more efficiently without one information about an image in a one-line summary
– as you’ll have seen in our cover feature! We only identify my_image.png
scratched the surface of ImageMagick there though, my_image.png PNG 320x240 320x240+0+0 16-bit sRGB
so let’s go deeper now. 71.4KB 0.000u 0:00.000
ImageMagick, or just “IM”, is a collection of Add the -verbose option to get a very detailed
command-line tools and APIs that can be used to information report.
work with images in various formats. They enable
you to perform many editing operations without a Geometric argument
graphical environment. It’s been available for many You perform transformations while converting by
years and should be a straightforward install from giving appropriate command-line arguments. Resizing
your usual package repository. is a common task of this kind.
Because a GUI isn’t required, IM is well suited to a convert image.jpg -resize 600x400 image.png
server environment and can support web and other This gives you a PNG image that is a maximum of
applications that receive and process image files. 600 pixels wide and 400 pixels high. It preserves the
It can be used in scripts to quickly and efficiently aspect ratio and won’t stretch, compress or otherwise
perform similar operations on large numbers distort the image.
of images. Tasks like bulk format conversion or You can specify image size, called geometry,
thumbnail creation are easy to perform when handled in various ways: as a percentage, either applied
this way. uniformly to the width and height (50%) or separately
PRO TIP The API supports many popular programming (50x75%), but doing so does not preserve aspect ratio.
jqmagick.imagemagick. languages including C, C++, Java, PHP, Perl, Python Explicit values, as we saw, are maxima by default
org is a free online image and Ruby as well as a good number of lesser-known but you can use a caret (^) to reverse this:
manipulation service. ones. If you need image processing in an application, convert image.jpg -resize 600x400^ image.png
the APIs most likely have you covered. In this case, the resized image will be at least 600
The ImageMagick suite comprises 11 command- pixels wide and 400 pixels high and the aspect ratio
line tools that accept similar command-line is preserved. You can use an exclamation mark (!) to
arguments and parameters, so knowledge of one tool force the geometry and ignore the aspect ratio. You
is transferable to the others. The best tool to start with can give maximum (>) or minimum (<) sizes and the
is called convert. image will only resize if they are exceeded.
convert image.jpg image.png Geometries can also be specified as one dimension.
That’s probably the simplest ImageMagick command ImageMagick calculates the other dimension so
and it does as it says: converts the image from JPEG that the image’s aspect ratio is maintained. A single
format into PNG, leaving the original file intact. dimension is assumed to be the width unless prefixed
ImageMagick supports myriad formats including with an x. You can even specify a maximum number
those you’re most likely to need (PNG, JPEG and GIF). of pixels with the @ operator.
You can list the supported formats:
convert -list format Transmogrification sequence initiated
Some formats are real whereas others are pseudo If you want to overwrite the original file, say because
formats prepared via an algorithm or input/output you’re resizing but not changing the format, you can
use mogrify. This is similar to convert except that it
doesn’t require an output file but instead overwrites
the original.
mogrify -comment “LinuxVoice example” *.png
You would use mogrify for tasks where you want
to modify the original file, which will happen unless
processing changes the format. It’s better to use
mogrify for simple in-place image processing tasks,
A montage of resized
images. We used identify, especially when batch processing. But convert is
convert, montage and more suitable for more complex image processing
mogrify to produce this and transformations, because it can perform multiple
image. commands and works well in command-line pipes.
112 www.linuxvoice.com
IMAGEMAGICK MASTERCLASS
As well as resizing, you can perform image Draw onto an image with
transformations (like crop, chop, rotate, shear and roll) graphics primitives. In this
and enhancements (colour, contrast and brightness) example, we drew some
or apply various special effects. All of these are simple shapes, some text
controlled using command-line options and they are and a Bézier curve.
described in full on the ImageMagick website
(http://bit.ly/imopts).
Magick Draw
You can use convert to create images from scratch.
To draw an image you start with a blank canvas that larger one. Just for fun, however: it’s hardly secure
you can create using a pseudo image file format and it’s very brittle (don’t try it with a lossy format like
called xc (a historical reference to X Window Colour) JPEG). First, make a message:
with an optional colour that defaults to white: convert label:”Linux Voice” message.png
size 100x100 xc: # white (default) and embed it with composite. This overlays images to
size 100x100 xc:wheat # off-white produce a single composite. Here, we use rose, which
size 100x100 xc:none # transparent is one of a few default images that ImageMagick
As well the plain xc canvas, other choices are gradient can generate, but you could also use your own. The
and plasma. -stegano option does the embedding and starts a
When an option requires a colour, you can supply given number of pixels into the image:
it in a number of ways, either as a colour name composite message.png rose: -stegano +27 rose_message.png
or in decimal or hexadecimal notation like this Decoding requires knowledge of both the offset and
rgb(255,128,0) or #EF9CB0. You can list colour the dimensions of the embedded image (make a note
names with of this with inquire message.png).
convert -list color display -size 66x15+27 stegano:rose_message.png
The documentation describes other supported colour
systems like hue-saturation and Lab colour space. Beyond the command line
You use drawing primitives to ‘draw’ on the canvas; There are some commands
there are various options including circles, rectangles,
irregular polygons, Bézier curves and text. You use
that require a graphical
environment because they
“As well as resizing, you can
them with the draw command-line option: display images – useful if perform image transformations
convert -size 100x60 xc: -stroke black -fill red -strokewidth 2 \
-draw ‘circle 50,30 50,55’ circle.png
you want to see the fruits
of your efforts.
and enhancements.”
You can also draw using SVG primitives read from a display is a very basic
SVG file; convert can render from SVG. X.Org application that displays one or more images. A
left-click opens a menu with commands for viewing
I didn’t know you could do that... and modifying the image and the right button pops up
ImageMagick has a few extras that you may find giving quick access to the main ones. It’s by no means
useful. There are pseudo formats that acquire images a replacement for Gimp or Inkscape but does give you
from a scanner, either the default a way to visually complete some tasks.
convert SCANX: image.png animate is for viewing image sequences
or a specific one: (slideshows). Still basic, but can be useful to see
convert SCAN:’hpaio:/net/scanner?ip=192.168.1.5’ image.png something quickly:
You can embed secrets inside images. This is called animate -delay 100 *.png
Steganography, and hides a smaller image inside a import takes screenshots straight into the format of
your choice. It has known bugs, sometimes showing
An alternative… black areas when capturing windows above others.
import screenshot.png
GraphicsMagick is a fork of ImageMagick that was made ImageMagick also has its own Magick Scripting
in 2002 and continues under active development. It has
Language, or MSL, that you can execute using the
an MIT licence instead of one based on the Apache 2.0
licence. It cites higher performance and multiprocessor conjure command. The only other command that
support as advantages along with name-spaced commands we haven’t mentioned is compare and it shows
equivalent to ImageMagick’s but with a gm prefix (such as differences between images. Try it with our stegano
gm convert...). GM is used by large sites including example:
www.flickr.com.
compare -metric PAE rose: rose_message.png rose_diff.png
Because the fork was over a decade ago and there is no
collaboration or code-sharing between the two, divergence
is unavoidable and you will notice minor variations between
the two. GraphicsMagick recognises fewer colour systems. John Lane is a technology consultant with a penchant for
All of our examples work in GraphicsMagick – just prefix Linux. He helps new business start-ups make the most of
the command with gm. open source.
www.linuxvoice.com 113
/DEV/RANDOM/
Final thoughts, musings and reflections
Nick Veitch
was the original editor
of Linux Format, a
role he played until he
got bored and went Cat
to work at Canonical Audio mixing
instead. Splitter! board use for
my Luminosity
of Free Software
videocasts
I
have a box full of cables under my bed. To be Knuth’s The Art
specific, it is full of USB cables. Well, cables Of Computer
and associated adaptors, extensions, 2 Improv ARM boards Programming
volumes 1-3, holding
converters, powered hubs, unpowered hubs. And up my monitor
chances are if I am looking for a specific cable, I
can untangle it from in there somewhere. The
Clipboard with open
rest of the time, the cables sleep, like some streetmap walking
Gorgon’s nest of failure, a monument to failed papers (which I
ideals and shattered promises. take with me when
I’m out, to record Thinkpad (my daily workhorse)
I understand that the ‘U’ in USB stands for missing details)
‘Universal’ in terms of the communication bus
My Linux setup Aaron J Seigo
itself, not the myriad plug/socket combinations
required to connect any one thing to any other.
But really? I still need old A–B cables for my
venerable LaserJet. One of my cameras uses a The project leader of KDE Plasma welcomes us to his habitat.
mini-B plug. I have a camera that uses some
off-the wall variation (I know, non-standard so I What version of Linux are you of any “real” UNIX box. When I figured out
can’t blame the USB guys for that), I have a using at the moment? it came with source code I fell off my chair
music-playing device that I now can’t use KDE Plasma, both Desktop and with delight.
because the micro-B port on it has broken in Active, on various devices (Intel and
some way, probably related to me trying to ARM; laptops, ARM project boards such What Free Software/open source
attach it to the wrong cable. as the Improv and tablets) on top of can’t you live without?
Is this what the future was meant to be? Are OpenSUSE and Mer OS. Kontact, for email and calendaring;
the dying hours of humanity to be spent any one of a number of web
drunkenly trying to connect your phone charging What was the first Linux setup browsers as so much happens on the web
cable the wrong way up? But lo! The type-C you ever used? these days; my development toolset
connector approaches (www.usb.org/ Slackware. I found it on a CD in the including GCC, GDB, Kate and Konsole; dev
developers/USB-Futures.pdf). It brings with it, back of a book while browsing in a environments like node.js and workhorse
apart from another indistinguishable-when-drunk bookshop. I was there to buy a book server software like PostgreSQL (of which I
format change, some good stuff – for a start it regarding the then-new Solaris, which cost am a complete fanboi ;).
doesn’t care which way up it goes. And better CAD$80… and it wasn’t even that thick. I
than that, it makes a nice click when connected. picked up the book titled Slackware and What do other people love but
I don’t really care if I have to get a bigger box, when I saw it claimed to have a full you can’t get on with?
these are the things that should have formed UNIX-like OS on the CD in the back I Artistically devoid pop stars, religion,
part of the standard in the first place – hardware checked the price of the book and just bitcoin, funnelling personal
designers, please note that usable-after-a- about choked: it was half the price of the information through private interests who
double-Hendricks is a more precious feature thin little Solaris book. I couldn’t believe happily violate our trust and our rights,
than speed increases, and one for which we are that I had a UNIX-ish system on a papayas and the proliferation of desktop
happy to pay extra implementation £££. computer that cost a fraction of the price environment projects in the last few years.
114 www.linuxvoice.com
A quick reference to Vim commands