Skip to content

Instantly share code, notes, and snippets.

- # Just assume HTTP::Headers is a blessed hash ref
- +{%$headers};
+ +{ map {$_ => $headers->header($_) } $headers->header_field_names };
@leedo
leedo / gist:4003808
Created November 2, 2012 19:30
AnyEvent directory scanner
sub scan_dir {
my ($path, $filter, $cb) = @_;
my (@queue, @matches);
my $cv = AE::cv;
my $enqueue = sub {
$cv->begin;
push @queue, shift;
};
@leedo
leedo / gist:3846894
Created October 7, 2012 02:33
randomize IP
diff --git a/lib/Alice/Role/IRCEvents.pm b/lib/Alice/Role/IRCEvents.pm
index 2c6e676..9dd0bf9 100644
--- a/lib/Alice/Role/IRCEvents.pm
+++ b/lib/Alice/Role/IRCEvents.pm
@@ -10,6 +10,13 @@ use Class::Throwable qw/InvalidNetwork DisconnectError ConnectError/;
our %EVENTS;
+# array of all our IPs
+our @IPS;
#!/usr/bin/env perl
use AnyEvent;
use AnyEvent::Redis;
use Plack::Request;
use v5.12;
my $redis = AnyEvent::Redis->new;
sub {
class Plugin {
meta {
has @commands;
method command {
my ($command, $callback) = @_;
push @commands, [$command, $callback];
}
}
}
#!/usr/bin/env perl
use v5.10;
use Test::TCP;
use AnyEvent::Handle;
say "hit Ctrl-C to cancel";
my $cv = AE::cv;
my $s = AE::signal INT => sub { unlink "/tmp/$_" for qw/redis.conf dump.rdb/; $cv->send };
@leedo
leedo / extract.pl
Created August 13, 2012 19:55
mirror files from old CDN
#!/usr/bin/env perl
use DBI;
my $dbh = DBI->connect("DBI:mysql:database=x", "x", "x");
my $pattern = "%media.arstechnica.com%";
my $sth = $dbh->prepare("SELECT entry_text, entry_text_more FROM mt_entry WHERE entry_text LIKE ? OR entry_text_more LIKE ?");
$sth->execute($pattern, $pattern);
$('div[id*="taxonomy-"]').find('input[type="checkbox"], input[type="radio"]').live('change', function(){
setTimeout(function() {
acf.data.taxonomy = ['0'];
$('div[id*="taxonomy-"] input:checked').each(function(){
acf.data.taxonomy.push($(this).val())
});
update_fields();
}, 0);
sub cleanup {
my $cv = AE::cv;
for my $irc ($self->ircs) {
$cv->begin;
$irc->reg_cb(disconnect => sub { $cv->end });
$irc->disconnect;
}
#!/usr/bin/env perl
use strict;
use warnings;
use HTML::Parser;
my $len = 0;
my $max = 85;
my (@close, @open);