This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warnings; | |
use strict; | |
use Benchmark qw/cmpthese/; | |
for my $r (10,100,1_000,10_000) { | |
print " ___ $r ___\n"; | |
my $str = "foo;bar;" x $r; | |
cmpthese(-1, { | |
orig => sub { # https://stackoverflow.com/q/48961457/9300627 | |
$str=~s/\b([^;]+)(?=.*;\1;);//gr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warnings; | |
use strict; | |
use Data::Dumper; | |
use Memoize::Expire; | |
tie my %cache => 'Memoize::Expire'; | |
my $self = { cache => [ \%cache ] }; # self is not tied nor an object | |
eval { print Dumper($self); 1 } or warn $@; | |
#=> Can't locate object method "FIRSTKEY" via package "Memoize::Expire" at ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
use Benchmark 'cmpthese'; | |
use List::Util 'first'; | |
my @tests = ( | |
{ nrand=> 100, nlook=> 10, match=>'beginning' }, | |
{ nrand=> 100, nlook=> 100, match=>'beginning' }, | |
{ nrand=>10_000, nlook=> 100, match=>'beginning' }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
use Time::HiRes qw/gettimeofday tv_interval/; | |
use DBI; | |
my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:",undef,undef, | |
{ RaiseError=>1, AutoCommit=>0 } ); | |
{ # create table and fill with fake data | |
$dbh->do(<<'END_SQL'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WARNING # WARNING # WARNING # the following command generates a ~1 GIGABYTE file! | |
$ perl -le '$,=$/;for(1..50000){print+("Foo")x5000,"Bar CAPTURE Bar"}print+("Foo")x5000' >test.txt | |
# For testing outputs: | |
# perl -le '$,=$/;print"Bar CAPTURE Bar";for(1..49999){print+("Foo")x5000,"Bar CAPTURE Bar"}' >out_expect.txt | |
# UPDATE: Replace "time" with "/usr/bin/time" to get memory usage stats as well! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warnings; | |
use 5.018; | |
# run this multiple times: sometimes it prints "x1x2x1x", sometimes "x2bar-x2x2bar-x" | |
{ | |
my %repl = ( '-foo-bar-'=>1, '-foo-'=>2 ); | |
my $re = join '|', map { "\\b$_\\b" } keys %repl; | |
$re = qr/$re/; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
my %tehcodez = ( | |
sortfirst => q{ | |
@list = sort {$a<=>$b} @list; | |
@list = ( (grep {$_>=0} @list), (grep {$_<0} @list) ); }, | |
grepfirst => q{ | |
my @pos = grep {$_>=0} @list; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cpanm --installdeps . | |
requires 'Mojo::DOM'; | |
requires 'HTML::TreeBuilder::XPath'; | |
requires 'HTML::LinkExtor'; | |
requires 'WWW::Mechanize', '1.97'; | |
requires 'XML::LibXML'; | |
# for runsols.pl: | |
requires 'Path::Class'; | |
requires 'IPC::Run3'; | |
requires 'Test::More'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Documented at: https://www.perlmonks.org/?node_id=11116369 | |
$(function () { | |
var CB_FETCHTIME_MS = 15 * 1000; | |
var GERNERAL_REFRESHTIME_MS = 60 * 1000; | |
// AJAX CB Refresh | |
var refresh = function () { | |
$.ajax({ url: '/', dataType: 'html', | |
// testing shows the table rendered here is the same as in the nodelet | |
data: { node: 'showchatmessages', displaytype: 'raw', ticker: 'yes' } }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
igbpyutils >= 0.0.3 | |
sleep_until |
OlderNewer