Category Archives: Tech

Tech

Comments from ‘file’ (and ‘tar’)

Occasionally when using Linux (or Mac OS X) I’ll notice a tongue-in-cheek output message from a utility. Today, it was ‘file‘, a program that uses magic numbers and other tricks to tell you about the contents of a file:


[brock@stilgar][Darwin]-(~/Workspace/RvPacing/bridge/flma2memfem)-> file bridge_w_surf.flma
bridge_w_surf.flma: ASCII text, with very long lines
[brock@stilgar][Darwin]-(~/Workspace/RvPacing/bridge/flma2memfem)->

Emphasis mine. Thanks for the commentary, file.

ADDENDUM: Just now, tar gave me this little message because I forgot to provide some source data:

[brock@stilgar][Darwin]-(~/models)-> tar cfjv bridge_iso.tar.bz2
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information.

That one, I’ve seen before.

Finding Duplicates with sort and uniq

Imagine this: You have two text files full of information, with one data entry on each line. You want to find out which lines occur in both files. Now, if the files are mostly the same, it’s probably best to use a program called diff. However, if the files are mostly different, you can use this little incantation:

cat file1.txt file2.txt | sort -n | uniq -d

This will join file1 and file2, sort the joined data -numerically, and display only the lines that are not unique (uniq -d).

This came in handy for manipulating electrode files today. Our electrode files just contain lists of node numbers. The simulator gets unhappy when you try to do things with overlapping electrodes, so in this way we were able to remove the offending overlap without too much trouble.

Maintaining My Posting Rate

I had one major New-Year’s resolution (though I had resolved it before then): post to my blog on average once per day. This sounds simple, but I don’t just want one post on each day. I’m happy to let my posting muse cycle between wordlessness and logorrhea. Therefore, if I post three things one day, I’m off scot free for the next two days. In practice, this gets pretty hard to keep track of. I’ve already started to find it difficult 23 days into the year.

However, I was able to remedy this with a little PHP and MySQL code. WordPress (this blogging software) runs on those technologies, and so it was trivial for me to tap into the database and produce this page. It does something very simple. It goes from the beginning of the year to the present day, tallying posts along the way, and dividing by the number of days in the year that have passed. This gives me a total post count and a ratio of posts to days. As you can see if you look at that page, I have been coasting for a little while, but was getting dangerously close to “1”. This post should remedy that, which is kind of cheating, but I’m willing to accept it.

Probably this could be dressed up into a widget or plugin or something, and anyone is welcome to use it to do that, but I have neither the time nor sufficient interest to learn how.
Here’s the PHP code, if you’re interested: postcountphp.gz (1 kB)

ADDENDUM: Updated 2008-01-26 to only count published posts.

Label Your Power Bricks

Once upon a time, AC/DC adapters were special — they were made for expensive devices and were clearly labeled as belonging to those devices. No more. Now, every device comes with an adapter, most of them are nothing special, and the adapters are hardly labeled at all. Furthermore, they have mysterious round plugs that (unless you have calipers handy), you probably can’t tell apart. You could go around trying to match voltages and currents, or you could just label the damn things when you get them.

If you’re part of the GTD cult, you should already have a labeler. Just print out short, simple labels and stick them on!