Just Like Uni

Note: This entry has been restored from old archives.

My lordy, it’s just like Uni message boards :) And as usual Sam knows more.

At this time of the night after getting back from the local I’m not going to try to better any of that, and since it’s Sam it is probably foolish to try. Some points didn’t happen to apply to my “just now”, it’s is lucky my filenames had the decency to not contain spaces. Learnt something new about awk there, I fear my main weakness is sticking to the little I know until told off and given a better alternative! As for fmt, I didn’t know of an autoconf macro for getting to the thing (maybe it is so ubiquitous I shouldn’t need one), awk seems to be the defacto standard but these days bombing countries to death and sending in troops seems to be the defacto standard for making the world a better place, and nobody in their right mind actually thinks autoconf doesn’t kill puppies in its spare time.

Peter Weinberger? I never said he was the one I didn’t recognise! Sounds like a sausage in a bun to me… and means about as much ;) sam I am… not, actually, but Sam is so that’s okay I guess.

Shell scriptsi/aliases that do the job are so good, they save my poor old fingers, mine’s strangely called count and will soon probably be called add for both it’s accuracy and finger saving properties (I also have a count.pl that strangely does something completely different).

So much to learn…

awk awk awk!

Note: This entry has been restored from old archives.

I use awk a lot in my day to day work.

Just now: Do a subversion move of all files in the cwd to uppercase file names (I’m not going to explain why):

ls | awk '{u=toupper($1);if(u!=$1){system("svn move "$1" "u);}}'

And regularly I do things like: Get average size of files in a corpus:

find ./corpus/ -type f -exec stat {} ; 
        | grep 'Size:' 
        | awk '{c+=1;d+=$2}END{print d/c/1024 " kB"}'

Does it ever annoy you that grep doesn’t offer a total sum of matching lines?

grep -rihc 'foo' ./corpus/ | awk '{c+=$1}END{print c}'

Or that cut is only really useful with single char delimiters? The default awk delimiter is s+, so the second example above works as expected (and you can override the field separator with -F, even with simple regular expressions).

I’ve written some largish bits of code in awk before, it isn’t that far off using the likes of perl, but I’d generally recommend using more modern options for larger scripts[1] A sample of something I did in a fit of taking cross-platform too far[2] was to create an autoconf macro around this little monkey:

echo "The rabbit-hole went straight on like a 
tunnel for some way, and then dipped suddenly 
down, so suddenly that Alice had not a moment 
to think about stopping herself before she found 
herself falling down a very deep well." 
| awk -v width=50 -v pre='* ' '
BEGIN{
    line=pre;
}
{
    for (i = 1; i <= NF; i++)
    {
        if (length(line)+length($i) > width)
        {
            print line;
            line=pre;
        }
        line=line$i" "
    }
}
END{
    print line;
}'

I’ve modified it to make it into a hideous one-liner. In the original form it is an autoconf macro where the echoed string, the “pre” and the “width” are arguments. All to make failure messages that little bit neater.

What exactly does it do? Wraps a single line of text to a given width with a given prefix (in the process turning lumps of whitespace into single spaces), in this case the output is:

* The rabbit-hole went straight on like a tunnel 
* for some way, and then dipped suddenly down, so 
* suddenly that Alice had not a moment to think 
* about stopping herself before she found herself 
* falling down a very deep well.

Thank you awk (in fact in my particular case I should thank mawk).

There are plently of awk examples and docs out there.


[1] I don’t mean to slight awk too much, it is a complete programming language and is quite easy to work with. It’s been around since 1977 and was designed and written by Alfred Aho, Peter Weinberger and Brian Kernighan (you should recognise at least two of those names!).

[2] You never know, there might be a system out there somewhere without perl installed. The project only compiles on Linux? Hrm, but we have to be prepared for the future!

Flashy Shite

Note: This entry has been restored from old archives.

For a long time the good old Flashplayer plugin for Mozilla/Firefox has served me well, but don’t get me wrong: I hate flash as much as the next hippy. Recently I have found that more and more flash doesn’t work, it kind of works but important elements such as text are missing. The other thing that has pissed me off no end is all these sites that have embedded audio using flash and flash somehow bypasses the normal Linux volume control so I have to reach to the speakers to adjust the volume.

A solution to my flashy woes has been found though, the monkeys over at Adobe have a beta of Flash Player 9 for Linux. Better evil proprietary Internet for my browser, yay!

I do so wish the world would get over the stinking pile of turd that is “flash”, but with the current population explosion of horrid flash video and audio I doubt we’ll ever see the end of it.

Firefreeze

Note: This entry has been restored from old archives.

My recent experiences with Firefox 2.0 are less than ideal, I’m not using the latest release I’m using the version in Ubuntu’s Edgy. I’ve been checking apt for updates since upgrading and have been disappointed so far (I’d really prefer not to have to go outside the distro, going down that path one may as well roll-their-own).

My Firefox 2.0 keeps freezing, maybe it is one of my plugins doing the evil? I have no way of knowing… this is most upsetting. I got used to a Firefox that didn’t crash several times a day (unless you used a Java plugin in which case you’re on your own against some bodgey Java developer) sure it used huge wads of memory and strange amounts of CPU but I can live with that if it doesn’t bloody crash.

We’ll help Indonesia kill activists

Note: This entry has been restored from old archives.

It would seem that Australia agrees to let Indonesia do whatever they want to “suppress” the Papuan independence movement; that seems to be one of the points of a recent treaty. Ignore the headline nuclear bollocks, the stuff where we agree to help them suppress activists is far more interesting.

Of course, I don’t know how “evil” these activists are, for all I know it may be that they kill kittens and eat puppies. Plus I’ve only read an SMH report on the treaty, the actual document might be packed full of clauses that water it down and make it nothing more than the usual political fellatio.

Anyway, we can’t let poor old Indonesia loose a whole bunch of mineral and petroleum resources just because the area happens to be full of people who are inconveniently not Indonesian.

If you’re not like me and you’re willing to fight for a cause that is not my cause then I dub you terrorist; you will die.

Do It For The Mice

Note: This entry has been restored from old archives.

We do a lot of good work towards the betterment of mousekind, I sometimes wonder if we really are their subservient drones. Very often I read stories about how scientists somewhere think they have cured cancer in mice, made them live longer or simply worked out how to grow a fashionably decorative ear on their backs. Do a mouse a good turn today, give it a hearty meal of red wine, grapes and nuts and then put it in the fridge.

These are truly exciting days to be a mouse.