category archive: tech

arranging windows from the gnu/linux command line with wmctrl

A reboot of my computer recently caused me several hours of work. Nothing went wrong; the machine and Ubuntu started fine. No, I had to spend the time to save time. I was just trying to make things easier and more efficient, you see.

I rarely restart my home computer. If an occasional software update wants me to do it, I mentally cringe because it will mean several minutes of starting and arranging windows. I always have a collection of terminal, editor, and browser windows open and arranged just so. Things are coordinated between left and right monitor and a double-decker taskbar list. I can quickly move between windows and have everything lined up conveniently side by side and top and bottom, and all is well with the world. But then comes the reboot.

More frequently there is the need to restart Firefox. I like Firefox, but it leaks like a sieve on my machine. Maybe it’s all the plugins that are to blame, but in any case, after …

WordPress Plugin: Post Revision Display

I guess July is WordPress plugin month here at movingtofreedom.org, because here comes another one. This one was instigated by another Scott.

Scott Rosenberg wrote last week about the “mutability of online content” and the challenges news organizations face in handling changes and corrections to stories, and concluded that versioning made sense in journalism as a way to build trust. Readers can see all of the changes since publication so that there’s no sense of something being swept under the rug. The Drupal CMS has modules for making revisions publicly viewable, and of course this is a key feature of Wikipedia.

Scott noted that WordPress already stores revisions, and suggested a plugin could make old versions accessible to visitors. Looking to demo the idea on his blog, he later asked if any WordPress developers were intrigued. At first I was only intrigued enough to dig up an existing plugin by D’Arcy Norman that did some of what he was looking for: “Post Revision …

WordPress Plugin: The French Archives

The French are a fine people, but you should be aware that this plugin has nothing to do with France or the French.

Month Grid Archive

I wanted to be able to display my monthly archives in a grid:

With post counts for each month, but wasn’t finding a plugin for it. I did find Rob Marsh’s Compact Archives plugin which gave me a good starting place. (Thanks Rob!)

Along the way, it seemed like it would be nice to have post count totals for each year and a grand total. I think this table gives readers a nice snapshot of posting activity over the years.

It’s simple to use: put the_french_archives.php in your plugin dir, activate it, and put <?php month_grid_archive(); ?> in your template file.

You can optionally specify the month header styles. “abbr” is the default, “initial” shows only the first letter of the month, and “numeric” shows the month number. You can also customize the top row. Default is “Monthly” …

WordPress Plugin, YARQ v3.0: Yet Another Random Quote

This is a plugin/widget to show random quotes on your blog. Frank van den Brink originally created it and Christian Beer has also contributed. The wordpress.org homepage is here: Yet Another Random Quote.

I like this plugin, even if very few people around here can be bothered to actually click on a link to see my random quotes. Really, it’s okay. It’s just fine if you don’t give a rat’s ass about my collected pearls of wit, wisdom, and pop culture ephemera. (You probably won’t care to read my old YARQ post either.)

It appears that the plugin hasn’t been actively maintained, but through the miracle of free software I’ve been able to make my own fixes and enhancements, and now I can share them with you and the world. (I did get in contact with Christian, so we’ll see what we can do about updating the official plugin page.)

YARQ v3.0 works with WordPress 3.0 (for me, anyway), and I suspect will work with WP 2.5 …

findr: a GNU/Unix ‘find’ helper

I’ve been more aggressive lately about creating helper scripts and aliases for common tasks, and I liked this find helper enough to want to share it. I find that I often do filename searches like this:

find -iname “*some_word*”

That’s not so bad to type, but why not make it even easier for my, and maybe your common usage? We might prefer to do something like this:

findr some_word

And assume that we’re looking for a case-insensitive, substring match. And since we love regular expressions, we can work with find’s regex options:

–regextype posix-egrep -iregex

Which is just begging for a helper to do the work for us in standard situations.

Before we look at the script and some examples, here are a few more considerations for our findr command:

With the -iregex option, the match is against the whole path, so we’ll wrap the supplied regex search term with dot-stars (.*) to loosen things up. We probably want to limit our match to the last item …

Python Sequence Generator

