Skip to content

Instantly share code, notes, and snippets.

use Test::More;
my @patterns = qw{a b c};
my $string = q{c};
my $pattern = qr{((?{ join "|", @patterns }))};
ok $string =~ $pattern, "matches";
done_testing();
@leedo
leedo / magick.diff
Created February 21, 2013 20:57
patched Perl::Magick 6.77 Makefile.PL to work with homebrew
--- PerlMagick-6.77/Makefile.PL 2012-05-24 18:00:30.000000000 -0500
+++ PerlMagick-6.77-working/Makefile.PL 2013-01-27 15:42:48.000000000 -0600
@@ -154,13 +154,12 @@
}
}
}
-
# defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile
-my $INC_magick = '-I../ -I.. -pthread -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -pthread -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/graphviz -I/usr/include/freetype2 -I/usr/include/libxml2 -I"' . $Config{'usrinc'} . '/ImageMagick"';
-my $LIBS_magick = '-L../magick/.libs -lMagickCore -lperl -lm';
sub plugins {
my ($self, $network, $chan) = @_;
return @{$self->{plugins}} unless $network;
grep {
my $i = $_->config("ircs");
!$i || any {
lc $_->[0] eq lc $network
&& (!$chan || (!$_->[1] || lc $_->[1] eq lc $chan))
} map {[split "@", $_]} @$i;
} @{$self->{plugins}};
@leedo
leedo / async-error.pl
Created January 26, 2013 22:20
Any way to catch errors like this?
use AnyEvent;
sub app {
my $hook = shift;
my $cv = AE::cv;
# how to catch any unhandled errors in hook?
$hook->(sub { $cv->send(@_) });
$cv->recv;
@leedo
leedo / gist:4629474
Created January 24, 2013 23:23
trollolol
diff --git a/README.md b/README.md
index 55fe848..17c0953 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,14 @@ Hector supports a limited subset of IRC commands.
Install Hector with RubyGems and create your server:
+ $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
+ $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
open my $wp_config, '<', '../wp-config.php';
my $define_re = qr{define\( \s* ["'] ([^"']+) ["'] \s* , \s* ["'] ([^"']+) ["'] \s* \)}x;
my %config;
while (my $line = <$wp_config>) {
if (my ($constant, $value) = $line =~ $define_re) {
$config{$constant} = $value;
}
}
#!/usr/bin/env perl
use v5.12;
use AnyEvent::HTTP;
use HTML::Parser;
sub parse_mirrors {
my $body = shift;
my ($in_us, $in_head, $in_th);
my ($mirror, @mirrors);
#!/usr/bin/env perl
use v5.12;
use strict;
use warnings;
use AnyEvent::HTTP;
use HTML::Parser;
sub parse_mirrors {
use Plack::Builder;
use Plack::App::Proxy;
builder {
enable sub {
my $app = shift;
sub {
my $env = shift;
delete $env->{HTTP_ACCEPT_ENCODING};
my $res = $app->($env);
[leedo@trillian ~]$ plackup -MCarp::Always test.pl
HTTP::Server::PSGI: Accepting connections at http://0:5000/
EV: error in callback (ignoring): Not a CODE reference at /Users/leedo/perl5/perlbrew/perls/perl-5.16.2/lib/site_perl/5.16.2/darwin-2level/EV.pm line 1192.
EV::__ANON__() called at /Users/leedo/perl5/perlbrew/perls/perl-5.16.2/lib/site_perl/5.16.2/darwin-2level/AnyEvent/Impl/EV.pm line 88
eval {...} called at /Users/leedo/perl5/perlbrew/perls/perl-5.16.2/lib/site_perl/5.16.2/darwin-2level/AnyEvent/Impl/EV.pm line 88
AnyEvent::CondVar::Base::_wait('AnyEvent::CondVar=HASH(0x7ffa5bb895c0)') called at /Users/leedo/perl5/perlbrew/perls/perl-5.16.2/lib/site_perl/5.16.2/darwin-2level/AnyEvent.pm line 1981
AnyEvent::CondVar::Base::recv('AnyEvent::CondVar=HASH(0x7ffa5bb895c0)') called at /Users/leedo/perl5/perlbrew/perls/perl-5.16.2/lib/site_perl/5.16.2/Plack/App/Proxy/Backend/AnyEvent/HTTP.pm line 60
Plack::App::Proxy::Backend::AnyEvent::HTTP::__ANON__('HASH(0x7ffa5baf3738)') called at /Users/leedo/per