Skip to content

Instantly share code, notes, and snippets.

@sugar84
sugar84 / gist:5728083
Last active December 18, 2015 04:49
Simple xmpp bot, post all log message from dir to specified jabber accounts
#!/usr/bin/perl
use strict;
use warnings;
use FindBin qw/$Bin/;
use lib "$Bin/../..";
use POSIX qw/setsid/;
use File::Basename qw/basename/;
use AnyEvent;
@sugar84
sugar84 / gist:3858366
Created October 9, 2012 12:03
plain vs reference
#!/usr/bin/env perl
use Modern::Perl;
use Benchmark qw/cmpthese/;
my (@arr1, $arr_ref1, %hash1, $hash_ref1);
say "Read access: ";
my $x;
cmpthese(-2, {
@sugar84
sugar84 / gist:3683853
Created September 9, 2012 11:14
Try::Tiny gotcha
#!/usr/bin/env perl
use Modern::Perl;
use Test::More;
use Test::Fatal qw/dies_ok/;
use Try::Tiny;
dies_ok { wrong_try_catch() } "First is dies";
dies_ok { wrong_try_catch2() } "Second should die too";
@sugar84
sugar84 / gist:3679238
Created September 8, 2012 20:00
AnyEvent::XMPP
#!/usr/bin/env perl
use common::sense;
use AnyEvent;
use AnyEvent::XMPP::Client;
my $cv = AE::cv;
my $client = AnyEvent::XMPP::Client->new(debug => 1);
$client->add_account('[email protected]', 'password');
@sugar84
sugar84 / gist:3150157
Created July 20, 2012 10:56
simple memory watcher for ubic
#!/usr/bin/env perl
use Modern::Perl;
# launch: bin.pl <service_name> [memory_limit in %]
my $service_name = shift @ARGV;
my $mem_limit = @ARGV ? shift @ARGV : 20;
my $pid = get_pid($service_name);
my $mem_size = get_memory($pid);
@sugar84
sugar84 / gist:2949008
Created June 18, 2012 15:45
search module
#!/usr/bin/env perl
use common::sense;
my $module = $ARGV[0];
$| = 1;
die "wrong module name: $module" if $module !~ /^[A-Za-z0-9:]+$/;
my @parts = split "::", $module;
$parts[$#parts] .= ".pm";
@sugar84
sugar84 / gist:2767755
Created May 22, 2012 09:12
delayed response through psgi
use common::sense;
use AnyEvent::HTTP;
my $app = sub {
my $env = shift;
return sub {
my $respond = shift;
fetch_content(sub {
@sugar84
sugar84 / gist:2570008
Created May 1, 2012 17:49
proxy, anyevent::http::socks
#!/usr/bin/env perl
use strict;
use warnings;
use DB::Local;
use AnyEvent::HTTP::Socks;
use constant CHECK_TIME => 15 * 60;
use constant TIMEOUT => 10;
use constant MAX_GETS => 60;
@sugar84
sugar84 / gist:1918805
Created February 26, 2012 20:19
some psgi app
#!/usr/bin/env perl
use strict;
use warnings;
use 5.12.3;
use FindBin qw($Bin);
use lib "$Bin/../lib";
use DB::Connect;
use HTML::Template;
use Plack::Request;
@sugar84
sugar84 / gist:1816344
Created February 13, 2012 12:07
Example of AnyEvent::Filesys::Notify
#!/usr/bin/env perl
use common::sense;
use AnyEvent::Filesys::Notify;
use AnyEvent;
my $src = "/my/proj/path/htdocs";
my $dst = "/var/www/html";
my $cv = AnyEvent->condvar;