s5h.net

“fresh linux news and advice.”


puce2006-10-22 andrew fs

More of a note than anything else, I will be putting some time into writing a guide for AFS newbies in the comming weeks. I feel strongly that this file system offers much for people who wish to spread their network files around mutliple sites.

puce2006-10-19 id3 tags

iPod nano relies heavily on id3 tags in order categorise audio files in it's database. That's ok I suppose, whats wrong with using directory organisation? /path/artist/album/track.mp for instance? That's besdies the point really, not everything that is available for purchase and download is in this format. Here is a script that adds tags to files in the following format:

tacknumber_artist_-_album_-_track name.mp3

and the script is nothing major

#!/usr/bin/perl

use strict;
use warnings;

sub recase {
	my $val = shift;
	$val =~ s/_/ /g;
	return( lc($val) );
}

opendir( D, "." ) or die( "could not open dir: $!" );
while( my $r = readdir(D) ) {
	next if( $r eq "." || $r eq ".." );
	next if( $r !~ /^([0-9]{2})_(.+)_-_(.+)_-_(.+)\.mp3$/ );
	my $track = recase($4);
	my $art = recase($2);
	my $alb = recase($3);	

	my $g = "rock";
	my $cmd = "/usr/bin/id3 -t '$track' -T '$1' -a '$art' -A '$alb' -g '$g' '$r'";
	print( "$cmd\n" );
	`$cmd`;

}
closedir(D);

puce2006-10-16 google code errors

I've seen one or two pages showing some programming errors that are interesting, here's my attempt at compiling them into a single post.

  1. memcpy errors
    the man page shows this as
    void *memcpy(void *dest, const void *src, size_t n);
    obviously the programmer has the parameters in the wrong order
  2. backdoor passwords
  3. this will crash
  4. python sucks
    substitute with your own favourite language
  5. drunk coder
    add your own 'high' keywords
  6. klude
  7. disgruntled employee
    i hate my life
  8. fix this
    lots of people already do searches for FIXME etc
  9. it's the user's fault
  10. of course we own it
    stolen code
    you are not expected to understand this
    i've no idea what this does
    what does this do?
  11. dragons here
    general joke
  12. potential buffer overflow
  13. naughty words

puce2006-10-14 signals

For anyone who has perl installed and is a cable modem user might find it useful to configure mrtg and a perl script to retrieve signal strength values from the modem. This could help diagnose possible network creep issues where the signal weakens gradually over time.

Here is what I have come up with for this problem.

#!/usr/bin/perl

use strict;
use warnings;
use LWP;

# simple script to get signal values from a cable modem
# this returns the values based on paramter if specified
# parameters:
#
# 	up	prints the upstream signal
# 	down	prints the downstream signal
# 	snr	prints the siganl to noise ratio
#
# use permitted under the GNU GPL version 2 licence
#
# script by ed at s5h dot net
# http://s5h.net

my $url = "http://root:root\@192.168.100.1/P_configuration.htm";
my $b = LWP::UserAgent->new;
my $report;
my ($out,$in,$snr);

sub main {
	my $r = $b->get($url);

	if( !$r->is_success ) {
		die( "Could not get the page: $!" );
	}

	my @l = split( "\n", $r->content );
	foreach my $ll (@l) {
		if( $ll =~ /Upstream.*: (.+) dBmv/ ) {
			$out = $1;
		}

		if( $ll =~ /Downstream.*: (.+) dBmv/ ) {
			$in = $1;
		}

		if( $ll =~ /SNR.*: (.+) dB/ ) {
			$snr = $1;
		}
	}
	if( defined( $in ) && defined($out) && defined($snr) ) {

		if( $report != 0 ) {
			if( $report == 1 ) {
				print("$out\n");
			}

			if( $report == 2 ) {
				print("$in\n");
			}

			if( $report == 3 ) {
				print("$snr\n");
			}
			print( "0\n" );
		}
		else {
			print("Out:$out\nIn:$in\nSNR:$snr\n");
		}
	}

}

$report = 0;

if( defined( @ARGV ) ) {
	if( $ARGV[0] eq "up" ) {
		$report = 1;
	}

	if( $ARGV[0] eq "down" ) {
		$report = 2;
	}

	if( $ARGV[0] eq "snr" ) {
		$report = 3;
	}
}

main();

The above script is called periodically from the following mrtg config

Title[cmds]: FQDN cable modem signal (in)
MaxBytes[cmds]: 1000
AbsMax[cmds]: 100000
Options[cmds]: gauge,growright
Target[cmds]: `/usr/bin/perl /home/ed/code/perl/cablemodem/cablemodem.pl down`
PageTop[cmds]: <B>FQDN cable modem signal downstream</B><BR>
ShortLegend[cmds]: &nbsp;
YLegend[cmds]: hour
Legend1[cmds]: &nbsp;
LegendI[cmds]: &nbsp;
LegendO[cmds]: &nbsp;
WithPeak[cmds]: ymwd
XSize[cmds]: 350
YSize[cmds]: 150