I was looking for Python “sequence generator” code earlier today. By that, I’m thinking of a method to increment an arbitrary string of letters and numbers in an orderly way.

I figured there should be code samples out there to make quick work of it, but it was more challenging to find something than expected. Part of it might be my weak conceptual grasp of the subject. Maybe I just lacked the necessary search terms. With the words I did have — sequence and generator — I got a lot of static since these terms describe basic Python concepts.

I finally resorted to crafting my own sequence generator. To you, Future Searcher, I hope it will be useful. It is easy enough to convert this into a function, which I did for my script. (Or maybe you’ll want an actual generator!) I won’t elaborate on it more. If you’re looking for this, you probably know everything you need to know.

(I’m releasing this into the public domain. Use the code freely and …

Python CSS Shrinker for WordPress

This isn’t really specific to WordPress, but it preserves the first comment for WordPress theme management, WordPress is awesome, and I’m specifically using this for WordPress style sheets, so I’m making the connection.

I wrote this script to condense my style sheets into smaller files for faster download times. I’m all about customer service here.

And it’s pleasing to me to distill the CSS into a purer essence and reduce network overhead. (Not that the throngs of visitors to this site are noticeably plugging the tubes.)

One benefit of using compression this way is that I can be more liberal in my stylesheet comments, knowing they won’t burden the “production” .css file delivered to my patrons.

I didn’t go for maximum shrinkage, but this provides sufficient minification for my tastes. Read below for additional commentary and caveats.

(I’m putting this in the public domain. Use at your own risk!)

css_shrinker.py

#!/usr/bin/python3

import sys
import re

css = open(sys.argv[1], 'r').read()
unshrunk_size = len(css)

# save first comment which wordpress needs to display …

No More ‘Curly Quotes’ in WordPress

I’m ditching curly quotes. If you’ve come across this post via a web search, you probably already know that WordPress replaces apostrophes and double quotes with prettier “curly” versions, like this:

"I'm in double quotes." → “I’m in curly quotes!”

It does this with the best of intentions, I’m sure, and I think the curly quotes look very nice, but I don’t want them anymore. And if you clicked on this page in your search results, it’s likely you want to remove them also, along with other “character entity reference” conversions, e.g. double dash (--) to em dash (—). (Or maybe you were searching for how to suppress “smart” quotes?)

It’s easy to change this behavior, and it doesn’t require a plugin. You just need to add a few lines to one of your theme files. Before we get into that, let’s ask:

Why not pretty formatting?

To prevent WordPress from mangling code samples. This is the most common complaint I’ve seen. You’ll still have other things to watch for, though, …

gedit bad behaviors

GNOME’s gedit text editor is great, but I’m bugged by a couple of things:

If I pick a “recent” file from the File menu and the file is currently unavailable because it’s on a file system that’s not mounted, gedit takes the liberty of removing it from the recent files. Why not leave it there? Chances are I’ll be mounting the file system and wanting to get at it again. And if it’s a “dead” file, it will fall off the list soon enough anyway.
If I print something and choose multiple copies, gedit remembers this setting. (Even after closing and reopening the application.) This seems hostile to me, since most other applications don’t do this. I never remember to look there and keep getting extra copies on future print jobs. Maybe this is a GNOME common print dialog feature, but in any case it’s hurtful and wasteful.

Python script: Extract slashdot user names and ID numbers from a story discussion

I was reading slashdot yesterday and some (inane) comments about people’s user ID numbers made me curious about the overall distribution of IDs in slashdot discussions. It didn’t take long to take what I’d learned about the Beautiful Soup screen-scraping library from writing my Twitter status backup script to get some simple information.

Here’s a quick and crude little Python script that does the job as of yesterday’s slashdot HTML/CSS scheme. It spits out the ID number and username, which you then might send through the Unix sort command with various options, e.g.:

slashdot_info.py ‘[slashdot story url]‘ | sort -un

I’m placing this code into the public domain after disclaiming any responsibility for your use of it. Suggested enhancement: Add option to get number of comments for each user and allow sorting by that variable also.

(Update: This only grabs the first 50 comments. I’m not invested enough in the problem at the moment to want to figure out how to grab the entire discussion. That’s another exercise left to you.)…