Letters

Short vs. Clear

Regarding Dave Taylor's question to readers in his September 2012 column, my vote is for both. I find the various short forms useful and like to discover them; however, I absolutely agree about the problem of obfuscation. I tend to avoid shortcuts in code I will have to maintain and use them only on the command line or in “throw-away” code.

I suggest that you focus on clever ideas for the most part and maybe dedicate occasional columns to shortcuts.

Alternatively, you could finish the column with a shortened version of your monthly script with some minimal notation to guide the advanced or the curious in deciphering the syntax.

Love your column Dave, keep it up.


Keith

Another Response for Dave

Use new bash features even if some old servers don't understand them? My answer is yes! My clients want the best solution for their challenges. If they can't or don't want to upgrade an old server, they will pay the extra time to adapt the script to the ancient version of the shell. But they want me to be as efficient on the new servers as I (not the script language!) can be. So I learn everyday something new and use it in my daily work. Please do the same!


Eugen

Bash Notational Shortcuts

When efficiency is important, but gets in the way of clarity, I like to use a feature found not only in bash, but in sh, csh, zsh and many other scripting languages. If you start a line with a # character, the shell ignores the remainder of the line, which allows you to include human-readable explanatory material.

You even can precede the # with white space, so the explanatory material aligns with the indentation level of the code!

i18n? No problem—the shell automatically adjusts to whatever human-readable language you use in the remainder of the line!

But wait—there's more! It doesn't even have to be a human language! If you replace a clunky but clear construct with a tight, abstruse one, you even can include the former as explanatory material, as long as you precede it with this almost-magical # character!

Given how much time we all spend debugging or enhancing other people's code, I am continually astonished at how many shell programmers seem to be unaware of this universal feature of scripting languages.


Jenny Howard

Linux-Based Security Camera Systems

I have read in the Letters section that readers say they wish to see different articles or more home-use practical-type projects. May I suggest a possible article about Linux-based camera security systems? ZoneMinder is one that comes to mind, but I'd also like to read about what is available in the commercial product area that supports IP cameras as well as DVR cards with cameras attached.

I have used several brands of DVR capture cards, and most ran on a Windows-based system. I purchased a 16-port card and experimented with ZoneMinder and then discovered a company called Bluecherry (www.bluecherry.net or store.bluecherry.net), and I purchased one of its hardware-compression DVR cards and use its Linux-based camera server system. The company has a newly released 2.0 version of its server software running on Ubuntu 12.04 Linux.

Many people like the idea of being able to put up cameras around their homes or businesses. LJ might want to do a simple article of some of the commercial and open-source DVR-security-camera-type applications available for Linux. I have seen articles written for Asterisk and other IP phone/PBX systems that can be used in homes or businesses, so why not one for security cameras?

I have been reading the magazine for more than seven years, and given the pros and cons of what others have said about the switch to the all-digital format, I am very pleased with it and the choices of formats available.


Chad Pauli

Setting up a Linux-based camera system certainly sounds like a cool project. I actually really like the folks at Bluecherry, and I tried my best to purchase an entire 32-camera system from them. Sadly, the red tape at my day job prevented it, but I did try the software, and it really was amazing. For some strange reason, it seems that many systems are Windows-only, or claim to be Web-enabled but then require Internet Explorer in order to work. Hopefully, someone will read this letter and offer an article on configuring a camera system. It certainly sounds interesting to me!—Ed.

Comment to Jeff Shutt

When reading the Letters section in the September 2012 issue of Linux Journal, I saw Jeff Shutt's message about shell scripting and .csv files, and I wondered if he'd already heard of csvdb (sandbox.ltmnet.com/csvdb). This tool allows one to manipulate .csv files with SQL (including UPDATE and ALTER TABLE), and it could be a good alternative to shell scripts.

I don't know how to contact him, but maybe you could act as gateway and forward this info to him? Thanks in advance.


