Skip to content

Instantly share code, notes, and snippets.

@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: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: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: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: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;