Your Ad Here

Monthly Archive for August, 2006

Notes on the Gentoo 2006.1 LiveCD & Installer

So, I did it; I downloaded the newest Gentoo LiveCD and threw it at my computer to see if it would stick.

  • X did not work, from the LiveCD; not sure why other LiveCDs always seem to work with my system, but Gentoo’s doesn’t. No matter; I prefer a text install.
  • Gentoo now has (perhaps 2006.0 had this? I don’t know) a curses-based installer; this is what I wound up using.
  • The curses-based installer is pretty standard for a Linux install, but seemed a little non-intuitive at times. Maybe I’m thinking about other curses-based installers like those of ArchLinux or the old Debian installer. I can’t really explain, but if you install it with this method you may see what I mean; once you go through a few steps, you quickly get a grasp of how it is set up.
  • It seems that through the installer, you basically choose a whole list of options; it is only after you have finished selecting every possible option and/or package and selecting “install” that the installer begins to go to work.
  • If you choose a lot of packages (and there are quite a few you can choose to include), it will compile most or all of them from sourse, as is the gentoo way; so when you click “install”, go do something else for awhile. If you’ve selected X.org and Gnome or KDE, find something to occupy yourself with until tomorrow, because that’s when it will be done.

It was still installing when I left home this morning… so I’ll see when I get home how it worked.

Gentoo 2006.1

Gentoo 2006.1 was released today.

Ah…. okay. I think I’ll install it.

Fun with Python: finding simple palindromes

A common computer science exercise involves testing whether or not a given word is a palindrome; that is, whether it’s the same word if the characters are printed in reverse order. Usually this involves some sort of loop through the characters of the word, while comparing each with the corresponding character starting at the end. Since I’ve been playing with Python recently, and since Python has such interesting tools for slicing up strings in different ways, I decided to write a program like this in Python to see what I’d come up with.

Of course there are other ways to do this, maybe better ways (see the end of this post); this was just a first attempt. It looks like this:

#! /usr/bin/python 

import sys
# test; is a word a palindrome?

str = sys.argv[1].lower()

if len(str)%2==0:
   if str[:len(str)/2]==str[len(str)/2:][::-1]:
     print str,”is a palindrome”
   else: print str,”is not a palindrome”
else:
   if str[:len(str)/2]==str[len(str)/2+1:][::-1]:
     print str,”is a palindrome”
   else: print str,”is not a palindrome”

This is a fairly elementary version of such a program; it will only test single words; that is, you could type a phrase in quotes as an argument, but unless it were character for character (including spaces and punctuation) a palindrome, it would come out false. It’s made for nice, simple palindromes like radar, racecar, ogopogo, level, detartrated, or aoxomoxoa.

Looking through the code to see what it does is basically a crash course in how Python allows you to slice up strings. Like many languages, Python automatically indexes a string; so, “hello”[0] would be “h” — “hello”[4] would be “o”.

Slicing works like this:

>>>str=”hello”
>>>str[:2]
“he”
>>>str[2:]
“llo”

The actual syntax is technically string[start:finish] — leaving the start blank will start at 0, and leaving the finish blank will go to the end of the string.

Also, the [::-1] that you would have noticed in the code simply writes a given string in reverse. (Technically, the third value is the “step”, so [::-1] is simply saying “step through the entire string backwards”.) So in effect, what this program does is compare the first half of a string with the second half reversed, to see if they’re the same.

Which brings us to the simpler way to do it: if we can simply reverse a string like that, this whole program could have been:

#! /usr/bin/python

import sys
# test; is a word a palindrome?

str = sys.argv[1].lower()

if str==str[::-1]:
   print str,”is a palindrome”
else:
   print str,”is not a palindrome”

Or, if you wanted to be very succinct:

#! /usr/bin/python

import sys; str=sys.argv[1].lower(); print str==str[::-1]

Okay then. That’s enough Python geekery for one night. :-)

Note: the wise among you will chuckle when I admit that, yes, I really did write the longer, ridiculously more complicated version of the program first. I could use this to segue into how the simpler solution to any problem is rarely the first to occur to us, or how easy it is to get caught up in a “solution” (in this case, compare the first half to the reverse of the second half) and miss a simpler solution… but I’ll save that for some other day.

Another note: in my defense, my first attempt was probably remembered from a time I solved a problem like this with a for loop… in which case it could actually be more efficient to compare the first half of the string with the second half, because it means you don’t need to step through the whole thing.

Which Linux book should I read?

This was a question I asked myself over and over, several years ago in the space before I started using Linux. I had read a lot about what Linux was… but I was still a rank beginner, a neophyte. Maybe a few levels below neophyte.

