s5h.net

“fresh linux news and advice.”


puce2006-04-26 some cool videos

There's some videos from the Skolelinux meeting available for download. Descent quality, but not all are in English.

puce2006-04-24 best ... episode ... ever!

Today perhaps the best episode of LUGRadio was aired, really great work chaps. LUGRadio for those who don't know if a brilliant fortnightly radio show that takes most of the new and old from the open source scene and adds comedy. Really great. episode 49.

In other news I found this page on wikipedia: curly bracket languages, which at first might look a little boring, but for those who know C-based languages it can give one a little more scope to work with.

puce2006-04-21 how to report spam, the effective way

OK, getting spam is one thing, having it sent from within your own country via an ISP in your own country helps matters, e.g. phone calls to said ISP are not too expensive. Having just received many of these I feel that the account owner should be contacted. Failure of this can lead to only one thing in my eyes, contacting some people at SORBS/spamcop/spamhaus.

puce2006-04-19 web 2.0, whatever next!

There are blogs all around promoting the use of web2.0 but what really is it? Well there's no single definition to answer this as there is no standard, but what we do know is that it's all about syndication and communication. Sites that are web2.0 are really just a means of visitors assigning information to posts, such as applying tags. Most typically a web2.0 site will record off-site clicks, then syndicate with other blogger's pages, popular links soon get promoted.

So, why all the fuss you might ask? Well, it's only recently that all this group work can be pulled together. Look out for sites that support web2.0 if you are intersted in online communities. However, if you are just doing research, you might want to avoid them. It could well be the route to online drama.

        pucefunrun

I've been collared into doing a sponsored funrun. If you have anything besides dust in your pockets please sponsor me on this 3mile run. You can use the paypal link to the left of this page to pledge something. All proceeds go to CANCER RESEARCH UK.

puce2006-04-10 cue to sox commands

Don't you just hate it when your backup of a cd is just a cue file and a couple of .mp3's? I sure do. Converting back to .mp3 tracks can be a real hassle. First off getting back to the .wav is as simple as mpg321. But what next? Having one large wav is no good for the in-car-mp3 player. So I had to do some perl, there's no other option. Thankfully perl has some features of c, such as the time_t structure for converting a time in seconds to hours, mins, seconds, days etc.

#!/usr/bin/perl -W

use strict;
use warnings;

sub t {
  my @ti = gmtime( shift );
  return( "$ti[2]:$ti[1]:$ti[0]" );
}

my @lines;
my $album;
my $track;
my $title;
my $start;
my $file;
my $index;
my $performer;
my @trackdata; # 0 = number, 1 = title, 2 = performer, 3 = index

@lines = <STDIN>;

foreach my $line ( @lines ) {
  if( $line =~ /^\s+(TRACK) ([0-9]+) / ) {
    if( $2 > scalar( @trackdata ) ) {
      for( my $i=0; $i<$2 ; $i++ ) {
        $trackdata[$i][0] = -1;
      }
    }
    $trackdata[$2][0] = $2;
    $track = $2;
  }
  if( $line =~ /^(FILE) (")*(.*)("){1}/ ) {
    $file = $3;
    $file =~ s/mp3/wav/;
  }
  if( $line =~ /^(TITLE) (.*)$/ ) {
    $album = $2;
  }
  if( $line =~ /^\s+(TITLE) (")*(.*)("){1}/ ) {
    $trackdata[$track][1] = $3;
  }
  if( $line =~ /^\s+(PERFORMER) (")*(.*)("){1}/ ) {
    $trackdata[$track][2] = $3;    
  }
  if( $line =~ /^\s+(INDEX) [0-9]+ ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/ ) {
    $trackdata[$track][3] = ( $2 * 60 ) + ( $3 ) ;
  }
  
}

my $count = scalar( @trackdata );

for( my $i=0 ; $i<$count ; $i++ ) {
  next if( $trackdata[$i][0] == -1 );
  my $command;
  $command = "sox $file \"$trackdata[$i][0]_-_$trackdata[$i][1].wav\" trim " . t( $trackdata[$i][3] );
  if( $i < $count-1 ) {
    $command .= " " . t( $trackdata[$i+1][3] - $trackdata[$i][3] );
  }
  print( $command . "\n" );
}

