Skip to content

Instantly share code, notes, and snippets.

View daoswald's full-sized avatar

David Oswald daoswald

  • Newfold Digital
  • Salt Lake City, UT
View GitHub Profile
#!/usr/bin/env perl
use feature (feature_bundle);
use v5.36;
BEGIN {print feature_bundle(0); }
curl -l http://localhost:3000/bar.html
HASH(0x55bcb62743c8)
cat myapp.pl
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/bar' => sub {
my $data = {one => {foo => 1}, two => 24};
@daoswald
daoswald / mytest.pl
Created July 27, 2018 05:30
Expanding months into month/year ranges
davido@davido-desktop:~/scripts$ cat mytest.pl
#!/usr/bin/env perl
use strict;
use warnings;
use 5.020_000;
use Text::CSV;
use feature qw(state);
use Data::Dumper;
use Test::More;
doswald@pro-doswald-ll3:~/repos/testml$ make test
git branch --track testml-tml origin/testml-tml 2>/dev/null || true
git worktree add -f testml-tml testml-tml
Preparing worktree (checking out 'testml-tml')
HEAD is now at cc3197c Adjust test for new CLI option
npm install --save-dev diff ingy-prelude lodash
npm WARN saveError ENOENT: no such file or directory, open '/home/doswald/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/doswald/package.json'
npm WARN doswald No description
npm WARN doswald No repository field.
sub tv_mark {
my $t0 = [gettimeofday];
state $cum = 0;
if ($_[0]) {
my $c = $cum;
$cum = 0;
return $c;
}
else {
return sub {
@daoswald
daoswald / mojotest.pl
Last active April 9, 2018 05:35
Mojo::IOLoop::subprocess along with promises to allow for ->wait, and accumulation.
#!/usr/bin/env perl
use Mojolicious::Lite;
use Benchmark qw(:hireswallclock);
# The point: No controller logic in add1, mult2, power.
# But we will run add1 and mult2 in parallel, and then wait for them to finish before taking the power.
sub add1 { my $a = shift; sleep 2; return $a+1; }
sub mult2 { my $b = shift; sleep 2; return $b*2; }
#!/usr/bin/env perl
use strict;
use warnings;
BEGIN {
foreach my $method (qw(foo bar)) {
no strict 'refs';
*{__PACKAGE__ . '::' . $method} = sub {return $method};
}
}
Normally when a quantified subpattern does not allow the rest of the
overall pattern to match, Perl will backtrack. However, this behaviour is
sometimes undesirable. Thus Perl provides the "possessive" quantifier form
as well.
*+ Match 0 or more times and give nothing back
++ Match 1 or more times and give nothing back
?+ Match 0 or 1 time and give nothing back
{n}+ Match exactly n times and give nothing back (redundant)
{n,}+ Match at least n times and give nothing back
@daoswald
daoswald / -
Created January 28, 2017 05:34
Hello world!
chomp(
my @words = do{
open my $word_ifh, '<', '/file/path/wordthree.txt' or die $!;
<$word_ifh>;
}
);
my $alternation = join '|', @words;
my $regex = qr/($alternation)/;
my @hits;