I would go into the local book-superstore, and look at all the different books on Linux. Which one should I get? How would I make up my mind?

There were books on Red Hat Linux. Books on Suse. Mandrake. Books which were simply about Unix. Books about Linux in general. Among the “general” books, there were a lot to choose from also; there were the various O’Reilly offerings, particularly Running Linux, and the Nutshell book. There were the “budget” books (the ones called things like “Mastering Linux” that sell for $20 bucks and look like a graphic designer was never allowed to touch the cover). Even if one decided to go with a book about Red Hat, there were such things as Red Hat 8 Unleashed (which should date the time I was beginning Linux), or the Red Hat Linux 8 Bible. There were the books by Mark Sobell, with their nice personal endorsement by Linus Torvalds. And, of course, there were a few “official” Red Hat publications. And that isn’t even mentioning the “For Dummies” books… but enough about those.

For a beginner, the bookshelf was as overwhelming as the idea of a first install. How in the world could you separate the wheat from the chaff when you didn’t even know enough about the subject matter to distinguish them?

Well, if you’re looking to buy a Linux book, maybe my experience since that time can help you out.

Don’t Do what I did

In the end, I chose to base my purchase on a bad criteria; I chose to find a book which included a Linux distro on CD. Bad idea. I chose the Red Hat Linux 8 Bible, weighing in at about 10 lbs and about $50 USD. It had Red Hat 8 on 3 cds, and sufficient text to get one going, for sure.

What, exactly, was wrong with the book? That’s a hard thing to put a finger on. It seems quite a serious charge to allege that a 950 page book didn’t contain any useful information. I suppose it must have had a bit of useful information; it did get me started.

But the things you really want to do — like, update the latest drivers on your graphics card. Not a whisper in the book. I read the README that came with the nvidia binaries and finally got xfree86.conf edited properly (yes, it wasn’t xorg.conf then).

After a few months, I decided to abandon Red Hat. That also meant I pretty much abandoned the book, which was completely specific to just that distribution, and much of it to just version 8. I was still a little too wet behind the ears to complete a Debian install — it has since become an easier process, so is not such a daunting task — and I eventually settled on Gentoo Linux.

Gentoo was also a bit daunting of an install, but the documentation was (and is) spectacular. Technical writers everywhere should be required to read the Gentoo Installation Handbook, just to see how it should be done. Walking through a Gentoo install is a process that might take awhile, but it was worth it for me. Some folks make much of saying stuff like “I learned more from installing Gentoo than blah blah etc,” and others waste little time in mocking them for saying it. Without getting into a debate, I would suggest that:

  • If you pay attention, you will learn a fair bit about Linux from a Gentoo install.
  • You’ll probably not learn the same things in most other Linux installs.

It is what it is; because it walks through so many things, you can’t help but learn. Is this actually what I’m recommending for people? Not necessarily, although I don’t think it’s a bad idea.

Fine, but what book should I get?

Good question. If I had to do it all over again, I would probably get Linux in a nutshell. It’s more of a reference, and if you really want to learn Linux, a reference is probably going to be the most useful.

Another suggestion is, don’t buy a book at all, at first. Find a version of Linux that appeals to you, download it and try to install it; if you run into trouble…

  1. Read Eric Raymond’s essay on asking smart questions.
  2. Find the appropriate forums or IRC chat-rooms, and ask away.

Oh, and if you simply must buy a book (I understand… I love books), for heaven’s sake buy something used on Amazon, or check out BookPool or some other online discount seller — $50 bucks for a book? Yikes.

“Open Source” vs. “Free”, and why people still don’t get it

It had to happen eventually; it seems that some people have just as hard a time wrapping their heads around what “Open Source” means as they did with “Free”.

PTP’s review of 3 linux desktops displays this misunderstanding clearly:

One of the first choices to make is whether to go with an open source version or with a commercial version of Linux. For arguments sake, and to keep costs as low as possible, let’s say an open source version is best to cut your teeth on. There are no up front costs and several to choose from.

Okay… wait a minute.

All “commercial” versions of Linux are Open Source. They have to be; that’s the whole point of the GPL. Some of them may provide a few proprietary binaries, but “Linux” is Open, whether is it’s Red Hat or Fedora, Novell or Suse, Ubuntu, Linspire or Freespire.

This quote is just using Open Source as a synonym for “free” (as is beer).

The funny thing is, the term “Open Source” was coined for the express purpose of clearing up the confusion around what “free” meant.

You may be aware that Richard Stallman and the Free Software Foundation make much of what they really mean when they say “Free Software” — the canonical explanation is that “Free Software is free as in freedom, not as in beer.” That is, you might have to pay for Free software — but you are free to do with it, or it’s source code, whatever you want.

