Page 20 of 28
CHM to PDF conversion
Have some CHMs that you’d rather browse as PDFs? Easy. To convert, you’ll need libchm-bin
and htmldoc
on Ubuntu, probably the same on Debian and similar on others. Then, do the following:
$ extract_chmLib foo.chm foo/
$ htmldoc --webpage -f foo.pdf foo/*.html
Done.
Malfunction Junction
Wikipedia has an amazingly large and varied database of information, including numerous lists, such as a list of ridiculous highway intersections. There are some really screwed up intersections shown on that page most notably I-40 meeting I-295 in Knoxville, I-96 with highway 39 in Detroit, and the local-to-me Springfield Mixing Bowl. None of these intersections, however, can shake a stick at Swindon’s Magic Roundabout which is a single large central roundabout with 5 feeder roundabouts.
Using Gmail as an information store
This guy has a very good tip on how to use Gmail to store arbitrary information. I’m sure everyone has at sometime used some web-based email as a method of either moving data or otherwise storing something, by simply sending a message to yourself. Well, he goes a step further and setup a way to automatically take emails sent to a specific sub address (yourname+something@gmail.com
) and archive them away. Simply setup a filter to take anything sent to yourname+database@gmail.com
, apply the label ‘database’ and archive it. When you come across something interesting on the internets, simply email it to yourname+database@gmail.com
and it will skip your inbox but be held forevermore in Gmail’s coffers. To recall it later, just run a search for label:database keywords
and google will search through your database.
Rubel goes a step further, using Google Toolbar’s 'send to Gmail’ function which takes the page you’re currently looking at and pipes it to an email. Just toss in your database address and send it to be stored.
Pandora Internet Radio
Pandora is an internet radio service that also recommends new music, based upon what you tell it you like. You simple give it some artists that you like and it will start playing songs by those artists, as well as artists that Pandora thinks are similar. By giving each played track a thumbs-up or thumbs-down vote, Pandora learns what you like and tailors the ‘stations’ that you make to your taste, all the while showing you new music similar to what you have given a thumbs-up. Check it out.
Using sed
Many people don’t have a clue how to use old-school Unix commands such as sed
and I can say that I was in that camp until recently. Previously, I would be more inclined to write a script in Perl or open up vi to perform complex and repetitive replacement tasks across multiple files. I’m comfortable with both Perl and vi, most importantly their regular expressions which allow for quick and easy manipulation of text. I was pushed to learn sed
when I had a number of different files that all needed a very similar modification to each of their thousands of lines. Sure I could write a Perl script to do it, but it was a good opportunity to learn the stream editor and I’m glad I did.
The most useful thing sed
can do is regex-based alterations to files just like vi, except you can apply a sed
command to multiple files from the command line with a simple glob. The syntax for sed
regex is much like that for vi
or Perl; the big difference that I encountered as compared to Perl is that capturing with parenthesis is done using backslash-escaped parenthesis and the later references with backslash-escaped numbers. If you run sed
without any options, it takes a regex and any number of input files; the output will be to standard out, so sed 's/foo/bar/' *.txt
will replace ‘foo’ with 'bar’ in all text files in the current directory, showing you the results on STDOUT
. This is great to test and make sure the right changes are going to be made, but to actually make the changes, the best method is to use sed
’s in-place editing option, -i
. Now, if you run sed -i 's/foo/bar/' *.txt
, sed
will replace 'foo’ with 'bar’ in all files in the current directory, altering each of the files.
perl -MO=Lint
It is generally accepted that when developing Perl, you should be using warnings (use warnings
) and recommended that you go a step further with use strict
, which forces the declaration of variables with my
before they are used, among other things. Beyond these two, however, is the B::Lint
module that performs further checks on your code. Using it couldn’t be simpler; simply pass the option -MO=Lint,all
to the Perl command when invoking your program. The -M
option tells Perl that you want to use the module specified, and ’,all
’ is an option passed to the Lint module, telling it to perform all checks, which is probably what you want. If you have some bad habit, or want it to specifically skip some checks, you can add that on to the argument list, prepending the option listed in the documentation with ‘no-’.
Better uses for your Sunday mornings
Many people spend their Sunday mornings going to church for an hour or two, which I argue is a waste of time. I don’t expect to convince anyone to give up religion altogether by saying this, but that’s really beside the point; church is a waste of time, even for the religious. From a theological perspective, God wants you to respect him and obey the tenets of your religion, but most of all, religion is supposed to help you have a good life. Now, I’m sure some people do get a lot out of hearing a sermon once a week, or meeting with like-minded people, but undoubtedly many simple see it as a necessary chore to maintaining their faith. My alternative is simple: exercise.
From the perspective of the CDC, AMA or any number of other health-minded organizations, the vast majority of Americans are significantly overweight and get much less exercise then they ought to. Quite simply, spending an hour or two every Sunday exercising would greatly improve this situation and is significantly beneficial from a psychological standpoint as well. On the surface, it would seem that a religious sermon would be more beneficial for mental well being than physical exercise. Studies show, however, that the mental benefits resulting from exercise are as profound as the physiological ones. Exercise improves mood, alertness and overall affect for days afterward. A good sermon can change ones life, or improve mood as well, but most sermons aren’t that inspiring, and hearing someone talk does a lot less for preventing a heart attack than regular exercise.
Motorola Razr Shortcuts and Bluetooth
I recently got a bluetooth headset to use with my Motorola Razr and it works wonderfully, with the one drawback that having bluetooth enabled on the phone all the time reduces its battery life from 5-6 days standby, to 3-4. I thought that turning bluetooth on and off was a pain, requiring navigating 6 menus deep to do so, until I saw the option for shortcuts in another configuration menu. Shortcuts are easy to setup and make doing anything, including enabling or disabling bluetooth, a snap.
To setup a shortcut, you simply navigat to the menu option you want as a shortcut, in this case Settings > Connection > Bluetooth Link > Setup > Power. Then, highlight ‘on’ and hold down the menu key (top middle button) until a popup asks you if you want to assign a shortcut. Say yes, and then assign it the key '1’, the default. Do the same for 'off’ in the bluetooth power menu, assigning it the key '2’. Now, you can simply press the menu button and then 1 or 2 to turn bluetooth on or off. Shortcuts can be altered from the Settings > Tools > Shortcuts menu. I’m very happy that Motorola included the shortcuts feature, in particular because the Razr’s interface is so blindingly slow.
Senator Blackburn on The War in Iraq
Representative Marsha Blackburn (R, TN) made the most blatant invocation of patriotism as a scare tactic that I’ve ever heard in the debate over the non-binding resolution to condemn President Bush’s troop surge.
Rep. Blackburn: I think the question we have to ask is who’s side are you on? Who’s side are you on? Are you on the side of freedom? Are you on the side of allowing the terrorists to get an upper hand?
Wow, could you be more of a fear monger? Remember, if you don’t support a war in which thousands of American soldiers have died, countless more (really, find the statistics) have been maimed and costs us billions each year, then you’re on the side of the terrorists.
bash: /bin/tar: Argument list too long
Anyone who has worked with large numbers of files has seen the error ’Argument list too long
’ returned by a command before, usually something like cp
or rm
. Eventually, they find xargs
and all is well again; rather than globbing directly, you use find
and xargs
to feed the intended command:
~/tmp$ ls | wc -l 77029 ~/tmp$ cp * /foo/bar/ bash: /bin/cp: Argument list too long ~/tmp$ find . -print0 | xargs -0 -I {} cp {} /foo/bar/
For those who don’t know, that final command is running find, which simply prints a list of the files in the current directory. xargs
then passes a not-too-long subset of that list to cp
in batches, replacing the {} with said list. The -print0
tells find
to terminate each filename with a null character rather than the default newline, so that weird filenames work; the corresponding option -0
must be used with xargs
so that it looks for that syntax. Now, on to the problem of the day.
I know xargs
, but for the problem I had, I didn’t think it would help (more on that later). I wanted to tar
up a whole bunch of files, too many for the command line to handle. The solution was simple, for tar
provides an option to receive its list of files that makeup an archive from a file:
~/tmp$ find . -print > baz.lst ~/tmp$ tar -cf baz.tar --files-from baz.lst
Simple. There’s probably a way to one-line that, but simply piping the output of find
to tar with --files-from -
didn’t work, and I didn’t spend any more time trying to figure it out. As I said previously, I didn’t think xargs
would help, but I pulled up the tar
manpage and, using the -r
option, you can append to an existing archive, which could work in conjunction with xargs
just fine.