Command-line shuffle

Posted by Michael Giarlo on September 26, 2009

Being a nerd, I tend to like the command-line. When I'm working on my laptop at home, I tend to like listening to music. Before I discovered that mplayer had a really convenient shuffle idiom, I would invoke it thusly (to listen to all my Pavement tracks in shuffle mode):

export IFS=$'\n'
for track in $(find /mnt/upnp/MediaTomb/Audio/Artists/Pavement -name \*.mp3 | ~/bin/shuffle.py); do mplayer $track; done

And the wee shuffle script I whipped together looks like this:

#!/usr/bin/env python
# shuffle.py
 
import sys
import random
 
args = list(sys.stdin)
random.shuffle(args)
sys.stdout.writelines(args)

And here's the convenient shuffle idiom that renders my arg-shuffling script somewhat useless:

find /mnt/upnp/MediaTomb/Audio/Artists/Pavement -name \*.mp3 | mplayer -playlist - -shuffle -loop 0

Lynx and HTTPS/SSL on Ubuntu (8.10)

Posted by Michael Giarlo on January 12, 2009

Dear Future Me,

It has been a while, hasn't it? Yes, it has[1].

Did you try to view an HTTPS/SSL URL in Lynx[2] again, only to be met, most cruelly, with the following error message?

$ lynx https://example.org/resource/[3]


Alert!: This client does not contain support for HTTPS URLs.

Well, have no fear! The lynx package, at least within the aptitude repositories for Ubuntu 8.10 (Intrepid Ibex), has no SSL support as you have just witnessed. The lynx-cur package, on the other hand[4], does! Support SSL, that is. Fix yourself thusly:

$ sudo apt-get install lynx-cur

N.B. the new lynx looks for its configuration in a different place than the old lynx, so you may need to fiddle with things if you've tricked out lynx with bells and whistles and racing stripes and nitrous boosts. Otherwise, huzzah!

Notes
  1. In the future you will have evolved beyond answering your own questions, no doubt, but here in the past, in this quaint and backwards era, it is quite common to hold conversations with yourself. Or myself. But I (i.e., you) digress! (We digress in the past as well! Quite the confusing state of affairs, conversationally speaking!) []
  2. Do they even have Lynx in that brave new world of the future? Does the lynx species still exist? Did the polar ice caps melt and wipe out all non-domesticated felines? Inquiring, unevolved minds of the past want to know! []
  3. I am assuming that in the future example.org remains a reserved dummy domain. []
  4. I hear that in the future hands will be replaced by hooks and detachable chainsaws and the like? []


HOWTO: Get Twhirl 0.8.7 working on Ubuntu

Posted by Michael Giarlo on December 16, 2008

I use the Adobe AIR-based Twhirl as a Twitter and identi.ca client on my Ubuntu box. Twitter recently made some changes to their authentication API, apparently, which prevented Twhirl from connecting as of version 0.8.6. The fine folks over at Twhirl pushed out 0.8.7 in a jiffy but it included some AIR 1.5 dependencies. The problem was that Adobe AIR for Linux only comes in 1.0 and 1.1 versions.

I was a tad frustrated that such a seemingly minor Twitter API upgrade resulted in a fundamentally different (and broken) version of Twhirl, but I couldn't fault them for trying to respond quickly. I followed the twhirl user on Twitter when this went down, and I was pleased to find out that they've whipped up a special AIR 1.1 Twhirl client for us Linux users.

I ran into some problems trying to install the client. The first problem I ran into was due to a corrupt download. If the file is less than 997K or so, you should try to download it again. If Firefox fails you, there's always wget. Want to make sure you've got a good file? Run unzip against it (an .air file is a .zip file underneath its raincoat). If it succeeds, you're golden.

The other problem was an old version of Adobe AIR. You want adobeair_linux_b1_091508.bin installed, not adobeair_linux_a1_033108.bin. Here's how you "upgrade" AIR from the alpha to the beta (1.1) and get Twhirl 0.8.7-air11 installed:

  1. sudo adobeair_linux_a1_033108.bin -uninstall
  2. sudo apt-get remove adobeair-enu (This step was not necessary on another box I tested. It could be that the original box I tried these steps on was munted up.)
  3. This may be optional! Clean out /opt/Adobe Air/, ~/.adobe/AIR/, and /root/.adobe/AIR/. Note that this step will wipe your settings for all your AIR applications.
  4. Download the AIR 1.1 beta for Linux
  5. adobeair_linux_b1_091508.bin (Some report that Firefox and other browsers must be closed during this step, but I couldn't reproduce that.)
  6. Download the latest AIR 1.1 Twhirl for Linux
  7. Then navigate to the twhirl-0.8.7-air11.air via Nautilus and double-click it.

Worked for me, at least.

Convert Windows shortcuts into Ubuntu shortcuts

Posted by Michael Giarlo on October 29, 2008

[Update: Feel free to grab the code via bzr with bzr branch http://lackoftalent.org/bzr/shortcut_converter.]

Here's another entry in the "dumb little scripts that work for me and may or may not be helpful to other folks" department…

I use both Windows and Ubuntu at home, gradually transitioning from the former to the latter. I've accumulated a bunch of Windows URL shortcuts, mostly things I wanted to read once so instead of bookmarking them, I dragged their links to my desktop. This creates .URL files which are simple little plain-text two-liners. It turns out that on Ubuntu, and probably similar *nix systems, web shortcuts are also simple little plain-text files. These files have the .desktop extension (though you won't see the extension by looking at the desktop).

I wanted a way to convert my .URL files to .desktop files so that I can just toss them on my Ubuntu desktop and double-click them the same way I would if I were on Windows. This cruddy little Python script does the trick.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# shortcut_converter.py
 
from __future__ import with_statement 
import os.path
import sys
 
TEMPLATE = """[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=%(basename)s
Type=Link
URL=%(url)s
Icon=gnome-fs-bookmark
"""
 
def convert(f):
    """ Takes a full filepath to a .URL file, converts it to a .desktop file 
        in the same directory """
    print "Converting %s" % f
    (filepath, filename) = os.path.split(f)
    (basename, extension) = os.path.splitext(filename)
    with open(f) as urlfile:
        lines = [line.strip() for line in urlfile.readlines()]
    url = lines[1].split('URL=')[1]
    dtfname = os.path.join(filepath, '%s.desktop' % basename)
    with open(dtfname, 'w') as dtfile:
        print "Writing %s" % dtfile.name
        dtfile.write(TEMPLATE % locals())
 
if __name__ == '__main__':
    for arg in sys.argv[1:]:
        if os.path.isfile(arg) and arg[-3:].lower() == 'url':
            convert(arg)
        else:
            print "*** %s is not a URL file" % arg

I used scp to pull over all my .URL files and then invoked the script thusly:

python shortcut_converter.py *.URL

worksforme!

Bash, For loop, Files with spaces

Posted by Michael Giarlo on September 27, 2008

Dear Future Me,

Are you trying to iterate over filenames with spaces in them using a bash 'for' loop?  And instead of iterating over the filenames, you wind up seeing a list of filename parts split by said spaces?  Use case: you want to print out a list of unique extensions for all files in the current directory and below:

    for file in `find . -type f`; do echo ${file##*.}; done | sort | uniq

If any filenames have spaces in them, you may see odd results.  The answer?  Set the input field separator (IFS) environment variable to the newline character (rather than the default space character):

    export IFS=$'\n'

And voila.