July 16, 2010

Windows Live and Droid font problem

In which I use the word Droid more than once but resist working in a Star Wars reference. Except for that one.

I logged in to Windows Live earlier using the test account I have access to ahead of the Student email migration to Live@Edu and was dismayed to discover the text was pretty much unreadable.

live.com_droid_font_1.png

Last time I logged in, which was probably a few weeks ago, it was fine. Some digging with Firebug reveals that the CSS for the page specifies this for the font family

live.com_firebug.png

As luck would have it I happen to know that I have a font called Droid installed on my computer. I'm using SUSE Linux Enterprise Desktop and it's one of the many fonts provided in the free-ttf-fonts package. That font looks like this

droid_gnome_font_viewer.png

Which explains why the Windows Live webpage text is unreadable. Firefox is doing exactly what it should be doing in the circumstances. It's looking at the list of font families specified in the CSS, finding that the first family specified in the list is available and using it. Unfortunately in this case the Droid font is not suitable for use at the size being specified and the result is text that is mostly unreadable.

Since I've had that Droid font installed for ages and the Windows Live page used to display fine, I can only assume Microsoft have added the mention of Droid to the CSS very recently. I'm guessing it was done for users on Android devices as Android comes with a font called Droid which looks nothing like the one I have installed and would be perfectly suitable for use on the Windows Live page.

So what to do about this? My first thought, renaming the file that provides the Droid font (/usr/share/fonts/truetype/droid___.ttf), doesn't work becase the name of the font is independent of the filename. You can call the file whatever you like but it still contains a font called Droid. I could probably write a Greasemonkey script to remove the mention of Droid from the CSS but the solution I've gone with for now is to just remove the font by deleting /usr/share/fonts/truetype/droid___.ttf



May 19, 2010

Getting a random word in a bash script

Earlier I got to wondering if there was an easy way to get a random word in a bash script. My first thought was

$ sort -R /usr/share/dict/words | head -1

That works but takes over ten seconds. The first Google hit I got was this page which suggets:

#!/bin/sh
WORDFILE="/usr/share/dict/words"
NUMWORDS=5
#Number of lines in $WORDFILE
tL=`awk 'NF!=0 {++c} END {print c}' $WORDFILE`
for i in `seq $NUMWORDS`
do
rnum=$((RANDOM%$tL+1))
sed -n "$rnum p" $WORDFILE
done

Which works, but only returns words that start with a b or c. The problem is that bash's $RANDOM is a number between 0 and 32767 and there's many more words than that in /usr/share/dict/words.

I didn't find any better suggestions so after a bit of fiddling I came up with this.

#!/bin/bash
WORDFILE=/usr/share/dict/words
# seed random from pid
RANDOM=$$;
# using cat means wc outputs only a number, not number followed by filename
lines=$(cat $WORDFILE | wc -l);
rnum=$((RANDOM*RANDOM%$lines+1));
sed -n "$rnum p" $WORDFILE;


The maximum value of multiplying two values of $RANDOM is greater than the number of lines in /usr/share/dict/words thus the problem of only getting back words starting with a b or c is eliminated.

Some time later, whilst looking at something else I came accross reference to the shuf command. Turns out that does much the same as 'sort -R' only much faster (around 0.2 second). So if you want a simple and fast way to get a random word in a bash script all you need is:

$ shuf -n1  /usr/share/dict/words

Edit: Assuming you're using a *nix machine which has shuf installed. shuf is part of GNU core utilities so it should be included in any randomly chosen Linux install. It's not included in Mac OS X (at least not Leopard which is what I have to hand) though or Solaris 10. Mac users could get shuf by installing the coreutils package that's available via MacPorts.


May 06, 2010

Vote!

Writing about web page http://news.bbc.co.uk/1/hi/uk_politics/election_2010/8661984.stm

Go on, vote. Some tips on what you're not allowed to do in a polling station are linked above.


April 29, 2010

O2 Joggler shell script strangeness

Last night I took delivery of an O2 Joggler which I ordered whilst they were recently on offer for £50. The offer exhausted O2's stock so I had to wait a couple weeks for mine to arrive. I didn't buy it for what O2 advertise it as, I bought it for what is is as piece of hardware. Inside is an Intel Atom Z520, 512MB ram, 1GB of storage and a wireless adaptor. Visible on the outside are an Ethernet port, 3.5mm headphone jack, USB port and a 7" 800x480 touch screen. Oh and a small sticker indicating it's 'powered by openpeak'. It runs Linux. I've seen people say that the Linux is a cut down Ubuntu 8.04 though I've not been able to find any proof of this. It very definitely has BusyBox on there though. Put some special files on to a USB flash drive, plug it in, boot the device and you have telnet access and can mess around with it's OS. You can also make it run a different OS off a flash drive. So, a neat little box that should be fun to play with. The Joggler has been around for nearly a year so there's already several forums out there already on the subject and the recent £50 offer has inevitably fuelled interest.

So far my biggest hack is to enable ssh access to it. Next will be installing scp so I can copy files/to from it easily. Earlier on I was having a bit of a general poke around in it, looking around the filesystem, seeing what processes were running and such when I discovered an interesting script. What makes it interesting are these three functions:

numDaysInMonth()
{
case $1 in
1|3|5|7|8|10|12)
echo 31
;;
2) echo $((28 + leap))
;;
4|6|9|11)
echo 30
;;
*) echo 0
;;
esac
}

parseTime()
{
set -- $(date "+%Y %m %d %H %M %S %Z")
Year=$1
CurMonth=`echo $2 | sed 's/^0//'`
Today=`echo $3 | sed 's/^0//'`
Hour=`echo $4 | sed 's/^0//'`
Min=`echo $5 | sed 's/^0//'`
Secs=`echo $6 | sed 's/^0//'`
Timezone=$7
}

