Skip to content

Instantly share code, notes, and snippets.

View realdecisions's full-sized avatar
🏠
Working from home

Evgeniy Vansevich realdecisions

🏠
Working from home
View GitHub Profile
@realdecisions
realdecisions / perl-memory-modules
Last active January 18, 2017 11:39 — forked from jkeroes/perl-memory-modules
Perl memory leaks resources
Complex memory analysis:
* Devel::MAT - makes heap dump and provides toolchain for dump-file analysis
Tracking memory leaks:
Devel::Arena - sv_stats() returns arena structures used for SV allocation
* Devel::Cycle - find_cycle($ref) returns all cycles found in $ref and the perl variables they point to
Devel::Gladiator - walk Perl variable arena
Devel::Leak - deprecated by Devel::LeakTrace::Fast
Devel::LeakTrace - deprecated by Devel::LeakTrace::Fast
* Devel::LeakTrace::Fast - prints leaked SV's and line numbers at END.
@realdecisions
realdecisions / MultiChannel.pm
Created September 23, 2016 10:09
Coro::Channel multiplexer
package Coro::MultiChannel;
#perl Coro::Channel multiplexer
use Coro;
use parent qw/Coro::Channel/;
sub CORO(){3}
sub new {
bless $_[0]->SUPER::new($_[1]);
#!perl
my $lol = bless { string => "test_string" };
$lol->{cycle}{reference}[0] = $lol;
my $lol1 = bless [];
$lol1->[0]{yet}{another}{cycle}{reference} = $lol1;
use strict;
require Devel::Gladiator;
@realdecisions
realdecisions / global_hook.pm
Last active May 13, 2016 15:55
fork::global_hook => Inline::С impl.
package fork::global_hook;
use strict;
use Inline C => <<EOF;
void find_and_call(){
SV* sva;
GV* method;
HV* stash;
char* name;
uint cnt = 0;
package fork::child_cb;
use strict;
my @CHILD_CB;
BEGIN {
*CORE::GLOBAL::fork = sub() {
my $ret = CORE::fork;
if ( defined($ret) && $ret == 0 ) {
@realdecisions
realdecisions / global_hook.pm
Last active January 26, 2016 21:26
Perl implementation of hooks for fork aka AFTER_FORK.
package fork::global_hook;
use strict;
use B;
use Devel::Gladiator;
use constant {
BLESSED => 0x00100000
};
@realdecisions
realdecisions / ImportMe.pm
Created December 29, 2015 19:04
Mouse import.
package ImportMe;
use Mouse;
my @imports;
sub import{
my $class = shift;
my %args = @_;
my $cb = sub {
my $self = shift;
@realdecisions
realdecisions / gist:87b1e77a3a4f85bf5cc5
Created September 25, 2015 15:51
Perl uniq array
#!perl
use Benchmark qw/cmpthese/;
use strict;
my @array = ( 'a', 'a', 'a', 'b', 'c', 'd', 'e', 'g', 'e', 'e', 'g', 'c' );
sub uniq_v1 {
my %tmp;
my @new_array = grep {
use Plack::Builder;
use Plack::Request;
use Cache::Memcached::Fast;
use JSON::XS;
my $_JSON = JSON::XS->new->utf8;
my $mem = Cache::Memcached::Fast->new({servers=>[qw/127.0.0.1:11211/]});
$mem->set('counter:1',0);
$mem->disconnect_all;
builder {
#!/usr/bin/env perl
use FindBin;use lib "$FindBin::Bin/../blib/lib";
use AnyEvent::HTTP::Server;
use EV;
use Cache::Memcached::Fast;
use JSON::XS;
use Data::Dumper;
my $_JSON = JSON::XS->new->utf8;