Frank Scheiner

Even better, how about we print your letter? That way Jeff won't be the only one benefiting. Thanks!—Ed.

Kyle's Raspberry Pi Beer Fridge Suggestion

I received my Raspberry Pi a couple weeks ago, a month after I ordered it, but it seems that production times are improving and that the new boards are being manufactured in Britain.

I started playing with it, and I have a suggestion for Kyle's beer fridge. My idea is to use a TI LaunchPad board (www.ti.com/LaunchPad) with an MSP430 micro-controller that has an integrated temperature sensor. TI provides all the development tools for free, and the price is less than $5.

The idea is to control the temperature on the LaunchPad and use the Raspberry Pi to retrieve the information and display it or post it on a Web server.

I had only one problem. The Raspberry Pi didn't boot with the LaunchPad connected to the USB port. I have no idea why, but the workaround is to connect them using the SPI port (a tutorial on how to do this can be found at mitchtech.net/raspberry-pi-msp430-spi).

I really enjoy every issue of LJ, and read each of them from the BOF all the way to the EOF (no more cover to cover).


jschiavon

Constructive Complaint, a Thank You and Further Ideas

Here in Belgium, I bought LJ at the store for years, and now I have to cope with Texterity. I don't really enjoy the format, but the content is there. I restrained from protesting and gave this a lot of thought. Since you went digital, I finally realized what was bugging me the most: it is not the change of media, but that it wouldn't be possible to select “text mode by default” in some settings. The second issue is related to my media consumption habits. I read LJ when I'm not at home, thus, almost exclusively on mobile Internet, which often is very slow. Some kind of cache, allowing on-line sync and off-line reading would be a killer feature.

Considering that this would not be possible with Texterity, you taught me there has to be another way, as I will explain now. Last week, I received a new keyboard with heaps of funky keys (Corsair K90). Upon connecting the keyboard to the computer and searching the Internet on how to get it to work, I discovered that so far, no one has gotten the funky keys to feed the penguin. I decided to dig a little deeper into the problem. Combining tricks I learned from Kyle Rankin's hacks and Dave Taylor's scripts, it took me four days to get a very functional script that should already be able to manage various types of custom inputs with minor tweaks. It is still far from perfect, but the code is on https://github.com/jupiter126/k90-test.

