Tag Archives: Linux

Are you a PC (or a Mac)?

Myths have a very long half-life, especially when it has to do with operating systems. Let’s say version N of some software was really bad at doing something, which got fixed in version (N + 2). It won’t be until version (N + 5) or so that most people will realize that the problem has been fixed. Until then, this will remain a hot topic for discus­sion each time the subject comes up.

You know what the best part is? Not one of these people would have used any version of the OS for the past five years. For instance, a typical complaint would go like this: “I used Linux (read, Red Hat Linux 7, from the Dark Ages) sometime ago (read, six years ago) and the screen resolu­tion sucked!” Obeying the rules of gossip, this gets trans­lated into, “The resolu­tion on Linux sucks!”

Unfor­tu­nately, everyone not using Linux will continue to believe this myth until someone demon­strates that the screen resolu­tion on Linux is actually awesome. Note that it is insuf­fi­cient to demon­strate that the screen resolu­tion on Linux is as good as that on any other system. That’s just too mundane to catch on.

This phenom­enon works all six ways (Linux, Windows, Mac = factorial(3)). Windows and Mac being more ‘mainstream’, however, their features and releases receive greater publicity.

It is inter­esting how these different groups interact with each other, almost as if they were following their own religion. Blind faith, super­sti­tion — it has all the elements except physical violence. Maybe one of these days, govern­ments will force their citizens to use one or the other piece of software. Then, countries will go to war over operating systems.

The Software Update Paradox

I like to keep my software up-to-date, so I sync it with the repos­i­tory every day, and see if there’s anything that needs updating.

And yet, I don’t like the fact that it takes time to perform the update, or that there is a chance that my stable system could be broken by the change, or that a package may fail to build.

So I run the update command, hoping that there’s nothing new.

Am I Cool Or What?

The title of this post was supposed to be “I Have A Macbook Pro Now”, but this one seemed just as appro­priate. I am one of those guys who watches in disdain as others argue about “being a PC” or “being a Mac” (it’s Linux all the way for me, baby) but then I figured one must try every­thing in life. Yeah, I know I’m twisting a perfectly legit­i­mate philos­ophy for the sake of personal gain, but this is my blog after all. Live with it.

Even the village idiot would have figured out by now that I’ve purchased a new Macbook Pro. I haven’t used a Mac before, except on rare occasions, so I’m still learning. That being said, there isn’t much to learn, apart from keyboard short­cuts. This operating system is Unix-y enough for me to feel comfort­able — for example, I copied over my zshrc file from my desktop to the laptop, and voila! I have a terminal that behaves exactly like the one on my good ol’ Gentoo box.

One of the disad­van­tages of being a Mac user though, is that almost every silly piece of software costs $20 or more. This is slightly mitigated by the fact that almost every­thing comes out of the box, except for Office software (no problem though, grab a copy of OpenOffice.org before they run out of copies). But I guess that’s a totally different world, where software is free (as in speech).…

Dictionary Attack

If you’re running an SSH server on a machine exposed to the Big Bad Internet, it is best to disable password authen­ti­ca­tion. Public-key authen­ti­ca­tion is a far safer option. Here’s a typical snippet of my server logs that explains why:

Nov 20 10:24:01 [sshd] Invalid user backup from 203.239.105.2
Nov 20 10:24:03 [sshd] Invalid user info from 203.239.105.2
Nov 20 10:24:04 [sshd] Invalid user shop from 203.239.105.2
Nov 20 10:24:06 [sshd] Invalid user sales from 203.239.105.2
Nov 20 10:24:07 [sshd] Invalid user web from 203.239.105.2
Nov 20 10:24:09 [sshd] Invalid user www from 203.239.105.2
Nov 20 10:24:11 [sshd] Invalid user wwwrun from 203.239.105.2
Nov 20 10:24:12 [sshd] Invalid user adam from 203.239.105.2
Nov 20 10:24:14 [sshd] Invalid user stephen from 203.239.105.2
Nov 20 10:24:15 [sshd] Invalid user richard from 203.239.105.2
Nov 20 10:24:17 [sshd] Invalid user george from 203.239.105.2
Nov 20 10:24:19 [sshd] Invalid user michael from 203.239.105.2
Nov 20 10:24:20 [sshd] Invalid user john from 203.239.105.2
Nov 20 10:24:22 [sshd] Invalid user david from 203.239.105.2
Nov 20 10:24:23 [sshd] Invalid user paul from 203.239.105.2
Nov 20 10:24:27 [sshd] Invalid user angel from 203.239.105.2
Nov 20 10:24:30 [sshd] Invalid user pgsql from 203.239.105.2

Pretty Fonts

If you install Linux for the first time and are greeted with an ugly set of fonts -

  1. Make sure you install all the popular TrueType fonts (Microsoft’s common fonts are gener­ally avail­able via your distribution’s repositories).
  2. Remember to enable anti-aliasing of fonts. Anti-aliasing can be turned on through the desktop-environment’s config­u­ra­tion, for example, KDE’s Control Center.
  3. Set the hinting to ‘medium’ while enabling anti-aliasing of fonts.
  4. Change the user-interface fonts to something that looks good, like Verdana, DejaVu or Calibri. Firefox also comes with an ugly set of default fonts, so you may also want to change those defaults too.

Mutt [Insert Dog Joke Here]

