Today's exercise: Try working the mouse with your feet.

<< Previous Page :: Next Page >>

Slowly Making Friends With The New Gimp

Date/Time Permalink: 11/10/07 10:52:08 am
Category: HOWTOs and Guides

What's driving me to put Gimp 2.4 on my Slackware box (my main office) is that I can never again do a Gimp tutorial until I am set up with 2.4. The interface overhaul is just too massive; every Gimp tutorial currently published in print or the web has now become worthless.

It's things like this that held me back from mastering Blender; I was just getting pretty good with it, when they rebuilt it. At least half the tutorials out there for Blender even now make references to buttons that no longer exist and menu paths that have changed. Hopefully, the Gimp community can handle itself better. For anybody who asks, I will be putting a header on each of my own Gimp tutorials specifying that they are for 2.2.

Anyway, I'm running Slackware 11.0, having just dialed in the perfect distro setup as I reviewed here. This may come as a shock, but I don't keep current on my main work station. I apply the Debian philosophy; I want long-term stability, because there is so much that is so complicated that I do, that getting it all set up takes something like a month. I was prepared to never upgrade the main system again for at least another year.

But with my work, Gimp pretty much controls at least 33% of my paycheck (no matter if I drew something in Inkscape or POVray, I still use Gimp for post-process and such.), so oh well, upgrade Gimp. The only Slackware package for Gimp 2.4 I could find was one for i486 (over at Linux packages), so that's what I settled for. Then when I got that in, Gimp informed me that it needed GTK+2-2.10.13 or later. I "arghh!"ed and went to hunt that down, but happily my upgrades ended there where 2.10.14 for i686 installed without incident.

Unfortunately, Gimp is not running without incident. I have so far detected three operations which make it crash (!?!?). They are: using the lasso (free-select) for anything, attempting to stroke a path, and using the gfig plugin. So I go back to the site and guess what? They just released the bug-fix as 2.4.1, and the change-log mentions several stability issues including crashing when using plug-ins. Which will fix my problems nicely... just as soon as I locate the Slackware package for it! Which, as I write this, I just did... Slackware current has it, but don't bother using the site search (on the left); it's on the recent packages list (on the right).

Since everybody's going to ask: I'm not looking at the tarball because I don't think my system is ready to compile a huge package like the Gimp. There's other complications like the fact that I use Dropline for Gnome support, so this has potential problems with little library and method inconsistencies that I'd rather avoid. Dropline hasn't even released for Slackware 12.0 yet.

As a side mystery, Gimp 2.4's release candidate on my kids' Mandriva box is running tip-top, no problems at all. So now are these problems actually caused by a botched set-up on my own box? In any case, I can't go hopping back and forth between two computers and nudging my kids off their game just to use a stable Gimp. While puttering around last night, I did manage to draw a decent shield in 2.4:

A Slackware shield

I've been fascinated by shields lately. I'd like to say that I drew it all in Gimp, but I did the shield shape (just the outline) in Inkscape and exported to PNG because - duh! - Gimp's path tool crashes when I try to stroke a path. If my images look pretty busy going forward for this month, it's because I'm doing them as in-depth feature tests.

The 2.4.1 upgrade should fix things up, and my computing world will be at peace again. I just cough all this up to let people know, if anybody else out there is having these little frustrations, it's not just them.

Update: No, they didn't. Lasso, stroking a path, and gfig drawing a polygon all still make Gimp 2.4.1 vanish like a popped soap bubble. I have no idea what the problem is.

Why was I born?

