December 15, 2009

9 degrees celcius

The weather indicator in the top right of my GNOME desktop has been saying 9 degrees celcius for the last few days:

Wrong Weather

Which is clearly wrong. I think I've just worked out why it's not updating. A common source of weather data is airports. GNOME gets it's weather information from airports. For Coventry it uses Coventry Airport. Coventry Airport has been closed due to financial difficulties. Various sites which would usually display information from it's weather data feed all say 'no data'. So looks like the closure of Coventry Airport extends to it's weather data feed. Later on I might look at making it use an alternate data source.


December 07, 2009

Walt Disney World to become twin town of Swindon

Writing about web page http://news.bbc.co.uk/1/hi/england/wiltshire/8399996.stm

In the future, when people say 'stranger things have happened', this will be a citable example.


December 03, 2009

University Advent Calender as your (though maybe not your) wallpaper.

Writing about web page http://www.warwick.ac.uk/adventcalendar/

For no good reason other than because the idea got stuck in my head, a script (advent wallpaper script) which grabs an image of the University advent calender, does some stuff to it, sets it as your wallpaper and then adds a launcher to the panel that when clicked shows what's 'behind' today's door with the icon for the corresponding door as it's icon. Assuming you use GNOME for your desktop environment that is. Which statistically speaking, you probably don't.

Example screengrab (to click is to make larger):

Uni Advent Calender as wallpaper



Requires ImageMagick, gnome-web-photo, curl and Epiphany (the web browser not the holiday). Call from a cron-job or login script of something to automatically update wallpaper should you feel the desire to do so.


November 24, 2009

Fun with xkcd, bash, Imagemgick and GNOME

A script (xkcdannotated) which takes an xkcd comic then annotates it with the title and alt text like so:

xkcd.com - Silent Hammer

Invoked with no arguments uses the most recent comic, can also be told to use a specific comic or to use a random comic. Tested on Linux and Mac OS X.

A script (xkcdwallpaper)which calls xkcdannotated then sets the result as your GNOME wallpaper. Arguments as per xkcdannotated. Can also be told to overlay the comic on top of another image and set the result as the wallpaper.


November 23, 2009

Microserfs

Writing about web page http://en.wikipedia.org/wiki/Microserfs

Title:
Rating:
Not rated

This is a book I've been meaning to read for a long time. It came out in 1995 and is set in the pre-Windows 95 era. Thus reading it today serves as a bit of nostalgia tip. Apple is portrayed as a company on the decline, hurting from it's beating in the 'look and feel' lawsuit, hoping that a switch from Motorola 68K to PowerPC will help revive it's fortunes and with staff who are hanging on hoping to cash in on a redundancy package. There's mention of the hype around a company called 3D0 and of companies throwing huge amounts of money at that so very mid 90s concept of 'multimedia' whilst trying to give the impression that they have some idea what it actually means and how you to make money from it.*

Unlike the very similar in concept but set a decade later Jpod and I think every other Douglas Coupland book I've read, it is not set in or around the author's home of Vancouver, Canada. Instead it's set in Redmond, US, and later Silicon Valley. Despite the title and initial setting it is not a book about Microsoft or working at Microsoft. Rather it is about some people who happen to work at Microsoft and later a start up created by an ex-colleague.

As with all of Coupland's novels it is seems to be more about concepts and ideas than the characters, with the events which occur serving merely as a mechanism by which to explore the preceding. It doesn't tell a story with a clearly defined start and end, rather it recounts the events that occur during a particular section of the protagonist's life. It's written in the form of a journal by a guy called Daniel. He's in his late 20s and for the early chapters of the book lives in a house with nine phone lines along with five fellow Microsoft employees, one of whom is already a stock option millionaire. It's a tale of working long and irregular hours out of a passion for the work. Of all night coding sessions and 3am snack runs to the supermarket. Of living to work rather than living to work. Of an increasing awareness that people of the same age, even some in the same line of work, are starting to do 'normal' things. Normal things being settling down, living in houses they don't share with several other single people, buying furniture that isn't from Ikea and having interests and lives separate to work.

I read JPod first and enjoyed it. I've seen it refered Microserfs for the Google generation, which having now read Microserfs it obviously is. Though I think it's more like an attempt at Microserfs for the Google generation. Microserfs is more, well, it's events are far more plausible than those of JPod and over all it's the better of the two because of that.


