Monday, June 15, 2009

Beeees! And Kino to the rescue.

This weekend, I put my first videos up on YouTube. Here's why.

Three Saturdays ago, May 30, Kristina and I were in King Soopers when my cell rang. It was Kristine Smock, a mandolin player from Lyons.

There's a swarm of bees in the alley behind my house. Do you want them?

We hurried home. Kristina grabbed a cardboard filing box, shoved in a frame with old comb, tossed it in the car, and we drove out to Lyons. After she'd gotten the swarm in the box, she put on the lid and duct-taped both handles shut. Once home, she put it on the deck, pulled off one piece of tape and -- presto! -- one new hive.

I'd gotten her an observation hive for Christmas, which was still unpopulated. By last Wednesday, it was set to go and she'd drilled a hole in the wall.

A flip videorecorder was waiting for me on the porch from Amazon, so its maiden voyage was taking a video of the installation.

Okay, I had it captured. My first, little, 15' home movie. Now what? It'd be nice, for example, to show it to Kristina's parents.

Can't mail it, it's half a gig. YouTube? Uh-oh. YouTube has a 10' limit. Other services? Turns out there's a reason YouTube is popular -- they're slow and hard to use.

By the next night, I could get someone at the BLUG meeting to show me enough rudimentary Kino to chop my video and post the pieces to YouTube.

The trickiest part was figuring out to download the jmpegtools package, so that Kino would export the files in a format that YouTube liked. Figuring it out required actually reading the error messages on the screen, which told me to install the jmpegtools package. Duh.

Here's the result.

And here's the first one, in embedded form:

I finally learn how to do realpath

Kevin Fenzi said I should send my shell-level realpath off to the maintainer of an appropriate package -- coreutils, maybe -- for possible inclusion.

So, I wrote unit tests, a simple Makefile and documentation: man page, README, INSTALL, stuff like that.

Kevin, wiser than I, looked and found documentation that suggested readlink -f would do the trick. And it does. I could prove it to myself because I had unit tests.

One difference in functionality, which I can live with: if the file is missing, readlink -f succeeds and reports it's in the current directory.

So, to find the path to an executable, this does the trick:
path2 () {
local _cmd=$(type -p $1)
[ -f $_cmd ] && readlink -f $_cmd
}

Tuesday, June 9, 2009

iPods and Banshee

Scott Mann posted a note to the Boulder Linux Users' Group Mailing list, asking for advice about iPods, MP3 players, and what software to use to manage them under Linux.

As you'd expect, much of the advice was hyperbolic. "Don't get an iPod. They're unuseable." Quick, someone tell Steve Jobs.

I replied with my recent experience.

A few months ago, I switched my girlfriend, Kristina, over to Linux; her old, G3, iBook was finally biting the dust. She's been completely happy with Ubuntu.

Last week, she bought an iPod Nano on eBay.

She's going to fill it with
her Dad's favorite music and give it to him.

When it arrived, she took it out of the box, turned to me, and said, "How do I put music on this?"

I took Scott Mann's advice and installed Banshee. It mostly just worked. It rips CDs to ogg by default, but I kept throwing gstreamer packages at it until it said it knew how to create mp3s, too.

To my mild surprise, it now also converts flac, ogg, wmv, and wv files to mp3s, on the fly, when I drag them onto the iPod. I found this out by accident. I mean, uh, by carefully reading all the documentation.

Still, after reviewing this thread, I started to wonder whether, instead, I should have traded Kristina in for a smarter girlfriend -- one who'd have bought an mp3 player with a much better interface and then re-flashed it with Linux or RockBox herself.

When I asked her if she thought so, too, she ignored the question.

Maybe she's smart enough.

Tuesday, June 2, 2009

What's the Absolute Path to a File?

There's no standard command that gives you the absolute path to a file. That's insane. Here's an implementation.

Yes, it resolves symlinks and works on directories, too.

I couldn't figure out how to get Blogger to stop re-formatting my code, so I passed it through this, web-based, C#-formatting tool (!), and now it seems to look okay.

Argh.

// realpath - what's the real path to a file?
// Turn relative paths into absolute paths,
// resolve '.' and '..',
// follow symlinks

#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
char path[_POSIX_PATH_MAX];

if (argc != 2) {
fprintf(stderr, "usage: %s filename\n", argv[0]);
exit(EINVAL);
}

if (!realpath(argv[1], path)) {
perror(NULL);
exit(errno);
}

printf("%s\n", path);
return(0);
}

Friday, May 29, 2009

Google Runs Rings Around M$ This Week

Google seems to be in fine form this week.
  • Wednesday, they gave away Android phones to everyone at the Google I/O conference.
  • Yesterday, they announced Google Wave.
  • Today they have up the full video of the Google Wave talk. And the product will be Open Source.
And Microsoft? Their big announcement, yesterday, was bing, a new search engine to compete with Google. Which, at this point, even if it eventually works and comes out, is soooo 20th-century. Sorry.

It'll be interesting to see how Google ties this to ads.

Thursday, May 28, 2009

Editing Parallel Trees

Sometimes, I need to work in parallel trees -- trees with the same structure, but some important difference (different revision numbers, different compiler flags, ...). When I'm deep inside one tree, getting over to the homologous place in the other can be painful. Not only is it a lot of typing, but I'm often made aware that I should work at "Typos R Us."

The string substitution syntax ${FOO/bar/mumble}, which returns $FOO, but with mumble substituted for bar, solves my problem. For example, if I'm in the tree /home/jsh/tree1/a/b/c/d, and I want to pop over to /home/jsh/tree2/a/b/c/d, I just say

$ pushd ${PWD/tree1/tree2}
or even

$ cd ${PWD/1/2}
Presto! I'm there faster than you can say, "xyzzy." Or, at least as fast.

Not only am I in the new tree, but now pushd, with no arguments, (or cd - ) takes me back and forth.

Wednesday, May 27, 2009

How to Change File Extensions

Changing file extensions is easier than people make it out to be. Even on sites that provide shell programming tips, I see recipes like this:
#!/bin/sh

for file in *.dat ;

do mv $file `echo $file | sed 's/\(.*\.\)dat/\1txt/'` ;

done
It's easier than that. Honest.
$ for file in *.dat; do mv $file ${file/.dat/.txt}; done
All in the same, parent shell. One process. No pipes, no sed, no magic regex metacharacters. So easy, you can type it on the command line.

I do it all the time.

If I need to be careful, I start like this:
      $ for file in *.dat; do echo mv $file ${file/.dat/.txt}; done
Then, if the output commands look like what I intended, I recall the loop, and tack a pipe of its output to bash on the end, like this:
      $ for file in *.dat; do echo mv $file ${file/.dat/.txt}; done | bash