Rockin’ it 8-bit (thanks to Maryke)

Instagram filter used: Normal

View in Instagram ⇒

Made with:

#!/bin/bash
# selfi.sh - strongly influenced by Interstellar Selfie Station
#                          http://interstellarselfiestation.com
# scruss - 2014-06-26

anytopnm "$1" |\
  pnmscale -xsize 160 |\
  pnmhisteq |\
  ppmdither -red 4 -green 4 -blue 4 |\
  pnmremap -mapfile < (echo P3 4 1 255 108 108 78 142 139 97 195 196 165 227 230 201) |\
  pnmscale -nomix 2 |\
  pnmtopng > "${1%.*}-selfi_sh.png"

Update, 2021: well, who knew that software that purportedly hasn’t changed since 2001 (netpbm on Debian) would change? This script broke between 2016–2021, and I had to remove the ppmtopgm line that was after the ppmdither call to make it work again.

clean up your GnuPG keyring

For reasons too annoying to explain, my GnuPG keyring was huge. It was taking a long time to find keys, and most of them weren’t ones I’d use. So I wrote this little script that strips out all of the keys that aren’t

  1. yours, or
  2. signatories to your key.

The script doesn’t actually delete any keys. It produces shell-compatible output that you can pipe or copy to a shell. Now my keyring file is less than 4% the size (or more precisely, 37‰) of the size it was before.

#!/bin/bash
# clean_keyring.sh - clean up all the excess keys

# my key should probably be the first secret key listed
mykey=$(gpg --list-secret-keys | grep '^sec' | cut -c 13-20 | head -1)
if
    [ -z $mykey ]
then
    # exit if no key string
    echo "Can't get user's key ID"
    exit 1
fi

# all of the people who have signed my key
mysigners=$(gpg --list-sigs $mykey | grep '^sig' | cut -c 14-21 | sort -u) 

# keep all of the signers, plus my key (if I haven't self-signed)
keepers=$(echo $mykey $mysigners | tr ' ' '\012' | sort -u)

# the keepers list in egrep syntax: ^(key|key|…)
keepers_egrep=$(echo $keepers | sed 's/^/^(/; s/$/)/; s/ /|/g;')

# show all the keepers as a comment so this script's output is shell-able
echo '# Keepers: ' $keepers

# everyone who isn't on the keepers list is deleted
deleters=$(gpg --list-keys | grep '^pub'|  cut -c 13-20 | egrep -v ${keepers_egrep})

# echo the command if there are any to delete
# command is interactive
if
    [ -z $deleters ]
then
    echo "# Nothing to delete!"
else
    echo 'gpg --delete-keys' $deleters
fi

Files:

Secure digital QSL cards, part 2: shell script

Following on from Creating secure digital QSL cards with your LoTW certificate, here’s a Bash script to generate encrypted signed PDF QSLs. You will need to edit the certificate file name, the QSL blank file name, your call sign, your LoTW password and the PDF encryption password. After doing so, please keep the script safe, as whoever has your LoTW password can pretend to be you.

The only checks that this script doesn’t do (and probably should) are if you have pdftk and PortableSigner executables in your path. PortableSigner is rather weird the way it runs; you need to specify full paths for all files, or it dies.

The script is called like this:

mkdqsl.sh callsign date utc mhz mode report

for example:

mkdqsl.sh VE3KPK 2011-10-02 2341 7.03581 CW 499

Code below the fold.

perhaps a slightly easier way to make SD cards bootable for CHDK under OS X

Now that CHDK has a working beta in the source tree for my Canon PowerShot SD790is, I actually have to prepare SD cards for it. The Bootable SD card – OS X instructions seem a bit contrived, so I took a look at the linux instructions, and modified them accordingly. These instructions should work for FAT16-formatted SD cards of 2GB capacity and under. It will not work for SDHC cards, which are generally formatted to FAT32.

This is all command-line only for here on in. It seems to work. Please note that you will be modifying raw file systems with root permissions here; there is no safety net. If you b0rk your main hard drive, don’t say I didn’t warn you.

Firstly, you’re going to have to find out where the SD card in mounted. Do this with:
df
I got:

Filesystem    512-blocks      Used Available Capacity  Mounted on
/dev/disk0s2   487463200 318749896 168201304    66%    /
devfs                222       222         0   100%    /dev
map -hosts             0         0         0   100%    /net
map auto_home          0         0         0   100%    /home
/dev/disk2s1     3969280      3328   3965952     1%    /Volumes/CANON_DC

There are three important concepts to note when looking at the mounted card:

  1. The mount point (or volume) – in this case /Volumes/CANON_DC. This is the location that you see in Finder when moving files around.
  2. The filesystem – here /dev/disk2s1. This is the partition on the disk, arranged according to a certain formatting scheme like MS-DOS FAT16.
  3. The disk device – which for me is /dev/disk2. This is the disk device itself, and it may contain several filesystems.

Your locations for these three could well be different, so please substitute your values.

You’ll need to unmount the device, as writing to a raw filesystem while the OS thinks it has control often results in hilariously unexpected results. I used the OS X-specific command

diskutil unmount /Volumes/CANON_DC

You should get a message like Volume CANON_DC on disk2s1 unmounted. Now you need to write the boot instruction:

echo -n BOOTDISK | sudo dd bs=1 count=8 seek=64 of=/dev/disk2s1

This will prompt you for your password.

If you need to, you can remount the filesystems on the card with

diskutil mountDisk /dev/disk2

(Note that we used the disk name here, not the filesystem. If there were several partitions on the disk, this command would mount all of them that it could. It’s also kinda handy for remounting USB devices that you’ve accidentally ejected from Finder.)

Update: Knowing a difficulty getting the firmware update method of getting CHDK to work on a Mac? Running a Leopard or newer machine? Then you need to learn all about Apple’s quarantine attribute and how to remove it with xattr: FAQ/Mac – Still having trouble?.

no, it just isn’t

Finding a source of “Unlimited free energy” would be the most unimaginably heinous crime possible against humanity. For it would inevitably turn the planet into a cinder. Hastening an isoentropic heat death. If you find a free energy source, you damn well better find a new free energy sink as well. Even then, the relative flux rates will still nail you.

 — Don Lancaster, How to Bash Pseudoscience.

batch renaming iTunes directories

In partial response to the Ask Metafilter question “How can I rename my music folders on my Mac based on ID3 tags?“:

#!/bin/bash
# itunes_sanity.sh - fix dir names created by iTunes
# only works for mp3s, and not actually tested on a Mac
# created by scruss on Sun Sep 4 22:05:00 EDT 2005

find "$@" -type d -mindepth 1 | while read directory
do
  artistdir=$(dirname "$directory")
  firstfile=$( find "$directory" -type f -iname '*.mp3' | head -n1 )
  year=$( id3info "$firstfile" | egrep ' TYE ' | sed 's/=== TYE (Year): //; s/[^0-9]*//;' )
  album=$( id3info "$firstfile" | egrep ' TAL ' | sed 's,=== TAL (Album/Movie/Show title): ,,;' )
  echo mv \'$directory\' \'$artistdir/\[$year\] $album\'
done

So if you were in the terminal, in your music library (one up from the individual artist directories), and you did:

itunes_sanity.sh Dan\ Jones Tripping\ Daisy

you’d get:

mv 'Dan Jones/Get Sounds Now' 'Dan Jones/[2005] Get Sounds Now'
mv 'Dan Jones/One Man Submarine' 'Dan Jones/[2003] One Man Submarine'
mv 'Tripping Daisy/Jesus Hits Like the Atom Bomb' 'Tripping Daisy/[1998] Jesus Hits Like the Atom Bomb'

If that looks okay, run the output through the shell:

itunes_sanity.sh Dan\ Jones Tripping\ Daisy | sh

and all should be well.

You’ll need id3lib, which is probably most easily installed from Fink. Also, this only works for mp3 files; I can’t grok the tag info for AAC files. And finally, this might go seriously screwy on weird characters in filenames. You know my feelings on that …

dealbreakers

Okay, so if I were to buy an iBook, I must be able to:

  • have virtual workspaces, like X11
  • use a compose key for accented characters
  • be able to do my usual Perl/Bash things in the terminal
  • get basic, useful applications for free.

Since I can do these things on Linux now, there’s no point in me switchin’ in the kitchen.