Title[cmus]: FQDN cable modem signal (up)
MaxBytes[cmus]: 1000
AbsMax[cmus]: 100000
Options[cmus]: gauge,growright
Target[cmus]: `/usr/bin/perl /home/ed/code/perl/cablemodem/cablemodem.pl up`
PageTop[cmus]: <B>FQDN - cable modem signal upstream</B><BR>
ShortLegend[cmus]: &nbsp;
YLegend[cmus]: hour
Legend1[cmus]: &nbsp;
LegendI[cmus]: &nbsp;
LegendO[cmus]: &nbsp;
WithPeak[cmus]: ymwd
XSize[cmus]: 350
YSize[cmus]: 150

Title[cmsnr]: FQDN cable modem signal noise ratio
MaxBytes[cmsnr]: 1000
AbsMax[cmsnr]: 100000
Options[cmsnr]: gauge,growright
Target[cmsnr]: `/usr/bin/perl /home/ed/code/perl/cablemodem/cablemodem.pl snr`
PageTop[cmsnr]: <B>FQDN - cable modem snr</B><BR>
ShortLegend[cmsnr]: &nbsp;
YLegend[cmsnr]: hour
Legend1[cmsnr]: &nbsp;
LegendI[cmsnr]: &nbsp;
LegendO[cmsnr]: &nbsp;
WithPeak[cmsnr]: ymwd
XSize[cmsnr]: 350
YSize[cmsnr]: 150

If you do have a problem with your network, there's always the auto network trouble page to give possible causes.

puce2006-10-12 windows is not hardware ready

Today I'm amazed for three reasons

  1. amazon.com
    a few weeks ago i placed an order for three books with amazon.com as they were not available from the .co.uk variant
    1. Dragon Fire
    2. The Haskell Road To Logic, Maths And Programming
    3. In the Line of Fire: A Memoir
  2. ebuyer.com
    on Tuesday I placed an order for an ipod nano
  3. ipod integration

What arrives first? The order from the states, or the ipod from the same country where I live? Yea, that's right the order from the states came here first!

My mental plan for today was to see what the ipod does in windows via itunes and one way or another debug that and reproduce the same procedures on linux... That would be a good plan, except for a major problem. The ipod fails to work in XP. Firs I thought it was qemu and a usb issue, but that later turned out to be that itunes just does not work right, or I could not use it right, one of the two. So I did some reading, found that there's already a library on linux for this sort of thing and away I go, loads of ideas for working my own set of routines for synchronisation.

So, I have my ipod, but where is the arm holster for it that I ordered from ebay! I hate it when a plan doesn't come together.

The nano I ordered is the 4GiB variety, this is a huge improvement from a Rio which I had some years ago (10 maybe?) that could store only 32MiB on the internal flash, and read up to 64MiB of external flash. How did I cope with that? Now I have room for any old junk on there, but already I might have to cut back a little. Perhaps the extra few quid for 8GiB would have been a better choice?

puce2006-10-11 who would award a ...

... adware author thats right ms would.

puce2006-10-05 how much uptime?

How long has that box really been running? The system counter in Linux only counts to 497 days (2^32 / 60 / 60 / 24 / 10). The file /proc/kmsg holds the file date when the system was turned on and the kmsg file was created.

A=$( stat -c %Y /proc/kmsg );
B=$( date +%s );
echo $(( ( $B-$A ) / 60 / 60 / 24 ))

600 days comming up!

puce2006-10-03 russian education

The first class (last Thursday) was a total shock for me in many ways. Firstly, days of being a student a long behind me, my classroom behaviour is not what it used to be. Secondly, I've totally forgotten what it's like to be in a class and to be a less informed person. Day to day, I am very confident in what I do, this was a real eye-opener.

Learning Russian is not like learning pascal, perl, c, java or any other language that I have eaten my way through the syntax of.

Make no mistake, learning a spoken language is hard work.

puce2006-10-01 make-kpkg faster

Recently after a few kernel tweaks I decided to change some of the build concurrency levels. Since the slowest bottle neck of building a kernel is the disk IO, setting a concurrecy of make to something higher than 1 should allow a build to operate while another build process awaits disk IO.

To test this, run

$ sudo bash
# export CONCURRENCY_LEVEL=5
# make-kpkg kernel_image --initrd

(Substitute the make-kpkg arguments with your own).

        pucegvim

The following vimrc has grown on me.

set number              " show the current line number
set autoindent          " make block indents
set ts=8                " set the tab stops
set sw=8                " set the shift width
syntax enable           " enable syntax highlighting
colors torte            " set the colour scheme
set backspace=indent,eol,start " backspace goes wraps lines
set showcmd             " Show (partial) command in status line.
set showmatch           " Show matching brackets.
set ignorecase          " Do case insensitive matching
set smartcase           " Do smart case matching
set incsearch           " Incremental search
set autowrite           " Automatically save before commands like :next and :make
set hidden              " Hide buffers when they are abandoned
set mouse=a             " Enable mouse usage (all modes) in terminals
set background=dark     " background colour
set ru                  " set the ruler
set textwidth=72        " set the wrapping width
set antialias           " font antialias
set encoding=utf-8      " file format encoding
set spell               " set the spell checker (needs aspell)