Some people found this confusing, or at least saw the potential for confusion. Bruce Perens and Eric Raymond are usually cited as having coined and popularized the term “Open Source”. This term was supposed to clear up the confusion — it might not be “free” (as in costing-no-money), but the source was open.

The quoted passage from the above article seems to indicate that this hasn’t worked, either. Apparently, for some people “open source” has begun to mean “free” (as in costing-no-money) as well — otherwise, why contrast “open source” with commercial Linuxes?

If Debian started charging money for each download — which would not contradict the GPL in any way — it would not stop being “open source” (or “free software”, if you prefer). The status of the openness of the code would not change in the slightest.

The terms “Open Source” and “Free Software” have nothing at all to do with whether or not money is changing hands for the software.

The question is, will this perception ever change, and, should we care? So the article cited implies by the dichotomy that commercial versions of Linux are not Open Source — which is incorrect — what difference does it make? It might make a whole lot of difference to the FSF or to Eric or to Slashdot (because, hey, something to argue about again!), but does it matter to your boss? Does it matter to you?

The OSI was a valiant attempt to clear up the confusion, and all that has resulted is that some people now think that open source == free (as in costing-no-money), and therefore commercial Linux (or other software) must not be open source.

I guess we shouldn’t say it doesn’t “matter” — if I thought it didn’t matter at all, I wouldn’t be posting about it. However, you should always choose your battles — and I, for one, don’t think that the concept of “Free” or “Open Source” will enter into mainstream consciousness in the near future.

List comprehensions in Python

I love Python’s list comprehensions. There, I have admitted it.

When I first saw these, they seemed a little odd. Then I started using them in homework and on tests… to be honest, it simplified some things so much I almost felt like I was cheating.

So, what are they? I’m glad you asked.

IIRC, List comprehensions were added in Python 2.0. They are basically a shorthand for what you would have done with functions like map() or filter(). For example, if you had wanted to double every number in a list you could have done:

>>>def double(x):
… return x*2

>>>map(double, range(11))
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

With comprehensions, you can do:

>>>[x*2 for x in range(11)]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

Not a big deal; but it is a very elegant way of writing less code, and is quite readable.

You can also make it act like filter() by adding an if statement:

>>># get only the elements of a list divisible by 3
>>>list=[2, 5, 6, 12, 7, 9, 24, 32, 18, 4, 15]
>>>[x for x in list if x % 3 == 0]
[6, 12, 9, 24, 18, 15]

It’s a simple thing, but I found it very useful. Now, of course, you could write these with map() or filter() and just use a lambda:

>>>map((lamba x: x*2), range(11))
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

I like lambda a lot, but I think in this case, Python’s list comprehensions are simpler.

As a bonus, I found elsewhere that list comprehensions (currently) have an “undocumented” feature; they can be referred to within themselves. That is, say you wanted to eliminate repeated elements from a list; your list comprehension can refer to itself as ‘_[1]‘, like this:

>>>list=[1, 1, 2, 3, 3, 3, 4, 4, 5, 6, 6]
>>>[x for x in list if x not in locals()['_[1]‘]]
[1, 2, 3, 4, 5, 6]

User Interfaces of tomorrow

Here’s a great video of what would be a revolutionary new User Interface (UI). It’s a basically a large monitor with a multi-touch screen interface.

Remember the way they used computers in the film Minority Report? This is quite similar; very cool.

Via reddit.

World Class Errors

This was pretty fun; a page full of entertaining software error messages. Some of them are priceless.

EDIT: I guess it would have been better if I had included the link.

Linux/Apple/Windows desktop comparisons

Brian Glass linked to a cool post with videos showcasing the “latest & greatest” desktop interfaces for Linux, Apple, and Windows (Vista). I’d say all three are looking impressive, but for a welcome change, Xgl/Compiz for Linux is blowing them all away.

Check it out.

Free energy?

Just the phrase “Free Energy” reminds me of the “Free Money to change you life” ads/books so prevalent here in the US. That is, something doesn’t sound right.

You’ve probably heard of the alleged new technology which is supposed to use magnetic fields to, somehow, create energy. The company who developed it took out a full page ad in the economist to generate interest from scientists. Not the most conventional method of provoking research, to my knowledge.

I’m all for it, of course, if it works…. I maintain a healthy skepticism, however. They say if something sounds too good to be true, it probably is… and in general, I tend to agree.

All the same, it’s an interesting story, if only because the claim and the publicity are so outrageous. Perhaps this will become a new marketing strategy… How do we increase our visibility? I’ve got it… let’s say we’ve contradicted the laws of physics.

Yeah. That’s it.


Your Ad Here