This is more a first-draft that's never going to get a update, but it's here should anyone else get troubles reverting back to something useful. There's a real shortage of useful scripts for handling this, hence the conversion to/from wav. Of course getting from the sox output is just a matter of running mpg123 on the output.

puce2006-04-08 c strings

Posts are getting a bit thin on the ground lately. So, here's a quick string cat resizer in c. In most modern languages (perhaps all!) adding two strings together is a rather simple business of A = B + C, or A = B . C, or however your language does this. Most of the time in c one has some idea of how long the string is going to be prior to adding the two together. In some case one does not know this, or it would be much work to discover the likely length. In this example we can resize the pointer's memory during the cat (wouldn't it be nice if the strcat function did this automatically, but perhaps under a different name?).

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

char *stradd( char *root, char *branch ) {
  root = realloc( root, strlen( root ) + strlen( branch ) + 1 );
  strncat( root, branch, strlen( branch ) );
  return( root );
}

int main( int argc, char *argv[] ) {
  char *strptr = malloc( 1 );
  strptr = stradd( strptr, "hello" );
  strptr = stradd( strptr, " " );
  strptr = stradd( strptr, "world" );  
  printf( "%s\n", strptr );
  free( strptr );
  return(0);
}

        pucegobblemem.c

Here's something I knocked up to allocate memory, maybe to do some benchmarks with it. Using calloc forces the OS to zero the memory before returning the pointer. Give it a go on your own system, see what results you get.

#include <stdio.h>
#include <stdlib.h>

void help() {
  fprintf( stderr, "usage: gobblemem <size>\nwhere <size> is memory to gobble in k\n" );
}

int main( int argc, char *argv[] ) {
  unsigned long long val;
  void *ptr;
  if( argc < 2 ) {
    help();
    exit(1);
  }
  val = atol( argv[1] );
  ptr = calloc( val, 1024 );
  printf( "trying to allocate %ullMiB\n", val / 1024 );
  if( ptr != NULL ) {
    printf( "memory allocated successfully\n" );
    free( ptr );
  }
  else {
    printf( "could not allocate memory\n" );
  }
}

puce2006-04-03 perl sig

Just wanted to spend a few minutes to drop this in. I have been using a static signature for a while and changed my favourite mailer to use the output of a command as the signature text. This is what I've come up with.

#!/usr/bin/perl

my @lines; 
$lines[0] = "Regards, Ed                      :: ";
$lines[1] = ":\%s/\\t/        /g                :: ";
$lines[2] = ":\%s/Open Source/Free Software/g  :: ";

my @domains;
$domains[0] = "http://www.s5h.net";
$domains[1] = "http://www.bsdwarez.net";
$domains[2] = "http://www.linuxwarez.co.uk";
$domains[3] = "http://www.openbsdhacker.com";
$domains[4] = "http://www.keyra.co.uk";
$domains[5] = "http://www.keyraaugustiana.co.uk";
$domains[6] = "http://www.sexeh.net";
$domains[7] = "http://www.usenix.org.uk";
$domains[8] = "http://www.gnunix.net";
$domains[9] = "http://www.ednevitable.co.uk";

$lines[0] = $lines[0] . $domains[rand(scalar(@domains)) % 100]; 

my @me;
$me[0] = "proud";
$me[1] = "just another";

my @thing; 
$thing[0] = "unix"; 
$thing[1] = "linux";
$thing[2] = "perl"; 
$thing[3] = "python";
$thing[4] = "java"; 
$thing[5] = "bash"; 
$thing[6] = "c++";

my @type;
$type[0] = "person";
$type[1] = "hacker";

$lines[1] = $lines[1] . $me[rand(scalar(@me)) % 100] . " " . $thing[rand(scalar(@thing)) % 100] . " " . $type[rand(scalar(@type)) % 100];

print "$lines[0]\n";
print "$lines[1]\n";
print "$lines[2]Free DNS available\n\n";