Update: Well, I tried one thing and then another, but finally uninstalled Gimp, manually removed every trace of Gimp from the machine, and reinstalled the original Gimp-2.2.13 from my Slackware 11.0 diskset, plus untarred the .gimp/ configurations back to my home directory (which I'd thought to tar up and save before trying to upgrade). Happy ending: everything's back as it was.

I could piddle around all year with this, but like I said I need this for work. I have 2.4 running happy and fine on the other machine (why???) if I need it, and I'm sticking with 2.2.13 on this box until the next major upgrade. I have GTK+ upgraded as a souvenir.

I'll try again to make friends with the new Gimp when it's settled down.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

My 'lil' FreeBSD Notebook

Date/Time Permalink: 10/06/07 01:04:59 pm
Category: HOWTOs and Guides

New to BSD from Linux? Welcome to the outback! BSD is going to feel like a TV commercial that goes: "We've secretly replaced this geek's Linux with BSD - let's see how long it takes to notice!" Herein is a random little list of notes I'm leaving along the way, as I venture into the depths of BSD:

NOTE: BEFORE YOU COMMENT The computer I installed FreeBSD to is OFFLINE. It has no Internet connection. For very, very good reasons. If you leave me a comment on this post to the effect of me being an idiot who doesn't connect to the site and use ports, I WILL make fun of you! Don't let me do that.

My 'lil' FreeBSD Notebook

Console tip: The mouse in BSD is an actual mouse pointer graphic, and you can use it to snarf and paste text. Just click and drag over the text you want to copy, which will store it in the "clipboard". Then middle-click to paste it elsewhere. Exactly like in Linux (given the right setup).

You've gotten your desktop up and hit Ctrl-Alt-F2 to get to a console. Which key do you hit to get back to the desktop? Alt-F9. This is because you get 8 tty's in BSD, as opposed to 6 in Linux.

How do you get a Bash shell? First, "cat /etc/shells" to make sure you have Bash installed. It will probably be /usr/local/bin/bash. The command to change shells is "chsh -s /usr/local/bin/bash".

GNU users: Your (and mine) precious Emacs (M-x praise-be-unto-emacs) is available in the individual package section on the disks and will work fine on FreeBSD. Once you have Bash going, set Emacs as your editor with "export EDITOR='/usr/local/bin/emacs'" and $EDITOR will be used properly.

By the way, I'm not out to discourage anybody from discovering the wonders of more BSD-like shells and editors. While a Linux user is learning BSD, it's better to have Bash and one of vi/Emacs nearby while they explore. But FreeBSD has ee (an editor), and I tried it out and it will take you only seconds to learn, since every command is printed right at the top! And sh is a shell, itself in BSD, not a softlink to another shell!

Where the heck can you get binary packages? From the ports packages collection. The command to install is "pkg_add".

I was practicing installing packages (since the BSD box has no Internet) via floppy (retarded, I know) and picked 'freebsd-games.tgz'. That installed fine, but then I tried to start Rogue and it complained about a missing library ( First, I went looking for the package on the install CDs, but didn't find it. Then I checked /usr/lib, and there's So, I go root, cd /usr/lib, and made a link: "ln -s". Did the same for " -$gt;". Rogue ran. § Oh look, look. See Rogue run. Run, Rogue, run!

Floppy disks: I'm puzzled, because the ext2 floppy that I copied a file to in Slackware seemed to be fine, but gave FreeBSD heartburn - it complained of bad superblocks and wouldn't mount. I remounted it on Slackware - no problem. Either BSD is too picky or Slackware is slacking. A different ext2 floppy worked fine, as did a DOS floppy. Perhaps BSD is not as sloppy about file system integrity as Linux?

Mounting: If you have a shell with TAB-completion, try typing "mount" and then hitting TAB twice. Wheeee, look at all the programs! BSD seems to prefer keeping binary programs specialized to mount each file system. To mount an ext2 floppy it's "mount_ext2fs /dev/fd0 /mnt". For a DOS floppy it's "mount_msdosfs /dev/fd0 /mnt". And so on...

Docs: Besides man pages, the system documentation is in /usr/share/doc/, and it comes in two flavors: articles and books. You practically have a mini-Wikipedia in here. They are divided into folders by language. The majority of them are in HTML format, so you'll want to install a web browser first. Observation: lynx looks better in BSD than it does in Linux. Observation #2: Look for /new_users/index.html in the /articles/ directory here for a great, brief tutorial on day-to-day usage; this is easy to understand even if you're new to Unix systems in general. Observation #3: The 'BSD Funnies' is waiting for you, in the FAQ book, and it's funnier than anything in /usr/share/emacs/etc/.

Q: In Linux, you can scroll back through a few pages of console history with "shift-PgUp". How do you do this in FreeBSD? A: Hit the "Scroll-Lock" key and then use the arrows to scroll up and down much as you would in vi. This is actually a lot cooler than in Linux, because buffers viewed in 'man', 'emacs', and 'lynx' will all show up, along with past command output. This makes it much easier to gather facts from several documents together, for pasting quotes into one file, for instance.


         _~             ~_
        /                 \
       ~                   ~
      /                     \
      |    XXXX     XXXX    |
      |    XXXX     XXXX    |
      |    XXX       XXX    |
       \         @         /
        --\     @@@     /--
         | |    @@@    | |
         | |           | |
         | vvVvvvvvvvVvv |
         |  ^^^^^^^^^^^  |
          \_           _/
           Penguin Pete
  Killed by a mob of FreeBSD zealots
           with 14 gold

UPDATE: Oh, and I just found the "gotchas" for Linux users at the FreeBSD Wiki.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Obscure Linux Commands: Cheating At Word Games

Date/Time Permalink: 09/24/07 07:25:30 pm
Category: HOWTOs and Guides

Now, granted, cheating at word games won't make you very good at the word games. However, using practical problems from word games is an excellent opportunity to brush up on your Command-Line-Foo! There is no better exercise to master regexps.

One thing you've probably found is that 99% of Linux distros have a file in /usr/share/dict/ which is called "words". True to Unix traditions, it's nothing but a plain text file of words, one per line, which is what the system uses for spell-checking.

So, you're bumbling along doing a crossword puzzle, and you need to find a seven-letter word that begins with 'm', ends in 's', and has a 't' in the middle. Go get it, grep!

ß grep "^m..t..s$" /usr/share/dict/words

Blow by blow:

  • ^ - The carat (shift-6) says "this is the beginning of the line". Without it, it would find all words like "fundamentals".
  • $ - The dollar sign is the same thing, only for the end of the line. Without it, you'd also get words like "mattresses".
  • . - The period means "any character here". One, and one only, character will match here.

But suppose you're dealing with a game besides a crossword puzzle, like Scrabble for instance, and you're limited by more constraints than in a crossword. You might want to 'hook' (Scrabble lingo for 'add letters to the beginning or end of a word to form more words'). So, let's see how many words end in "are".

ß grep "are$" /usr/share/dict/words | wc -l

Well, those are good odds. But we hit the edge of the board with some of them (I peeked). So, we need words that are seven letters or less which end in "are". "^....are$" would get all of the seven letter words, but not the shorter ones. The solution is rather cryptic this time:

ß grep "^.\{1,4\}are$" /usr/share/dict/words

...but we've met the caret, dollar sign, and period before, so really the new part is the \{1,4\}. This says "match as few as one, and as many as four, repetitions of the previous character". The activator for the number range is the curly braces, which then have to be escaped with slashes (does anybody know why, class?). And since the previous character is a period, which matches any letter, we've found all the words shorter than eight letters which end in "are".

This is all well and good, but we only have so many letters to work with in Scrabble at one time. Say that our current rack has the letters "C F T W A B M". Can we limit it to only words which use those letters?

ß grep "^[cftwabm]\{1,4\}are$" /usr/share/dict/words

Ah, now we're getting somewhere! The [] square brackets give the set of acceptable characters. Another way to use them is to express a range (e. g. [0-9]), but that's hardly the usual case in word games.

Here's another kind of word game you can play online. It's called simply "Crossword", but it's not at all like a regular crossword. Instead, you have to fill letters into a partially-completed grid, using only the letter provided. If you have a four letter space with "_w_y" and the 'A' available, you click on one of the empty slots which will then light up every space on the board that uses the same letter, click on A, and it will put the letter A everywhere in the puzzle that's marked for the same letter. And so on to complete the puzzle.

I introduce this fun little diversion because it brings up still other kinds of problems to solve. As you progress to higher levels in this game, you eventually come to a problem like "All I know about this word is that it has seven letters and the first, fourth, and fifth letters are the same. What is it?" I'll bet even the regexp gurus are scratching their heads at this point....

I'll give you a minute if you want to solve it yourself.

Hint: you ain't gonna do it with regexps alone this time.

OK, here's the spoiler:

ß grep "^.......$" /usr/share/dict/words | \
> awk '{$W==$1; FS=""; if ($1==$4 && $4==$5) print $W;}'

That's right, we had to use some real programming. Any Perl Ninjas out there have a solution in fewer keystrokes, you're welcome to post it. I know you're dying to.

What we did is simply grep for all the seven-letter words. Then the awk part (a) first grabs the whole word as "$1" and sticks it into the variable $W for 'word', (b) declares field-separator (the built-in FS variable) as null so it treats each character as a field, then (c) recycles $1, along with $4 and $5, as individual letters within the word, (the first, fourth, and fifth). So the last awk statement tests the equality of those three letters, and only prints the word (still safe in $W) if the match test passes.

Last, here's a bonus program: an. If you don't have an (it's rare to find it included in a base system) you can pick it up here in the Debian archive. If you have a non-Debian system, look for the source tarball in the right-hand column of that page. It compiled on my Slackware in nothing flat.

When installed, an takes your quoted string and returns all the possible anagrams for that string.

ß an "Richard Stallman"
marshal card lint
marshal clan dirt
thrills card an am
thrills cram ad an
thrills can drama
... and etc.

And it will only return dictionary words! It's pretty fast, too. Just the thing for finding "bingos" in Scrabble, as well as basis for nutty conspiracy theories.

I found it amusing that Richard Stallman's name breaks down to "chill drama rants", amongst others... the first hit for "George Bush" is "buggers hoe" and another one is "here go bugs". Endless hilarity potential.

sign guy sig

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Arcane Linux Commands: dc

Date/Time Permalink: 09/20/07 02:34:48 pm
Category: HOWTOs and Guides

If anybody within earshot of you is struggling to learn sed and ever remarks "This is like learning Klingon! Could they make it any more cryptic?", you can always point them to dc.

dc is the command-line Unix "Reverse-Polish Notation"(RPN) calculator. The name stands for "desktop calculator". OK, so what is a Polish calculator and why would you want to reverse one? The math that you do in school uses infix notation, with the operator between the numbers (3 + 5). Prefix notation puts the operator first (+ 3 5) and is what the Lisp language uses. The prefix notation is known as "Polish notation" after the nationality of Jan Łukasiewicz who invented it. Postfix notation, then, has the operator at the rear (3 5 +), and so is also the reverse of Polish notation.

What's the difference? In computer programming, you have to specify what order you want a multi-part calculation to be in. Everybody is familiar with the old problem of A*B-C. For A=5, B=3, C=2, multiplying first and subtracting second gives you 13, while subtracting first and multiplying second gives you 5. To specify which operations you want performed first, you have to either memorize the complex orders of operations (which change from one language to the next) or use a lot of parenthesis ((A*B)-C) or (A*(B-C)). Hey, that's what everybody complains about in all those languages that use parenthesis!

In dc, we eliminate the problem this way:

dc -e '5 3 * 2 - p' 13, and

dc -e '5 3 2 - * p' 5. What's going on here is that it uses a "push-n-pop" stack, a data-storage system familiar to programmers of Assembly and Lisp. When you enter a number, it gets pushed onto the stack. When you enter an operator or a command, it pops the latest affected numbers off the stack, performs the operation, and pushes the answer back onto the stack. The commands (which are all single-letter) have various other effects.

Reading through "info dc" on the command line will give you the commands of dc, but will do little to help you grasp the unfamiliar concepts if you aren't used to using an RPN calculator. So consider this post to be the supplemental reading to the dc info section (or the dc man page).

Let's look at one of the reasons to use dc as opposed to the Bash echo command or Python: you can set the floating-point precision easily. The command to do that is "k" (first thing you thought of, right? It stands for krecision!) and it takes the most-recently-pushed number as an argument. So you can say "2 k" to set the precision to two decimal places for dollars-and-cents operations. While we're at it, let's introduce the "v" command, which computes a square root. This makes sense if you've seen it in ASCII art:

v 2

So, the dc way to get the square root of two to ten decimal places is:

ß dc -e '10k2vp'

which gives back 1.4142135623 and returns you to a prompt, lickety-split. We could also make it less confusing by using spaces:

ß dc -e '10 k 2 v p'

That's "10... set this as the precision... 2... calculate this number's square root... print the result".

The only time you need to use spaces is to separate two numbers (so 10 and 30 don't become 'one-thousand-and-thirty'). For that matter, you can also run dc interactively. The "-e" thingie says to evaluate the expression (and exit immediately). But check out this session:

ß dc

...the "q" is the command to quit. Since you can also omit spaces in interactive mode, we could also go:

ß dc

Story problem: Johnny is taking a contract to write 20 articles @ 600 words each, for which he intends to charge 2¢ per word. How much money will the client pay?

ß dc -e '2k20 600*0.02*p'

And we're going to add one more command: "f" dumps the whole dang tootin' main stack to the screen, instead of just printing the first value.

dc also has a memory feature. You can call the memory 'R' (register?) and this is of course another stack. So you can store a value for later use. Pop a value off of the main stack and push it onto the R stack with "sR" and pop the value back off the 'R' stack and push it back onto the main stack with "LR". To copy the value off the register stack (as opposed to moving it) you say "lR". By the way, registers can have ANY single-letter name you want! But they have to be initialized first before they are used (with a command like "sR"). Puzzled frowns? Here, my pupils:

ß dc
dc: register 'Q' (0121) is empty

Let's experiment with the previous calculation, using this new knowledge:

ß dc
2k20 600*0.02*sRlR
lR 0.15*f

What we did: the previous word-count problem, pushed it to Register, copied it back, printed the stack to show where we are, multiplied the Register times 15% and pushed it onto the stack and showed the stack again, then subtracted the second value from the first value and showed the stack again.

Story problem #2: Johnny is taking a contract to write 20 articles @ 600 words each, for which he intends to charge 2¢ per word. Johnny's agent charges 15% commission for finding him these jobs. What is Johnny's take-home before taxes?

ß dc -e '2k20 600*0.02*sRlRlR0.15*-p'

Feel free to indulge in some primal scream therapy, not only at Johnny's ridiculously low income, but at the fantastically terse command he used to figure it. The other beauty of dc is that it is a relatively powerful calculator (supporting +*-/ (standard four functions) % (modulus) ~ (division and remainder) ^ (exponent) | (modular exponent) and v (square root)) which can be included in a script or command line. It can also do base-conversions on-the-fly with the "i" (input radix) and "o" (output radix) commands.

So, 256 in hexadecimal is:

ß dc -e '16o256p'

While hex FFFF in decimal is:

ß dc -e '16iFFFFp'

So, it has many uses in scripting.

Hope you got something out of this little tutorial, and now for some links:

Wikipedia dc page
dc man page online, hosted by "Bash Cures Cancer".
Advanced Bash Scripting Guide (aka "the Bible") uses dc in a couple of script examples about half-way down. Also shows some of bc, dc's friendly companion.
Everything2's node on dc It gets around to the Unix command at the middle-to-bottom. Notable for having FizzBuzz in dc (horrors!!!)

tattoo sig

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Writers-Block Busters for Bloggers

Date/Time Permalink: 08/25/07 12:09:17 pm
Category: HOWTOs and Guides

Eh, it isn't really a geek HOWTO, but a lot of geeks blog, too. And the formatting's funny because I wrote it in Emacs with hard line breaks. Because sometimes I just like to.

If I had a nickel for every time I've read one of those "top ten ways
to beat writer's block" articles, I'd have a cheap, trite
metaphor. Well, here's my own list for finding the start button on the
writing machine in your head, and even how to oil it up occasionally.

1> The - THE! - most important thing I can tell you about writing
is this: If the text is not fun to write, it will not be fun to read.

I can apply this test to a piece of writing and tell instantly whether
the author was a burned-out zombie shuddering with every line they
typed, or whether they were chuckling and gibbering as they zipped
along composing their brilliantly inspired piece. Use this to help
yourself: make writing as fun as you can, always.

For everyone, point number one needs to be amplified. Don't get angry
at what I'm about to say; it's just words on a page. But this is
iron-clad truth, and you can either accept it or leave because I'm
wasting your time. The iron-clad truth extending from point #1 is:


There's almost nothing you can do about that.

2> Store nuts for the winter - Whenever any silly idea is popping
into your head, jot it down. Save a big old folder of pieces you
started when anything interested occurs to you. You should never ask,
"What will I do with this?" You should just jot down that idea, plan,
rant, joke, funny phrase, or cool new word you've just learned, and
then afterward ask, "How can I use this?" Turn your inspiration to the
task, instead of starting with the task and trying to find inspiration
from there.

3> Vary your hangouts like a cat. - Every now and then, try to
write using a different program, different computer, a notebook in a
cafe, a cocktail napkin in a smoky bar, a change of office, a
different chair, anything. Monotony breeds boredom. Especially writers
tend to suffer from the "same four walls" syndrome, because left to
their own devices a writer will live like a potted plant.

4> Use our feet to wind up your brain. - It's a cliche that people
get their best ideas in the shower. But try this: try pretending you
are a street mime and, clothed and dry, pretend to take a shower while
not in the shower. What did you do? You stood up and moved around, and
stayed on your feet for a few minutes! That's actually what's going on
in the shower. That and it's also private, so there's fewer

Taking a walk always does it for me. Driving doesn't count. Evolution
has wired it into us since the wide savanna to stay on the move. Our
brains really do work better when our bodies are in motion. Either get
out and trot to the store, visit your back yard, or just roam around
the house and let your feet and mind wander.

5> Put your brain on time-out. - The Buddhists say "The mind is a
monkey"; have you thought that maybe the reason why your mind is
blocked is because you've indulged it into being an inattentive slug?
So sometimes, force a time-out period, deliberately not
thinking. Meditation is fine if you know how, but it's not
necessary. Do housework, run some errands, or other trivial
activity. Deliberately watching something mindless on television also
works. But set a time limit, and come back in an hour. Now is your
mind ready to work on the task?

6> Get inspiration from the funniest thing you can find. - In
addition to the usual advice to read better authors for inspiration, I
find that it is especially invigorating to read or watch something
funny. Not just mildly amusing, but screaming funny. Laughter makes a
chemical reaction in your brain. It will get you going.

7> When all else fails, write about your block! - In rare cases,
you might be blocked because the subject or assignment just isn't any
fun. So start out writing a paragraph identifying with the reader
about why it is such a hard subject to tackle. Ridicule the
subject. Criticize the previous literature on the subject. Scold
yourself for not being able to find a handle on it. This is a sneaky
sideways approach, but it will eventually lead into a hook where you
at last do what you were supposed to do, which is write about the

8> Write about something else entirely. - project be damned,
sometimes you want to write about what is interesting to you. So get
it out of your system. Completely turn off all thinking about the
project at hand - the writing you have to do - and indulge in the
writing you want to do. You might be able to lead this back to the
task. Maybe work it into the project, continue an idea from your
desert article back into your main course article, draw on the
activity period for inspiration, or just get back into the zone. Like
#7, this idea sometimes works in rare situations.
Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

HOWTO create keyboard macros in Emacs

Date/Time Permalink: 04/29/07 12:04:04 pm
Category: HOWTOs and Guides

You hear about the great macro feature of Emacs all the time. You see cheat sheets for Emacs key combinations all the time. But you never quite see the keyboard macro trick demonstrated clearly. Here's how it works:

You begin with "C-x (" - that's Control+X, then shift-9. The message buffer will say "Defining kbd macro..." Then you type in whatever series of keystrokes you will want to call with one keystroke. When you're done with the series, hit "C-x )" (open and close parenthesis, just like Lisp, get it?) and the message buffer will now say "Keyboard macro defined". Now you can call the macro at any time with "C-x e" and it will execute just like you typed it all in from scratch!

A real-world (set-up!) example:

Ugh! My lousy HTML editor formatted my code listing example wrong! I want to get rid of the paragraph tags so I can just wrap the code in "pre" tags instead. I have a bunch of places where this happens in the file, and I'm looking to spend all day deleting "<p>" and "</p>" tags:

   <p>;; Factorial function</p>
   <p>(defun factorial (n)</p>
   <p>(if (<= n 1) 1</p>
   <p>(* n (factorial (- n 1)))))</p>

First (I'm working in XEmacs), I hold down shift+arrow keys to highlight the block I want to affect. Now before I type my key sequence, I just throw in a "C-x (".

My key sequence will be:

  • M-x replace-regexp
  • </?p>
  • :return: x2 (I want them replaced with "nothing"!)

This will strip both "<p>" and "</p>" tags from the block:

   ;; Factorial function
   (defun factorial (n)
   (if (<= n 1) 1
   (* n (factorial (- n 1)))))

Happy ending, but don't forget to type "C-x )" now to end the macro! Now I can go to all the other code blocks and highlight them, hit "C-x e", and the bad tags vanish.

vi users, I'm sure you have a way to do this too, but the sed sequence escapes me...

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

HOWTO Play With Your Old QBasic Programs on Linux

Date/Time Permalink: 03/31/07 01:21:43 pm
Category: HOWTOs and Guides

Most any geek who was a kid in the 80's played with BASIC at some point. And the BASIC language with one of the biggest followings is Microsoft QBasic - Microsoft's sole nod to the hobbyist programmer community. Dozens of online sites exist today that are devoted to QBasic, Quick Basic, and Basica, existing in much the same spheres as the surviving BBS/ ANSI art culture. If you still have some old floppies with archives of BASIC programs from your juvenile years which you'd like to revisit, here's how to do it on a Linux box:

Step 1: Get a copy of DOSbox. DOSbox is a no-brainer to install and set up, with its main dependency being the SDL library. Once you have that in, I recommend creating a directory named /DOS/ under your home directory - note that this is a plain old ext2 (or whatever you have set up) file system directory, you don't need to create a special FAT or DOS partition. Thereafter, starting your simulated DOS environment will involve starting DOSbox, typing "mount c ~/DOS/", then typing "c:", and you can then type "dir" to see that you're in your simulated "C:\" drive. Wasn't that easy?

Step 2: Find a QBasic version to download! Here's one. This is tricky - these sites come and go, and Microsoft, which hasn't supported QBasic for centuries, plays peek-a-boo with these DOS legacy program downloads all the time - it's a 50/50 break whether you can get the Microsoft site or an MS Windows system to admit that QBasic ever existed. Rumors abound of hidden folders on install disks. The last version goes by the string "QB45.ZIP" and when you've hunted it down, unzip it to a folder in your /DOS/ directory.

Next you have to format two floppies as DOS and write the disk packages to each. After that, mount the disks in the usual way in Linux, then 'mount' them in DOSbox with "mount a" and your floppy directory, then mount your "C:\" drive, cd to the A:\ directory and run "SETUP.EXE". Follow directions from there. NOTE: As Max Atkin points out in the comments, you can also have the disk images in your directory path and mount them that way without physical floppies.

Step 3: I didn't even bother with installing the second disk, since I'm not interested in making any more binary .EXE files, and the second disk is mainly support for the compiler. QB.EXE runs just fine with the install from disk one, and will be able to read your .BAS files. You can try out the demo BASIC programs included in the "EXAMPLES" directory. Everything works just like you remember, with your embarrassing old graphics demos and munchkin hax running in glorious 640x480 16 mode.

QB screenshot 1
A Mandelbrot demo from the example programs.

QB screenshot 2
One of my graphic demos.

UPDATE: Years after I posted this, I got into Flash toys, and this same idea is now implemented as "circlerama" in the sidebar to right right of this page.

QB screenshot 3
A hilarious drawing program I did, because I missed the old Apple MacDraw drawing mirrors feature so much.

UPDATE: Likewise, the same story goes for the Flash toy "drawdemon", also in the sidebar.

QB screenshot 4
The splash screen to an old tank shooter game I did. You aren't missing a thing by not playing it, believe me!

QB screenshot 5
Who didn't do a hangman game in their learning days?

QB screenshot 6
A draw poker demo game I did. Yes, I drew each card in my own invented bitmap format, saved as plain data files, because QBasic back then didn't have a way to display bitmaps that I was aware of.

Step 4: Thank your lucky stars that you've come a long way since these days!

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Five X Windows Background Hacks You Probably Didn't Know

Date/Time Permalink: 02/10/07 02:05:30 am
Category: HOWTOs and Guides

Every now and then I stumble upon a nifty little desktop background hack, and after noting them down for a few months, discovered I had enough to make a blog post.

All of these will be variably available here and there on POSIX Unix-like systems. But some distros may not include any of them! The solid color declarations come from a file most X windows setups should have, rgb.txt, which should be in /usr/X11R6/lib/X11/. Have a cat through it to see what declared colors you can use.

To start with the easiest. This is part of the Fluxbox system, and is mostly an interpretation of xsetroot. This program adds the gradient function.

background image screenshot

fbsetroot -solid gray40

Will set a neutral shade of solid gray.

background image screenshot

fbsetroot -mod 12 12 -bg black -fg green4

This will make a tight boxed pattern of black and green.

background image screenshot

fbsetroot -gradient pipecross -from black -to blue

This is an example of the gradient. If fbsetroot is on your system, then "man fbsetroot" will show all the gradient arguments.

This is part of the "xv" program, the really funky old shareware graphics program by John Bradley, last heard from in 1994. It's still hanging around on some Linux systems.

background image screenshot

bggen 0 0 0 255 255 255 | xv -root -quit -

A simple gradient.

background image screenshot

bggen black darkred black -h 128 -w 128 -r 45 | xv -root -quit -

A wild gradient square pattern.

background image screenshot

bggen black gray -r 45 -g 64x64 | xv -root -quit -rmode 3 -

A diamond pattern.

background image screenshot

bggen black red yellow green blue purple black | xv -root -quit -

A full-spectrum rainbow!

Image Magick is a full suite of programs all by itself. Practically guaranteed to be on most distros. There is enough to it to fill a manual on its own, but here is one example:

background image screenshot

convert -size 230x100 xc:black -fill white -pointsize 72 \
-draw "text 25,75 'Linux'" -shade 120x45 im_text.png \
&& display -window root im_text.png

This will create a simple Linux logo and tile it, with a file saved as "im_text.png" in the current directory.

An animated desktop! This is the fractal-generating program. It's a toss-up whether you have it or not.

background image screenshot

xaos -root -loadexample -autopilot

Will load a random xaos configuration file from /usr/local/share/XaoS/examples/, then zoom and pan around in it on autopilot. All desktop functions work normally, just with a moving background! Of course, if you pick up the xaos mini-language, you can create whole demos this way.

More animated desktops! Still hanging around on most systems, this is the simpler precursor to xscreensaver. It also sometimes goes by the name of "xlockmore". There is a multitude of screen hacks that come with it, see "man xlock" for more.

background image screenshot

xlock -nolock -mode matrix -inroot

The Matrix!

background image screenshot

xlock -nolock -mode deco -count 10 -inroot

Hideous rectangles.

background image screenshot

xlock -nolock -mode clock -inroot

An animated, analog clock.

background image screenshot

xlock -nolock -mode tetris -size 40 -inroot

The desktop plays Tetris with itself, and loses a lot.

Lacking that, xscreensaver itself can be run in the root window. Just go to a console and do a "ls /usr/libexec/xscreensaver/" and there are all the screen hacks! Run any one in your root with the -root parameter.

background image screenshot

/usr/libexec/xscreensaver/kumppa -root

will run 'kumppa' in your background until you kill it with Ctrl-C.

Silly Warning

UPDATE: GeekHacks also tells you how to set a specific example of the GLMatrix screensaver, and have it launch automatically when you log in.

UPDATE 9/14/07: Well, now that it's all over StumbleUpon, I'll add screenshots!

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

HOWTO fix filenames on Linux

Date/Time Permalink: 02/01/07 01:00:44 pm
Category: HOWTOs and Guides

A while back, I posted the Bash for-loop one-liner for batch file operations from the command line. Handy though it is, it has limited applications.

I work online, and have to share a lot of files back and forth with clients. A problem that comes up frequently is when a Windows user sends me a glob of files which have spaces in the file names, along with the standard ALL-UPPERCASE characters and ridiculous punctuation characters. It's the Microsoft file system's way of mangling file sharing for everybody just like their web browser mangles web pages. One-liner loops don't always solve the problem cleanly.

But no sweat; here's the Bash script I cobbled up to safely replace spaces with underscores in whatever directory the ugly things pop up:


ls > /tmp/list
# we have to make the list file in a separate 
# directory so that it doesn't get included 
# in the list of the current directory!
mv /tmp/list ./list
cat list | tr ' ' '_' > listnew
# this turns spaces into underscores
FILE_COUNT=$(wc -l list | awk '{print $1}')
while [ "$LOOP" -le "$FILE_COUNT" ]
# the command to feed awk
# output will be 'FNR==1', 'FNR==2', ..
  OLDFILE=$(awk $AWKFEED list)
  NEWFILE=$(awk $AWKFEED listnew)
# keep the quotes to make the shell read file 
# names with spaces as one file

rm list
rm listnew

exit 0

Quite a messy problem, and to my knowledge there is no one-line fix. (Well, you *could* do it in one line, but ugh!)

Calling your attention to a few highlights: the line calling "tr ' ' '_'" swaps spaces for underscores. You can change this with any other annoying characters you get (like bangs (!)) and the preferred character, or make multiple calls to tr in the same line. For that matter, the one-liner fix examples I gave earlier would knock out most cases of UPPERCASE names and other annoyances. This is just the most optimal solution I could come up with for spaces.

Having thus rendered the barbaric output of lesser systems into something more well-behaved, we may then go on with life in our civilized file environment. *sniff*

animated neon sign image

NOTE: If you're wondering why we Linux types get into such a snit over spaces, see why spaces in pathnames are a dumb idea.

Another update note: Not everybody cares what their file names look like. It is more of an aesthetic issue. Which filename is easier to read, "%233NEW%20YORK%21.jpg" or "New_York_3.jpg"? This also bothers command-line cavemen like me more than desktop-only users. For one thing, a standard file naming system makes it easier to automate file management tasks with scripts!

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

<< Previous Page :: Next Page >>
suddenly the moon