After I switched from KDE to XFCE as my desktop environ­ment, I had to abandon KMail as my email client (since I would rather not run KDE-based appli­ca­tions in a non-KDE environ­ment). The replace­ment I settled on was mutt, something I had already tried and liked a lot.

So what’s the big deal about console appli­ca­tions, you ask? I don’t know, but they’re just much nicer than GUI clients. It must be genetic or something.

So here’s how I’ve set up mutt:

  • I can read my Gmail messages (actually, Google Mail for my domain).
  • I can send email using Postfix, which routes messages through Gmail’s server
  • The recipient’s address is automat­i­cally added to my address­book when I send email
  • I can look up or autocom­plete addresses while composing email
  • Messages are signed using GnuPG before they are actually sent

I don’t like to manually check my email. Instead, I’ve set up a mail-notification applet (a ‘biff’) to check my email every couple of minutes and play a sound when there are new messages. Reading, deleting and composing mail are all just a few keystrokes away. Addition­ally, there is no need to open any heavy appli­ca­tion — the terminal window pops up within seconds.

KDE 4.1: Now In Portage

The wait is finally over. KDE 4.1 is now in the official portage repos­i­tory, which means that Gentoo users can upgrade to it without having to unmask any packages or setting up an overlay.

I upgraded to the new and shiny KDE 4.1 today for the first time. I could have easily gotten it from an overlay a long time ago, but then I figured it was best to wait for it to mature. Like its prede­cessor (KDE 3.5), this version of KDE looks quite unpol­ished until you spend some time customizing it. For instance, I cannot fathom the reasons behind not enabling font anti-aliasing by default. Without this tweak, all fonts look jagged and ugly. KDE also seems to have taken the path of Microsoft’s Windows Vista in terms of its color scheme: gray and black seem to be the norm.

Overall, I am not too disap­pointed with the upgrade, but I realize now that I’m going to have to wait for future releases for many pieces of function­ality that I used to love in KDE. This is one of the downsides of having software redesigned from scratch. For instance, Amarok 2 (still in beta) included in this version of KDE, is missing several key features, such as track-queuing and equal­izer support. I just wish the KDE devel­opers had focused on having a 4.1 release that was on par with 3.5.10 in terms of features, rather than worry about the details.

Regular Expressions

Regular expres­sions (regexes) are one of those concepts that sound innocuous, turn out to be fright­en­ingly complex when you approach them, but aren’t that big a deal when you actually get to know them.

The idea behind a regex is quite simple: it is a single concise series of symbols that can be used to repre­sent a class of expres­sions exactly. For example, a regex could be used to repre­sent “a sequence of charac­ters that begins with the letter C” or “a sequence begin­ning with b, ending with d and any number of x’s in between.” Regexes are extremely expres­sive, and can come in handy at odd times.

Regular expres­sions are built on simple rules. The following is not a compre­hen­sive list, but should provide an idea of what regular expres­sions look like -

  1. Alpha­bets and numbers repre­sent themselves. So do a large number of punctu­a­tion charac­ters. These are case-sensitive.
  2. A dot “.” repre­sents a single instance of any character.
  3. An asterisk “*” indicates that the preceding character may be repeated zero or more times.
  4. An plus “+” indicates that the preceding character may be repeated one or more times.
  5. A carot “^” is an anchor for the start of the line.
  6. A dollar “$” is an anchor for the end of the line.
  7. The “<” and “>” symbols are anchors for start and end of a word respectively.
  8. Et cetera.

For example, ^Cof*e+$ would match Coffee, Coeeeeee or Coffffffe but not Coffff, coffee or Cofeen. Regexes can be much more compli­cated in practice, but the basics are suffi­cient for many common cases.

The most impor­tant advan­tage of under­standing regexes is that it opens up the doors to a huge collec­tion of Unix tools, such as grep, sed and awk. Most Unix text editors also support regexes to some degree.

While grep is the most well-known amongst these tools — it is used to find lines that match a given expres­sion — sed aka ‘the stream editor’ is perhaps the most useful, because it can actually manip­u­late text. For instance, when I migrated more than a hundred old posts into this blog a couple of weeks ago, I needed to replace a whole bunch of <div> tags with <p> tags. That’s when sed came in useful: it took just ten minutes and a single command to get the job done.

Scripting Magic

It’s amazing how much can be achieved with the help of a few scripts. If you come to think of it, scripts are the original mashups that Web 2.0 has vener­ated in recent times.

Today, I decided that I would have a “Now Listening” box shown on my blog — I’m not sure if it is visible at this moment — which would display the name of the artist of the currently playing track on my computer. So here’s what I came up with -

  1. A Bash script that would use DCOP to query Amarok, deter­mine the currently playing song, and update a tempo­rary file accordingly.
  2. A small PHP script that would read the file and display this infor­ma­tion, but only if it is available.
  3. A set of CSS rules to format the gener­ated XHTML.
  4. A cron job to execute the script every minute.

Voila! It’s done…almost like magic.

A Fun Way To Spend A Saturday

Don’t try this at home, kids.

  1. Open a console window on your trusty old Linux box.
  2. Find a WordPress plugin you don’t need.
  3. Start typing rm -fr /path/to/wordpress/plugin-name.
  4. Instead, type rm -fr /path/to/wordpress and press enter.
  5. Oops.
  6. Spend a few hours setting up your blog all over again.
  7. Sleep.

Step #5 is the part I love the most.