Home

None of Them Knew They Were Robots

Recent Entries

You are viewing the most recent 5 entries

December 16th, 2003

04:36 pm: what kind of social software are you?

October 20th, 2003

03:01 pm:

October 9th, 2003

10:55 am: Fibonacci
They're writing Fibonacci programs over in the perl community... here is my -e contribution:
perl -le 's 220 1 12;1 while s e(\d+) (\d{1,4})$eqq[$& ].($1+$2)ee;print'
You can adjust how many numbers you get back by changing the quantifer on the second \d... to get up to 10 digit numbers, change {1,4} to {1,10}, etc

The above is ofcourse heavily inspired by the old classic prime number regexp, by Abigail:
perl -wle 'print "Prime" if (1 x shift) =~ /^(?!(11+)\1+$)/'
(give it a number as an argument)

I like perl :)

September 4th, 2003

07:00 am: LJ Scraping Exercise
Inspired by [info]ciphergoth's TrustFlow application, I recently set about to write a little LJ scraper of my own. I don't have any cool trust algorithms to offer, and what I'm doing isn't exactly rocket science... but it does provide a useful functionality that I don't think LiveJournal has on it's own (at least, I haven't found it yet anyway). And I had some fun writing it :)

My script tells you which LJ users you share the most interests with.

#!/usr/bin/perl -w
$L=10; die " usage: ./lj_interesting.pl ljusername
This script will show you the $L LiveJournal users whom you share the most 
interests with, and tell you what those interests are. It doesn't work as
well for really popular interests, as livejournal only shows the first 500 
users with a given interest, but the less common interests are probably 
more interesting anyway. This script is released in the public domain by 
the author, phyxeld. (notcopyright) 2003\n" unless $ARGV[0]; crawl(@ARGV);
sub crawl {
    my $user=shift;
    warn "Searching for users who share interests with $user ...\n";
    my @int=scrape($user,0); my $t=$#int+1;
    for $int (@int) {
        printf STDERR (qq"\x0d\x1b[K %3d%% [%-30s] request %d ".
        q[of %d "%s"], (++$i/$t*100),('*'x($i/$t*30)),$i,$t,$int);
        push @{$d{$_}},$int for (scrape($int,1));
    }
    print "\nUser '$_' has ",$#{$d{$_}}+1," common interests:\n   ",
        join(', ',@{$d{$_}}),"\n" for (grep { !m/$user/ && 0<$L--}
        sort {scalar @{$d{$b}}<=>scalar @{$d{$a}}} keys %d)
}
sub scrape { # scrape can do two things: @interests = scrape(user,0)
    my ($q,$w)=@_; my @r=(); #           @users = scrape(interest,1)
    $re=$w?qr[rinfo\.bml\?user=([\w+]+)']:qr[sts\.bml\?int=([\w+]+)'];
    my $u=$w?'interests.bml?int=':'userinfo.bml?user='; push @r, (m/$re/g) 
    for qx[curl "http://www.livejournal.com/$u$q" 2>/dev/null]; return @r;
}


Naturally, the more interests you have listed, the better your results will be... and the longer the script will take to run (so a visual progress bar is displayed while the script works). The added load on LJ could potentially get heavy if a lot of people ran this; there is one HTTP request sent out for each of your interests, plus one for your userinfo page. If this becomes a problem for LJ (I doubt it will), then I'll take it down. Due to my extreme laziness, I'm fetching the pages with curl, so you'll need that installed if you want to try this out. (Or replace the single occurance of the word curl in the source with wget -O -)

If anyone in [info]perl has any feedback about this script, I'd love to hear it. I'm cross posting this there and in my own journal.

Sample Output )

Current Music: Haujobb - Sinus Problem

August 17th, 2003

03:14 am: Best blonde joke ever.

Powered by LiveJournal.com