Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Sunday, January 11, 2009

Renaming MP3 by ID tag

Ever tried to recover from an IPOD dump, and get a bunch of files with the useless names? Here's a script to fix that.
$ ls *.mp3 | ./rename.pl - | while read line; do OLD=`echo $line | cut -d, -f1`; NEW=`echo $line | cut -d, -f2`; mv "$OLD" "$NEW"; done

And here's the perl script:

#!/usr/bin/perl
#
#Your Love Means Everything.mp3: (tag v1.0)
#songname: Your Love Means Everything
#artist: Coldplay
#album: Varie
#year:
#comment:
#genre: Other(12)
#

while( <> )
{
chomp;
my %hsh = ();
my @info = `id3ed -i "$_"`;
foreach my $iline ( @info )
{
chomp $iline;
#print $iline . "\n";
if( $iline =~ /songname:\s+\b(.+?)$/ ){
$hsh{ song } = $1;
}
if( $iline =~ /artist:\s+\b(.+?)$/ ){
$hsh{ artist } = $1;
}
if( $iline =~ /album:\s+\b(.+?)$/ ){
$hsh{ album } = $1;
}
}

my $newname = "$hsh{ artist }" . "-" . "$hsh{ album }" . "-" . "$hsh{ song }" . ".mp3";
$newname =~ s/\s+/_/g;
print "$_,$newname\n";
}

Monday, January 05, 2009

Autologging in and running app in X

I've been keen on doing this for some time, but a combination of:
  1. lack of need
  2. lack of time
have kept me from doing any real testing on a good solution. But someone has already done the work!

Wednesday, December 10, 2008

My first fvwm module

I've been using FVWM for some time now, but have never tried writing any kind of modules to extend it. Yesterday I tried it out, and I've got my first working FVWM module.



I wrote the module in Perl, and you can view there source here. Basically what it does is capture window focus events, and will set the transparency of the window to whatever is set in a configuration file
pblair@laptop:~$ cat ~/.fvwm/fvwmPeteTrans.cfg
XTerm:0.60
The above config will set all xterminals to 60% opacity when the focus moves away from it, but will return it to complete opacity once focus returns to it.

You can add as many types of applications (one per line). For instance, Firefox has
$ xprop | grep CLASS
WM_CLASS(STRING) = "Navigator", "Firefox"
So you could either place "Navigator" or "Firefox" at the left of the colon.

To install the module, place it somewhere where the .fvwmrc ModulePath will find it, then place it into the StartFunction section:

AddToFunc StartFunction
+ I Module FvwmPeteTransFocus
+ I FvwmButtons
P.S. You need "xcompmgr" and "transset" installed. And be sure to change the absolute pathnames within the module to the respective locations on your system.

Tuesday, December 09, 2008

Guerilla Refactoring

In the world of software development, refactoring is the process of updating code (usually for the better). But the problem may exist where management sees the existing application as "good enough" and doesn't want to allocate any budget towards fixing what in their eyes "aint broke".

Enter guerilla refactoring.

I must admit that I fall victim to this. I find lots of things at work that could be expanded upon, or made better, which would drastically increase the use of the package, make it more robust, or simply more elegant and orthogonal. I ensure that it doesn't eat into my work time, and the end product is usually something that I will directly benefit from, but hopefully also something that will make someone else's life better/easier/simpler.

P.S. I recommend this podcast from NPR.

Saturday, March 24, 2007

Perl programmer, who me?

Yikes-- it's true. Just purchased Programming Perl, 3rd Ed., from Chapters and am starting to pick it up.

First impressions: It's a damned ugly language to work with, but is very flexible, so I understand why so many sys-admins love it; you can really hack together a quick and dirty application in no time flat.

We'll see how much I like it as time goes.

Saturday, December 30, 2006

Spammers... damned spammers

Here's a screenshot of a little python application that I wrote to manage some spammers on the system. I've 'sed'ed their domains to example.com, but it basically shows how many messages are currently queued on one of our outbound smtp servers.

Every shift, I run an application that monitors the queues, and when an individual account exceeds the maximum number of allowed egress messages, my application logs it, and removes it from the queue.

But, spammers are smart little buggers, so they of course create multiple accounts from which they spam a little bit from.

My software is smart enough that it keeps track of all found spammers from the past 30 days, and simplifies their email address, then compares that to all of the email addresses in the current out queue. If the simplified "known spammer" address matches any of the current addresses, then those current addresses are treated as a single address and their queues are aggregated. If the aggregate exceeds the threshold, then all messages are removed and the synonymous accounts are flagged as spammers for later termination.

Note: The addresses in the above screen cap are the ones that come out of the filter against the known/previous offenders. Only usernames that have been previously declared spammers are aggregated.

Oh, and here's a little graph showing the outbound message queue on a single server. The drop was when I started work that day.




Wednesday, October 25, 2006

Python: Functional programming

I'm trying to get used to functional programming and I must admit, it's kinda fun!

Here's a trivial example using both generators, and built in functions to acheive the same result: