Friday, March 19, 2010

Gadgets

Two new gadgets in the eq stashbag: asus eee and nexus one. I really like android...

Wednesday, May 30, 2007

IRC RSS Aggregator Bot

I wanted a IRC RSS Aggregator bot and did not find any on the allmighty web, so I had to create my own. It is written in Perl and uses POE::Component::IRC and POE::Component::RSSAggregator. Here is the code:
#!/usr/bin/perl
use strict;
use warnings;
use POE;
use POE qw(Component::IRC);
use POE::Component::RSSAggregator;
$|++;

# Config.
my $rss_config = 'rss.cfg';
my $rss_config_saved = 'rssc.cfg';
my $nick = 'rssbot';
my $server = 'irc.myircnet.net';
my $port = 6667;
my $name = 'IRC RSS aggregator bot, by septic';
my @channels = ();


my @feeds = ();
my %globalheadline;
my %counter;

open(CONFIG, "<$rss_config");
while(<CONFIG>){
next if(/^#/);
$_ =~ s/\n//;
my @vals = split / /, $_;
push @feeds, { url => $vals[0],
name => $vals[1],
delay => $vals[2],
};
}
close(CONFIG);

foreach(@feeds) {
print $_->{url}." ";
print $_->{name}." ";
print $_->{delay}."\n";
}

my $irc = POE::Component::IRC->spawn(
nick => $nick,
server => $server,
port => $port,
ircname => $name,
) or die "Oh noooo! $!";

POE::Session->create(
package_states => [
'main' => [ qw(_default _start irc_001 irc_public irc_msg) ],
],
heap => { irc => $irc },
);

POE::Session->create(
inline_states => {
_start => \&init_session,
handle_feed => \&handle_feed,
},
);


$poe_kernel->run();
exit 0;
sub init_session {
my ( $kernel, $heap, $session ) = @_[ KERNEL, HEAP, SESSION ];
$heap->{rssagg} = POE::Component::RSSAggregator->new(
alias => 'rssagg',
debug => 1,
callback => $session->postback("handle_feed"),
tmpdir => '/tmp', # optional caching
);
$kernel->post( 'rssagg', 'add_feed', $_ ) for @feeds;
}

sub handle_feed {
my ( $kernel, $feed ) = ( $_[KERNEL], $_[ARG1]->[0] );

for my $headline ( $feed->late_breaking_news ) {
my ($name,$feedname) = split /:/,$feed->name;
if(not exists $counter{$name}) {
$counter{$name} = 0;
}
$globalheadline{$name.($counter{$name}%5)} = $headline;
$irc->yield( privmsg => $name => ($counter{$name}%5)." ".$feedname.': '.$headline->headline);
$counter{$name} = $counter{$name} + 1;
}
}
#IRC
sub _start {
my ($kernel,$heap) = @_[KERNEL,HEAP];

# We get the session ID of the component from the object
# and register and connect to the specified server.
my $irc_session = $heap->{irc}->session_id();
$kernel->post( $irc_session => register => 'all' );
$kernel->post( $irc_session => connect => { } );
undef;
}

sub irc_001 {
my ($kernel,$sender) = @_[KERNEL,SENDER];

# Get the component's object at any time by accessing the heap of
# the SENDER
my $poco_object = $sender->get_heap();
print "Connected to ", $poco_object->server_name(), "\n";

# In any irc_* events SENDER will be the PoCo-IRC session
$kernel->post( $sender => join => $_ ) for @channels;

undef;
}

sub irc_public {
my ($kernel,$sender,$who,$where,$what) = @_[KERNEL,SENDER,ARG0,ARG1,ARG2];
my $nick = ( split /!/, $who )[0];
my $channel = $where->[0];

if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
#$rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
#$kernel->post( $sender => privmsg => $channel => "$nick: $rot13" );
#$irc->yield( privmsg => $nick => $rot13);
}

undef;
}
sub irc_msg {
my ($kernel,$sender,$who,$where,$what) = @_[KERNEL,SENDER,ARG0,ARG1,ARG2];
my $nick = ( split /!/, $who )[0];

print "$nick: $what\n";

if(my ($val) = $what =~ /^info (\d)/) {
if(exists $globalheadline{$nick.$val}){
$irc->yield( privmsg => $nick => $globalheadline{$nick.$val}->headline);
$irc->yield( privmsg => $nick => $globalheadline{$nick.$val}->description);
$irc->yield( privmsg => $nick => $globalheadline{$nick.$val}->url);
} else {
$irc->yield( privmsg => $nick => "There is no information about $val.");
}
} elsif(my ($val) = $what =~ /^add (.+)/) {
my @thing = split / /,$val;
if(@thing != 3) {
$irc->yield( privmsg => $nick => 'add <url> <desc> <delay>');
} else {
if ($thing[0] !~ /http:\/\/[\/\w\s\d\.]*/i) {
$irc->yield( privmsg => $nick => 'Invalid URL');
} elsif (($thing[2] !~ /\d/) && ($thing[2] > 60)) {
$irc->yield( privmsg => $nick => 'Bad delay, should more than 60');
} else {
$irc->yield( privmsg => $nick => "OK $thing[0] $thing[1] $thing[2]");
my $mojt = { url => $thing[0],
name => $nick.":".$thing[1],
delay => $thing[2],
};
push @feeds, $mojt;
$kernel->post( 'rssagg', 'add_feed', $mojt );

open(CONFIG, ">$rss_config_saved");
foreach(@feeds){
print CONFIG $_->{url}." ";
print CONFIG $_->{name}." ";
print CONFIG $_->{delay}."\n";
}
close(CONFIG);
}
}
} elsif($what =~ /^help/) {
$irc->yield( privmsg => $nick => "This is the rss aggregator bot");
$irc->yield( privmsg => $nick => "Add a feed");
$irc->yield( privmsg => $nick => "add <url> <desc> <delay>");
$irc->yield( privmsg => $nick => " ");
$irc->yield( privmsg => $nick => "Information about a post");
$irc->yield( privmsg => $nick => "info <id>");
} else {
$irc->yield( privmsg => $nick => 'Write "help" if you want help.');
}

undef;
}