* Remeber that multimedia craze? There were 'multimedia capable' PCs, which in practice seemed to mean they came with a pair of speakers, a graphics card capable of displaying more than just text and a CD drive. There were 'multimedia games'  and 'multimedia titles', which tended to mean they contained lots of low resolution video clips and stuff to click on. Then of course there were 'multimedia devices' such as the Philips CD-i on which you could not only play multimedia games such as Cluedo and Burn:Cycle, but also watch films in Video CD format. Which as I recall had a tendency to look worse than VHS and some films didn't all fit on one disc so you had to change them part way through.


November 16, 2009

Generating Freedesktop.org spec compliant thumbnails

A lot of Linux software that needs to generate thumbnails of an image uses the freedesktop.org thumbnail specification. This is good as it means if one application has already made a thumbnail of an image then another application can make use of it rather than generating it's own. I recently found myself looking for a way to generate such thumbnails.

The impetus for this was gnome-appearance-properties. This is the application which allows you to do stuff like change your wallpaper. Sadly as the number of wallpapers available increases it's usability decreases to some extent. The reason for this is that the user interface is frozen until all the wallpaper thumbnails are displayed. This in itself isn't too bad, unless you have thousands of wallpapers, but if it's combined with a lack of pre-generated thumbnails the user interface is frozen until all the thumbnails have been generated. This is annoying because if there are few hundred wallpapers available thumbnail generation can take over thirty seconds even on a decent spec machine. Thirty seconds during which the user is left looking at an unresponsive interface. There is long standing bug report regarding this, that I can't currently locate, which makes the very sensible suggestion that the thumbnails should be loaded asynchronously. Hopefully at some point someone will implement that, but in the mean time I found myself wondering whether it was possible to script the generation of thumbnails in advance.

My first thought was ImageMagick and a bash script because I'm already familiar with those. As it turns out ImageMagick comes very, very close to being able to generate such thumbnails using the -thumbnail option. I say close, because whilst it inserts both the MTime and URI information required by the freedesktop.org spec, it generates the URI incorrectly by inserting one too many slashes at the start. It creates

$ convert /usr/share/pixmaps/backgrounds/cosmos/earthrise.jpg -thumbnail 128x foo.png
$ identify -verbose foo.png | grep Thumb::URI
Thumb::URI: file:////usr/share/pixmaps/backgrounds/cosmos/earthrise.jpg

when it needs to be

 Thumb::URI: file:///usr/share/pixmaps/backgrounds/cosmos/earthrise.jpg

At time of writing this is actually fixed, but only in the svn version. If you have 6.5.7-8 or later then you should find it generates the URI properly. If you have an older version you can create the thumbnails like this:

