Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gav (2710)

  (email not shown publicly)
AOL IM: flufflegavin (Add Buddy, Send Message)

Hacker in NYC.

Journal of gav (2710)

Wednesday April 02, 2008
09:08 AM

On misunderstanding copyright

I’m serious. Anyone who cherry-picks content from this piece without playing by the rule above can count on hearing from an attorney PDQ.

-- Tim Bray "On OOXML"

Consider this cherry-picking to discuss ludicrous copyright warnings against using excerpts. Tim please set your lawyers on me, this week is pretty boring.

Also see Fair Use.

Friday February 22, 2008
08:11 PM

Winter Scripting Games II

So far not doing great, missed the deadline of the 2nd and 4th events and was too hasty in submitting the 3rd to get it right.

This quiz is a good feeler for what Perl other people write, and if you look at the difference from the official solution, Jan Dubois', and mine, there's a world of difference looking at Perl written by a non-Perl programmer. It's strange and alien looking to me, and explains why people harp on about Perl's ugliness.

Anyway here is my (fixed) solution to Advanced Event 3: Instant (Runoff) Winner:

#!usr/bin/perl -w
use strict;
use List::Util qw( sum first );

my %C; # candidates

open my $in, '<c:/scripts/votes.txt'
    or die "Can't open 'votes.txt': $!\n";

while (1) {
    while (<$in>) {
        my @vote = split /,/;
        @C{@vote} = (0) x @vote if keys %C == 0;
        $C{$_}++ for first { exists $C{$_} } @vote;
    my @c = sort { $C{$b} <=> $C{$a} } keys %C;
    my $percent = ($C{$c[0]} / (sum values %C)) * 100;
    if ($percent > 50) {
        printf "The winner is %s with %.2f%% of the vote.\n", $c[0], $percent;
    delete $C{pop @c};
    @C{@c} = (0) x @c;
    seek $in, 0, 0;

close $in;

Thursday February 21, 2008
08:12 PM

Winter Scripting Games

I decided to enter the 2008 Winter Scripting Games. I managed to get full points for the first event but screwed up and didn't notice the deadline for the second.
Here's my entry for the first. It seems a bit simpler than Jan's solution and avoids an eval. I'll try to do a better job with commentary for the latter events.

#!/usr/bin/perl -w
use strict;

print "Enter phone number: ";
chomp(my $phone = <STDIN>);

my %letters;
    my @L = ('A' .. 'P', 'R' .. 'Y');
    my $n = 2;
    while (my @t = splice @L, 0 => 3) {
        $letters{$n++} = sprintf '[%s%s%s]', @t;

my $match = '^' . join('', map $letters{$_}, split //, $phone) . '$';

open my $in, '<c:/Scripts/WordList.txt'
    or die "Can't read wordlist: $!\n";
while (<$in>) {
    if (/$match/o) { print; last }
close $in;

Friday October 26, 2007
07:58 PM

Customer Service

In my inbox today:

Dear TiVo® Customer,
Yikes! We hate to be the bearer of bad news, but...

It seems that when I moved in the beginning of December 2005 instead of canceling my TiVo service I got a 3 month credit and ended up paying the $12.95 until May 2007 when I happened to cancel the credit card they used for automatic billing.

Now I owe them $12.95 for the month that they couldn't bill, even though they admit that my TiVo unit didn't transmit anything to them after November 24th 2005. As TiVo are all about customer service they gave me two options-- pay or go to collections. They are unable to issue a credit for the month that they were unable to charge me for the service I wasn't using.

I guess I'll have fun fighting the collections agency.

Friday October 19, 2007
06:07 PM

Wireless Extender

File under things-that-surprise-by-actually-working.

In my basement apartment I was unable to make cell calls with AT&T. Most of the time I'd just get "call failed" and it wouldn't go through.

The zBoost actually works. I attached the antenna on the outside of the building and ran the cable to the unit inside. I now get full bars and perfect phone calls. Can be picked up for around $230, not inexpensive but preferable to paying for a landline.

Sunday August 05, 2007
04:44 PM

Programming Erlang

I thought it would be a nice break from the Perl and C# programming I do at work to learn something new, and the Erlang seemed an interesting choice. I picked up Programming Erlang*.

It's a quiet Sunday, and I can learn about Erlang in lieu of chores. The problem is that this book is just boring. I've got through the first 150 of 383 pages (excluding appendices) and the author hasn't demonstrated a single program. The point of an introductory programming book is to evangelize and make your reader excited about solving their programming problems with this new language.

One of the things I don't think many people appreciate is just how good the llama and camel books are at getting people into Perl. I've read a lot of books about programming languages, and very few have sparked such motivation to want to learn more and start writing programs.


Saturday July 14, 2007
12:40 PM

Interesting spam tricks

Using Google's "I'm Feeling Lucky" feature to make links that take you straight to their website without having to include their url in the spam.
Wednesday June 27, 2007
11:51 PM

Business Activity Monitoring

Business Activity Monitoring is a fancy term for writing rules that look for problems in the systems that run your business and sending people messages messages to (hopefully) fix them.

It's something I've been working on for the last year, and it's something that's helped fix a lot of things that we were making mistakes with in the day-to-day running of the business. We have a system that runs a SQL query, takes out any rows it's seen before, then if there's any left feed it through a template and send an email.

It's allowed me to take every mistake that we've found in the way that we entered data into the system, or processes, and turn it into a rule that will catch it next time. This is something I've always been keen on, every time you catch a mistake it's a positive thing. Computers can have fun checking thousands of updated records every day, and humans can do more useful things with their time, or more importantly, grow the business without having to hire more people.

It's interesting to me as I never really worked with business systems before. Almost all my previous focus was in a very narrow part of the business, trying to make websites that made it easy for customers to place orders, and then giving that order to somebody and letting it be their problem. Now I get to think about purchase orders, tracking numbers, inventory counts, profit margins, etc, things that were somebody else's problem.

One of the things I've learnt about reporting is that if you can't be lazy then there isn't any point. Our accounting package has a whole bunch of useful reports, but they rely on somebody running them. Most of the checks I've added could have written a simple script to handle, but I can just copy and paste a SQL query into the tools GUI, check off the recipients, pick a schedule from a drop down list, and be done in a couple of minutes.

Monday June 18, 2007
09:33 PM

Square wheels

Why would somebody implement a database in a database? I've seen this anti-pattern a few times before and it's confusing to me, when do you wake up and say "obviously the answer is to put the data a database, but let's invent our own abstraction".

Instead of nice code that looks like:

SELECT some_value FROM some_table WHERE some_other_value = 'something';

Figure out how many SQL statements your poor database will have to execute if the schema looks like:

object(object_id, object_type)
object_type_to_attribute(object_type, attribute_id)
attribute(attribute_id, attribute_name, data_type)
table_bit(object_id, attribute_id, value)
table_string(object_id, attribute_id, value)
table_number(object_id, attribute_id, value)
table_text(object_id, attribute_id, value)

Friday June 15, 2007
09:36 PM

Signal to Noise

Email used to be a simple text* channel for the exchange of ideas. Of course, over time, like many channels the signal to noise ratio approaches zero.

I think the email I just received is a sign of impending doom. A simple message, just three short paragraphs containing 201 words. Unfortunately the alternative HTML rendering with leaf motif stationary increased this 1,222 byte message to 33,547-- 96.35% of the message was fluff.

* I remember the joys of UUDECODE.