# We registered for all events, this will produce some debug info.
sub _default {
my ($event, $args) = @_[ARG0 .. $#_];
my @output = ( "$event: " );

foreach my $arg ( @$args ) {
if ( ref($arg) eq 'ARRAY' ) {
push( @output, "[" . join(" ,", @$arg ) . "]" );
} else {
push ( @output, "'$arg'" );
}
}
print STDOUT join ' ', @output, "\n";
return 0;
}



The config file for the rss should look like this:
#url nick:name delay
http://www.slashdot.org/slashdot.rss mynick:slashdot 300

Sunday, April 22, 2007

6581

Now I have my own 6581! I have always liked the sound of SID, but have never had a C64 myself. Now I have bought a C64 and am going to do a project, much like the Parallel Port SID 6581 Synthesizer Chip Interface-project, but with USB and microcontroller instead.

Thursday, April 19, 2007

SID

I completed a .sid yesterday with Goattracker. MacFist did I call it, also did a wave version for those who don't have a 6581 sid chip, or a decent emulator to play it on. :)

Wednesday, April 4, 2007

WEP is f**ked

I saw this post at /. WEP Broken Even Worse where some guys in germany have found an even faster way than the aircrack guys. Ofc it is based on aircrack, but it is much faster. With some ARP injects and some deauths a net is forced really fast. I don't want to tell if i tried it myself. If you know my curiosity you can go figure yourself!

Wednesday, March 14, 2007

Zilog Z80


Found some very nice programs for my old TI-82 that i copied to it today. I also found a guide for making your own Z80 .asm programs. The best TI source is definately www.ticalc.org.

Monday, February 19, 2007

Opera

Mouse gestures in Opera are nice. But if you dont use them they are difficult to remember.. A few is nice to know. Especially the commands you do frequently when you are surfing the big waves of the web.