my half-arsed attempt at blogging
bash
cURL and Google Spreadsheets
Dec 6th
I failed to find a good example of something that worked to pull a spreadsheet from google-docs using cURL. All that I found didn’t work, in one shape or another.
A bit of playing, and quite a bit of reading got this
#!/bin/bash
PASS=`cat /path/to/0600/google-password-file`
SHEET="https://spreadsheets.google.com/feeds/download/spreadsheets/Exportkey=addyourownsheetIDhere&exportFormat=csv&gid="
AUTH_TOKE=`curl --silent https://www.google.com/accounts/ClientLogin -d \
Email=foo@example.org -d \
Passwd=${PASS} -d \
accountType=HOSTED -d \
source=cURL-SpreadPull -d \
service=wise | grep Auth\= | sed 's/Auth/auth/'`
curl --silent --output /path/to/file --header "GData-Version: 3.0" --header "Authorization: GoogleLogin ${AUTH_TOKE}" "${SHEET}${TAB}"
seemed to do the trick
Exportkey could be defined in the script, as a variable, thinking about it. You’ll need to supply that; I typically grab it from the web-based URI, but there is a warning in the docs about that:
To determine the URL of a cell-based feed for a given worksheet, get the worksheets metafeed and examine the <link> element in which rel is http://schemas.google.com/spreadsheets/2006#cellsfeed. The href value in that element is the cell feed’s URI.
YMMV.
I’ve added in &exportFormat=csv&gid= because I wanted CSV outputs, and gid’s value is provided via a for … and case deviation.
--header "GData-Version: 3.0" was needed to avoid the redirection.
Hopefully, this might be of benefit — as a working (when written) example of using curl and google docs/google spreadsheets.
Transmission and Renaming Torrents
Sep 14th
I’ve recently (ish) started using transmission as my torrent client; the change-over comes from my switching-things-off approach; instead of keeping ktorrent running on the laptop (and caneing my bandwidth), I can have something mainly work on the NAS which is always on (bar power-cuts/maint).
One of the things that I noticed was the apparent lack of renaming within Transmission (and the curious way earlier tickets are marked as duplicitous of later ones).
So, erm, I’ve written something that works for me. And hacked out the mailer-script to something a little cleaner— at least in my view.
The premise is that you’re using a POSIXish operating system — my NAS runs on Debian — and that all of your exports are within the /nas directory, and your torrents directory is /nas/torrents.
The changes needed are (with transmission not running, apparently) to include /path/to/post-download as the value for
script-torrent-done-filename in settings.json
You’ll need to echo in "/path/to/store/the/completed-file" to a file named as per the torrent (see your incomplete directory for that), but with “.move” appended; the rest should all happen automagically.
You might find it useful to chown the directories you’ll be moving things to that of the user running the transmission processes; I tend to setgid to my GID too.
The other file, mvtor, is one for doing a manual move, specify the torrent as an arguement; e.g., ./mvtor "ubuntu-10.04.1-alternate-i386.iso"
Firefox Extensions
Jan 10th
Thought this might double up as a note of the firefox extensions I currently have installed — I’ve tried getting this to script, but, the source file isn’t something I’m over-familiar with, and getting fields to match-up ain’t happening, due to my crapness.
Anyhow, I would appear to have these firefox extensions installed:
- Adblock Plus
- AutoPager
- BetterFlickr
- Better YouTube
- Delicious Bookmarks
- DownloadHelper
- Echofon
- Extended Statusbar
- Fast Video Downloader (with SearchMenu)
- Firebug
- Firefox (default)
- Firefox (en-GB)
- Flagfox
- Flashblock
- Gmail Manager
- Greasefire
- Greasemonkey
- Image Download
- Image Zoom
- Inline Code Finder for Firebug
- is.gd Creator
- JavaScript Options
- keyconfig
- Magic’s Video Downloader
- oldbar
- Password Exporter
- Save Image in Folder [sic]
- ShowIP
- SkipScreen
- TinyUrl Creator
- Ubuntu Firefox Modificiations
- URL Fixer
- VMware Remote Console Plug-In
- Xulrunner (en-GB)
- YesScript
A few of those don’t have links I can identify from the URI.
Want some code that vaguely does this for you?
#!/bin/sh
#
# ffexts:
# list firefox extensions: names and URIs for download/homepage
#
# Copyright (c) 2010 Adam McGreggor. Some rights reserved.
# Email: <adam@amyl.org.uk> Web: <http://blog.amyl.org.uk>
#
# $Id: ffexts 119 2010-01-10 00:38:04Z adam $
#
set -e
MOZDIR=~/.mozilla/firefox
PROFDIR=`ls -lha ${MOZDIR} | grep default | awk '{print $NF}'`
FILE=extensions.rdf
INFILE=${MOZDIR}/${PROFDIR}/${FILE}
OF=~/tmp/ffexts
OUTFILE=~/pseudohome/nas-docs/firefox-extensions-$(date '+%Y%m%d')
# check for existing outfile, as we'll be
# appending; if so, zap it
if [ -e ${OUTFILE} ]; then
rm ${OUTFILE}
fi
# grab the interesting bits from the RDF file
for K in name homepageURL
do
# nice fix-up, eh?
grep "NS1:${K}" ${INFILE} | sed -e "s/NS1:${K}=//" \
-e 's/"//g' -e 's/>//' \
-e 's/^[ \t]*//' | sort | uniq > ${OF}-${K}
# using wc here is entirely optional ![]()
wc -l ${OF}-${K}
# append
cat ${OF}-${K} >> ${OUTFILE}
done
Conditional Prompt colo(u)rs
Dec 23rd
I often work on several different machines, for different projects and things. It’s bloody annoying when I get the wrong machine!
I thought. I know what, I’ll make all of these machines use a colored prompt, and make that lot of machines use a different one.
(At this point, I should say that my dotfiles, and a variety of other things are kept in a subversion repo. Most of those bits are my-eyes-only (particularly a lot of the very badly/hastily thrown together scripts), but a few bits I’m gradually releasing.)
After mentioning this on twitter, a couple of people have been interested in how I did it.
The solution is quite easy, work out the hostname, and from that determine the ‘class’ of machine, and then apply some colors. The archwiki was useful in getting out the colors to use; along with underlining, and emboldening (I never use underlining, except in manuscript: ghastly thing that obscures text).
Whilst not perfect (the color parts could be set as a variable, and then passed to the PS1 line; I could have used “else” clauses…), it works. For me, so, erm, here’s my .bashrc — you want from the # work out machine name/domain: line.
A simple switch wotsits in screen(1), and
$ cd ~/pseudohome && svn up
followed with a
$ . .bashrc
is how I deploy (some people have an ’svn up’ in their start-up scripts, I don’t).
Comments here, if you want to.