#!/bin/bash
# makethumb - script to generate thumbnails to freedesktop.org spec
# *** Assumes GNU coreutils. ***
file=$1
saveto=~/.thumbnails/normal
tagfile=/tmp/$(basename $0)_tags
mkdir -p $saveto
thumbname=$(echo -n file://$file | md5sum| cut -d " " -f 1);
mtime=$(date +%s -r "$file")
echo "Thumb::URI={file://${file}}" >$tagfile
echo "Thumb::MTime={${mtime}}" >>$tagfile
convert -resize 128x -strip +profile "*" $file MIFF:- | cat $tagfile - | convert MIFF:- "PNG:${saveto}/${thumbname}.png"
rm -f $tagfile
$ makethumb /usr/share/pixmaps/backgrounds/cosmos/earthrise.jpg

Generating thumbnails this way is quite slow though. Using

$ find  /usr/share/pixmaps/backgrounds/ -type f -exec ~/makethumb {} \;

332 thumbnails took around 1:15 in my tests, though obviously this will vary depending on the spec of the machine. I tried using a variant of the script which generated thumbnails for all the files in a given directory, so only invoking the script once instead of multiple times. There was no significant difference in speed between the two methods though.

So I started looking for some way to use GNOME's thumbnail generation capabilities. The only example I could find of doing this used Python GTK bindings and was incomplete. I've only ever cobbled together one python script before, (that was also to use GTK bindings), but I managed to put together this

#!/usr/bin/python
# makethumb.py - script to generate thumbnails using GTK bindings

import gnome.ui
import gnomevfs
import time
import sys
import os

file=sys.argv[1]

uri=gnomevfs.get_uri_from_local_path(file)
mime=gnomevfs.get_mime_type(file)
mtime=int(time.strftime("%s",time.localtime(os.path.getmtime(file))))
thumbFactory = gnome.ui.ThumbnailFactory(gnome.ui.THUMBNAIL_SIZE_NORMAL)
if thumbFactory.can_thumbnail(uri ,mime, 0):
thumbnail=thumbFactory.generate_thumbnail(uri, mime)
if thumbnail != None:
thumbFactory.save_thumbnail(thumbnail, uri, mtime)

Using that to generate thumbnails in the same manner shown above for the bash script was about ten seconds faster. However after some experimentation I put together this (updated 15/8/11 to include suggestions from comment 2):

#!/usr/bin/python
# makethumbs.py - generates thumbnails for all files in a directory

import gnome.ui
import gnomevfs
import time
import os

dir="/usr/share/pixmaps/backgrounds/"

thumbFactory = gnome.ui.ThumbnailFactory(gnome.ui.THUMBNAIL_SIZE_NORMAL)

for subdir, dirs, files in os.walk(dir):
for file in files:
path = os.path.join(subdir, file)
uri = gnomevfs.get_uri_from_local_path(path)
mime=gnomevfs.get_mime_type(subdir+"/"+file)
mtime = int(os.path.getmtime(path))
print uri
print mtime
if thumbFactory.can_thumbnail(uri ,mime, 0):
thumbnail=thumbFactory.generate_thumbnail(uri, mime)
if thumbnail is not None:
thumbFactory.save_thumbnail(thumbnail, uri, mtime)

I found that generates 332 thumbnails in around 9 seconds. A massive difference to repeatedly invoking the makethumb.py script. I expect there are people who could provide a detailed explanation of why it's so much faster. I am not one of them.

It's also interesting to note that I've found this script generates thumbnails around three times faster than the gnome-appearance-properties creates them. Why that is I have no idea. The thumbs that result are not identical. The thumbnails generated by the Python script have the width and height of the original image embedded in them whilst the ones generated by gnome-appearance-properties do not. The ones generated by gnome-appearance-properties have a very lightly larger file size and the Channel Statistics embedded in the thumbnails are different too. However both sets of thumbnails say they were generated by GNOME::ThumbnailFactory.

Interesting as all this is, (to me anyway if it's not to you then why did you read this far?), it's all about generating thumbnails on a per-user basis. What if it was possible to have a system wide cache of per-generated thumbnails. E.g. you install a bunch of wallpapers and along with them you can install thumbnails that will be used rather than each user generating their own. The freedesktop.org thumbnail spec does cover this. So I tried creating such thumbnails. gnome-appearance-properties ignored them. When I say ignored them, I don't mean it looked at them and didn't use them, the output of strace indicates that it doesn't even look to see they exist. Which is a shame.


November 15, 2009

Why don't polar bears eat Unicorns?

Because polar bears live at the north pole and Unicorns live a the south pole with the penguins. Whether the crown and cape were intended to indicate that this is an Emperor Penguin wasn't clear. Either way, the penguin is clearly not amused.

Frickin Unicorn

Seen at a garden centre yesterday. A garden centre that was already fully decorated for Christmas, had hired people to abuse the ears of their customers with renditions of Christmas carols on an accordion and tambourine and had Christmas trees on sale. Real live Christmas trees, not artificial. The really tragic thing is I'd be willing to bet this was all set up weeks ago.


November 04, 2009

Microsoft promises Mac and Unix versions of ActiveX this year…

... in 1996. I was idly flipping through the October 1996 issue of Personal Computer World(*) the other day when I noticed this article:

Article from Computer World October 1996.

I was aware there were once versions of Internet Explorer for both Mac and strange, even optimistic, as it may sound for Unix (**), but this is the first time I've encountered a reference to ActiveX on anything other than Windows. Evidently Microsoft did deliver on the promise, though I've not been able to locate any info on how long the projects lasted. I doubt their demise was much mourned.

It appears that Microsoft did, as suggested at the end of the article, give away ActiveX. Something else I was unaware of. The documentation is available here. Though this article suggests that they only gave away part of it and did not '...disclose the specifications and source code needed to build working client-side ActiveX applications on platforms other than Windows'.


The other part of the article that caught my eye was that part about set top boxes being expected to bring the web in the living room. I can dimly remember such talk. It seems plausible enough on the face of it but it never happened and in retrospect seems hopelessly optimistic. The closest I can recall coming to the 90s web in the living room via a set top box experience was via a friend's Phillips CD-I. It had an email client and a web browser. Both were utterly dismal.


(*) A colleague has a bunch of such magazines piled in the corner of our office. I'm not sure why.

(**) I tried running it on mimosa but it just says "SunOS 5.8 is not currently supported." and displays an empty window.


November 02, 2009

If they really must do it, they should ask if Elvis is there.

Writing about web page http://sky1.sky.com/derek-acorah-to-attempt-to-contact-michael-jackson

This November Sky1 HD and world-renowned psychic medium Derek Acorah will attempt to make contact with Michael Jackson in two special shows, Michael Jackson: The Live Seance and Michael Jackson: The Search For His Spirit.

Possibly the most moronic thing on TV since that advert for the 'love calculator' via text message thing. (If you've seen it you know what I mean. If you haven't seen it, hope you never do.)


October 29, 2009

Adventures in NX, sshd and pam.

Or: How to get pam to distinquish between a login that's happening via ssh by someone using an NX client and one that's not.

I've got some Linux machines where I use pam_script in the GDM pam stack to do some stuff which I only want doing when the user logs in with an X session. Having set one of these machines up for NX access I realised that the pam_script stuff didn't get run for NX logins for the obvious reason that the logins don't happen via GDM. I want the pam_script to run for NX logins too and found this presented a problem. NX logins are done over ssh so I would have to put pam_script in the sshd stack. However I don't want the pam_script stuff to run for ssh logins done using the traditional command line method of 'ssh user@hostname'. So I needed to find a way to allow pam_script to distinguish an ssh login happening via NX from one that wasn't. Google searches didn't yielded a solution, hence this post.

NoMachine's nxserver allows you to execute scripts upon certain events. So I used UserScriptBeforeLogin to create a file in /tmp with a name based on the IP address of the machine the session was being initiated from.

#!/bin/bash
# $1 is ip address login is coming from
touch /tmp/nxsessioncomingfrom_$1

pam_script can then check for the presence of that file to determine whether the login is an NX one or a regular ssh one. To do that check, pam_script has to know where the login is coming from. (You can't assume that a login happening via ssh is an NX session simply because the aforementioned file exists in /tmp since someone could  login via ssh at the same time someone else is logging in with an NX client.) pam_script gets given the username of the user logging in as an argument. My first thought was to make pam_script look at the output of 'who' to find the IP address that user was logged in from. However I discovered that a user logged in via NX does not show up in the output of 'who'. They're listed in the output 'usr/bin/utmpdump < /var/run/utmp', but not in the output of 'who'. I expect there's some technical reason for that but I lost patience with trying to find out what it is. (If someone logged in via NX opens an interactive shell session, say by running gnome-terminal, then they do show up in the output of 'who'.) [Update: See note below regarding output of 'who'] So I needed to find another source of information abuot where the user was logging in from.

The only place I could find this information was in /var/log/messages. The NX Server writes an entry there that looks like:

Oct 26 09:40:00 foohost NXSERVER-3.4.0-8[25571]: User 'xxxxx' logged in from '137.205.xxx.xxx'. 'NXLogin::set'

Having located that, pam_script can determine whether the user logging in is coming from the same IP address as the file in /tmp indicates an NX session is coming from like so

ip=$(grep NXSERVER /var/log/messages  | grep "User '$1' logged in from" | tail -1 | awk '{print $11}' | sed "s/'//g;s/\.$//g")

if [ ! -f /tmp/nxsessioncomingfrom_${ip} ];then
# if the file isn't there then exit the script
# no reason for 34 other than it's distinctive for testing purposes
exit 34
else
# if the file is there then delete it and continue
rm -f /tmp/nxsessioncomingfrom_${ip}
fi



Update: I worked out why users don't show up in the output of 'who'. It's because sessreg isn't being run when they log in. To get sessreg to run you need to edit /usr/NX/etc/server.cfg and set the value of CommandSessreg to the location of sessreg. Search for CommandSessreg to find the placeholder. I haven't yet bothered to check whether sessreg runs early enough to make the need for UserScriptBeforeLogin redudent.



Search this blog

Tags

RSS2.0 Atom
Not signed in
Sign in

Powered by BlogBuilder
© MMXXIV