# function to get a very close approximate to the number
# of seconds since epoch for use to mark app start time
# and, upon app exit, current time. The delta of current
# to start time is used to determine if the restart should
# be tallied or not by comparing to MinAppUpTime
##
calculateEpoch()
{
parseTime

# leap days in past years
##
leapdays=$(( (Year - 1969)/4 ))
leap=$(( Year % 4 == 0 ))

# days since the epoch, not counting earlier months this year
##
numDays=$(( (Year - 1970) * 365 + leapdays + Today - 1))

# step through earlier months this year and add the days
##
month=$((CurMonth - 1))
while [ ${month} -ge 1 ]; do
numDays=$(( numDays + `numDaysInMonth $month` ))
month=$(expr $month - 1)
done

# now the seconds...
##
epoch=$(( ( (numDays * 24 + Hour) * 60 + Min) * 60 + Secs ))

echo ${epoch}
}

The calculateEpoch function is later called like so:

startTime=`calculateEpoch`

I can't figure out why someone wrote all that code to get a 'close approximate', or to put it another way, incorrect, value for the number of seconds since epoch instead of using this to get the correct value:

startTime=`date +%s`

And yes, the BusyBox date function does allow that. If you happen to have a Joggler on which you've enabled shell access, the code in question appears in /openpeak/tango/xinit.sh


April 20, 2010

…Volcanoes

Writing about web page http://www.bbc.co.uk/iplayer/episode/b0074spx/10_Things_You_Didnt_Know_About..._Volcanoes/

Interesting programme about those volcano things the people on the news keep going on about recently. It's not new, but it's on iPlayer as it was repeated in the middle of the night a few days ago.


Why not have a child write it in crayon?

I recently opened an account with Santander. I just received an email confirming the account is open and conveying various pieces of important information. It's HTML formatted with all the text marked to display in Comic Sans. I'm tempted to close the account. Though maybe I'll settle for asking them to explain why a financial institution communicates with it's customers in a font that was designed for use in the speech bubbles of cartoon characters.


April 13, 2010

Vote for Gary's mother.

I popped in to the city centre on the way home from work earlier and my attention was drawn to a small group of people gathered around someone saying something, incoherent with distance, in to a microphone. Then I noticed there was a bunch of Police hanging around. On closer inspection the person with the mic turned out to be Jack Straw. For those of you who are currently thinking 'who?' he's the current Secretary of State for Justice. (Is it just me, or is 'Ministry for Justice' a rather sinister name for a government department?) It seemed a rather odd set up given the position in government he holds. There seemed to be just him and a couple of people holding signs with the Labour logo on them. Not holding them aloft placard style or anything, just holding them around chest height so they were mostly obscured by the spectators, even when you got close. He wasn't on any kind of stage or raised area. Not even an old soap box. Maybe it was supposed to be some sort of connecting with the common people type exercise. Odd.

I've just remembered I've actually spoken to Jack Straw on a previous encounter. Well I say talked. He asked me for a malt whiskey. He was Home Secretary at the time and I was a barman at Scarman House. He wandered off without paying.


April 06, 2010

Got ISA?

If you've got an ISA find out what the interest rate is on it. Don't look on the website, phone them and ask. I just found out I'm getting a shockingly pathetic 0.3% on mine and feel like a fool for not checking sooner. I might as well have been keeping it in my sock draw. The good news is you can transfer them.


March 24, 2010

Some grease for the SeeSaw

Follow-up to SeeSaw (see what they did there?) from Mike's blag

It was only this morning that I got around to actually watching a programme on SeeSaw. It works just as you'd expect and it all seems good except for one glaring omission; There is no facility to pop the video out in to a new smaller window on it's own like there is on BBC iPlayer. Apparently such a feature is under consideration, but I consider it a pretty much essential feature so I whipped up a Greasemonkey script that adds it. So if you're using Firefox, have Greasemonkey installed and wish SeeSaw had a pop out feature, then click here. With the script installed the words 'Pop out' appear in the top centre of a programme's page.

If you have the Flashblock extension installed then that will mess up the script unless you've added seesaw.com to your whitelist.


March 23, 2010

Digital Economy Bill (Act now if you can be bothered).

Writing about web page http://www.guardian.co.uk/media/2010/mar/22/digital-economy-bill

There's a lot of talk in the media (maybe not as much as there should be) about how it appears that current government is attempting to get the Digital Economy Bill enacted before the next general election. The bill covers quite a lot of things including the switch of of analogue radio (does you car have a DAB receiver? no, mine neither), what Channel 4 should do, the role of Ofcom, a £6 annual tax on phone lines to help pay for the development of broadband infrastructure and the part which is causing a lot of controversy; How to deal with online piracy. This is the part which would seem to allow people's Internet connections to be cut off due to alleged copyright infringement.

The imminence of the next general election, (consensus seems to be some time in May), means that the bill may not get a proper debate in parliament. It would be rushed through. This is clearly not a good thing especially given some of the proposals in the bill. One member of the House of Lords has described it as "a complete and absolute abuse of parliamentary process". Parts of the bill appear to have been essentially written by the British Phonographic Industry.

Whether the bill gets a proper debate or not will essentially be decided on Thursday. So if you use the Internet and you think that a bill which may potentially affect your usage of it should be properly discussed in parliament, now appears to be the time to speak up by either contacting your MP or writing to Harriet Harman, Leader of the House (via, read this advice regarding form letters first).



Search this blog

Tags

RSS2.0 Atom
Not signed in
Sign in

Powered by BlogBuilder
© MMXXIV