Have you considered crowdsourcing the LJ app? Again, I thought about it a lot, and it seems to be the best long-term solution. (No, I don't sound like Lennart!) The main argument is that since LJ went digital, there is no point in paying for copies of LJ anymore, and that most LJ readers have the technical know-how required to wget pirate versions, although they willingly choose to pay instead, in order to support LJ. Thus, piracy is not an issue, as nowadays we are not buying an app, but rather sponsoring the writers of the content.

Another important argument is security, it is normal that you don't want to run unknown code on a server, but hey, I never said I wanted to crowdsource the server! Setting standard procedures and protocols for authentication and issue retrieval are the key elements for successful adoption (like passing zipped XMLs after successful authentication). From that point on, users or groups of users will be able to code their own apps for their own devices, and instead of having users like me complaining all year long about the past, you will promote the *NIX way. If you don't like the application, stop losing time complaining and start writing one you like better.

On the other hand, I am sure a lot of your readers are not only willing to code a killer app, but also have the skills to do so and prefer running code they know rather than an obscure app. Do I really need to convince you that the future is open source? What are you waiting for in setting up an “LJ Git”? I would love to find Dave's code there, for example!


Nelson

Thank you for the feedback. I like the idea of a Linux Journal Git repo. We'll have to see if it's feasible. Regarding your text-mode question, I find that the .mobi and .epub versions are much more text-friendly. My favorite way to read Linux Journal currently is either via PDF on a big tablet or with Amazon's Kindle, because the latter will sync my reading progress between devices.

Even if there is not an official LJ repo on GitHub, I like the idea of a crowdsourced app to interface with the existing distribution model!—Ed.

Configuration Management Article

I've been one of your readers for about eight years, and since then, a lot of stuff has changed. As a long-term Linux hacker, I've been hacking on a configuration management system for some time.

As it has matured, I think it could be time to make it more public. Thus, I was wondering whether you are interested in getting or writing an article about cdist—the new kid on the block of configuration management systems. cdist is kind of a revolution, because it is almost completely dependency-free and has very well known DSL. Let me know what you think.


Nico

By all means, submit an article query on the topic to info@linuxjournal.com. Configuration management is certainly something sysadmins are pretty much forced to use now. I'll admit I've never heard of cdist; at the very least, thank you for bringing it to my attention!—Ed.

Readable Shell Scripting

I just read Dave Taylor's Work the Shell column titled “Bash Notational Shortcuts: Efficiency over Clarity” in the September 2012 issue. I agree wholeheartedly. Bash code should be written for readability, not efficiency. If the code needs to be efficient, then use a compiled language to reduce processing time. If I use some clever Bash construct in a script, six months (or however much time) later, I may have to dig around to figure out what I did and how I did it. Not to mention that others coming after you may need to figure out what you did so they can make requisite changes. This holds for any moderately usable programming language that gives potentially many ways to solve a particular problem.

I say keep your examples easily understandable and inefficient. You may want to pepper your examples with more efficient examples, but because your audience potentially could be at many different levels of knowledge, keeping the examples readable and understandable without having resort to research in order to understand them will benefit more of us who don't script on a daily basis.

Thanks, and I look forward to your column next month!


Trey Blancher

Thanks!

Thanks so much for offering a digital version of Linux Journal in .epub format. I already had a NOOK (original) and a NOOK Color reader, so I didn't need any additional hardware to take advantage of your format change.

In 2011, I was offered an early retirement, which I took. A short time later, I moved overseas. Linux Journal is the only magazine I have renewed my subscription to. At this point, I have two requirements: a digital-only subscription option and .epub as a format option. Thankfully, Linux Journal fits both of my requirements.

Thanks again for an affordable way to keep up with one of my favorite publications.


Gar

That's great to hear, Gar! We decided to invest the time to produce the .epub and .mobi versions, because we wanted the switch to digital to offer more rather than less. I find the multiple formats very nice, because I don't always read from the same device.—Ed.

Xoom: It Really Whips the ZaReason Tablet's Arse!

Although I think it is a always a noble endeavor to try to produce hardware tailored for Linux/open source, I'm not so sure about Android's future in that it is so extremely limited and kludgey compared to any bona fide laptop/desktop Linux distribution, but that is beyond the scope of a mere letter to the editor. (Yes, yes, I know it is possible to run a real Linux distribution using chroot and a VNC client on rooted Android devices. Go ahead and try it and see how much fun you have!)

Err, getting back to the point, ZaReason's underpowered tablet is just not worth the price—not when there are used Motorola Xooms on eBay for about $200. The Xoom has a dual-core processor, a 1200x800 screen nearly big enough for comfortable magazine PDF reading, a surprisingly good quality camera, USB host support via a cheap $5 cable, and the latest version Android. What with all the competition, with the price of a used original iPad in freefall and $200 Nexus 7s, why would anybody buy this ZaReason thingy? (I am in no way affiliated with Motorola and have no love of big corporations. I just want a cheap tablet!)

Come to think of it, don't most Linux-preinstalled laptops—still rare beasties—command a hefty premium? You often can buy a svelte used high-end Lenovo or MacBook Pro for the price of one of those $1,200 Emperor seven-pound Dell boat anchors. What is this, the Linux Tax?!

Dirty word or not, I doubt rooting is such a big deal for most FUD-resistant, warranty-voiding, independent-minded Linux users. Rooting the Wi-Fi-only Xoom was trivial, after a few hours of wading through Web fora. (Wading through semi-literate forum-geek nonsense is nothing new to anyone who has used Linux for any length of time.)

Like most new Android devices, the Xoom sucked at first: a microSD card slot you couldn't use because there was no driver and a sluggish UI that I was tempted to refer to as another sort of sandwich besides ice cream. But now, the Xoom is nearly mature. Although the UI still looks like crap—a perennial problem of all Android devices (haven't the devs ever heard the old realtor's saying “light and bright”?)—it is definitely “buttery” smooth ugliness with plenty of mostly free apps: Netflix, eBay, Firefox, e-book readers and so on. If only the half-baked Android UI didn't resemble something out of the Addams' Family School of Design....


Mike "Zaphod" Grossman

I understand where you're coming from, but in the case of ZaReason, the company's willingness to leave its product open is a philosophical mindset I really want to support. For me, it's sort of like shopping at a local farm market and paying more for vegetables, because I want to support those folks. ZaReason may not be able to match the price point of bigger companies, but it gets my hat tip for its business ideals.

I'll admit, as an end user more than a developer, I'd be more likely to buy a Nexus 7, but if I were a developer, I could see the wide-open model being very refreshing.—Ed.

Random Numbers and OpenMP

I was reading the May 2012 issue when I came across “Parallel Programming in C and Python” by Amit Saha, which had relevance to my job supporting weather/climate modeling on HPC systems. OpenMP is a particularly nice way to handle threading, but you have to be careful what you use in your parallel code. The common example of calculating pi in pi_openmp.c is a nice way of showing parallelism, but I would have liked to have seen a comment about using rand() in your function called in the parallel region. Creating random numbers in threaded applications can be tricky due to the hidden state of the generator being stored across calls. rand() is probably not the best method to use in C due to this, possibly rand_r(unsigned int) to store the state and be suitable for this example. There is also probably a race condition to decide which thread gets which random number due to using the same random state.

Another aspect I would have liked to have seen is repeatability of answers, which is important in science where OpenMP can affect the order of calculations.

Otherwise, I found the article to be a great way to introduce people to threading, and I especially found the Python aspect useful to add to my understanding. I hope to see more HPC-relevant articles in the future.


Thomas Green

Amit Saha replies: Thank you for reading my article and writing in with your comments. I am glad you found the Python bits interesting.

I find your comments about rand() and OpenMP enlightening, as I myself didn't think of it before. This blog post seems to be suggesting the same thing: software.intel.com/en-us/blogs/2009/11/05/use-of-rand-in-openmp-parallel-sections. And, a number of other blog posts seem to suggest that the initialization of the generator be done separately in the individual threads. This means that in pi_openmp.c, the random number generator should be initialized using a random seed (such as current time) in the part_count function. Thanks again for writing in.

Eight-Year-Old Linux User

I have an eight-year-old son who is fond of computers, mainly because of games, naturally. Last week when I got home, I saw that my Xubuntu laptop was open. I asked my son who opened it. He replied that he did it. Once I defined a user for him on Xubuntu, so that he could Google his homework. It seems he remembered the user name and password, logged on, opened Chrome, and listened to music via YouTube. For basic stuff like this, Ubuntu is simple enough for a small kid like him. I wanted to share this for those who think Linux is only for geeks.


Kaan

You are absolutely correct. It's weird for me to watch my kids use technology. They don't care at all what operating system they're using. In fact, my girls tend to do homework research on their phones before cracking open their laptops. I think I'm too old to consider my smartphone my “primary computing device”, but my kids don't have a problem with that mindset. They also grab my Dell D420 running Xubuntu and use the system without hesitation. Kids are amazing.—Ed.

Photo of the Month

Here is a photo of a pack made by a pizzeria on a beach in Palermo, Sicily, Italy. As you can read, Linux offers pizza, panini and other magnificent stuff, like “arancini”. The content is excellent, like our preferred OS.


Giovanni Organtini

Linux Pizza