aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-07-16 07:51:17 +0100
committerGitHub <noreply@github.com>2019-07-16 07:51:17 +0100
commitf67b21bc51f755b9f35108509baedbe3e53a9bfe (patch)
treeaa26872bf05205de5fe768950e3d1b412895e9c8
parent25bd8ce0d252e23fe76bb80bd0d1f3f0084700e9 (diff)
parent64dd12898a1077962fdd913ed2d5f48e15a3f19c (diff)
downloadperlweeklychallenge-club-f67b21bc51f755b9f35108509baedbe3e53a9bfe.tar.gz
perlweeklychallenge-club-f67b21bc51f755b9f35108509baedbe3e53a9bfe.tar.bz2
perlweeklychallenge-club-f67b21bc51f755b9f35108509baedbe3e53a9bfe.zip
Merge pull request #381 from jacoby/master
all but the blogging and MAYBE the API challenge. Plus profile pic.
-rwxr-xr-xchallenge-017/dave-jacoby/ch-1.pl21
-rwxr-xr-xchallenge-017/dave-jacoby/ch-2.pl164
-rwxr-xr-xchallenge-017/dave-jacoby/ch-2b.pl55
-rw-r--r--challenge-017/dave-jacoby/picture.jpgbin0 -> 516253 bytes
4 files changed, 240 insertions, 0 deletions
diff --git a/challenge-017/dave-jacoby/ch-1.pl b/challenge-017/dave-jacoby/ch-1.pl
new file mode 100755
index 0000000000..87ed00e14d
--- /dev/null
+++ b/challenge-017/dave-jacoby/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ postderef say signatures state switch };
+no warnings
+ qw{ experimental::postderef experimental::smartmatch experimental::signatures };
+
+say a( 1, 2 );
+say a( 2, 2 );
+say a( 2, 5 );
+exit;
+
+sub a ( $m, $n ) {
+ die 'Invalid input' unless $m >= 0 && $n >= 0;
+ return $n + 1 if $m == 0;
+ return a( $m - 1, 1 ) if $m > 0 && $n == 0;
+ return a( $m - 1, a( $m, $n - 1 ) ) if $m > 0 && $n > 0;
+}
+
diff --git a/challenge-017/dave-jacoby/ch-2.pl b/challenge-017/dave-jacoby/ch-2.pl
new file mode 100755
index 0000000000..77e26dafaa
--- /dev/null
+++ b/challenge-017/dave-jacoby/ch-2.pl
@@ -0,0 +1,164 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ postderef say signatures state switch };
+no warnings
+ qw{ experimental::postderef experimental::smartmatch experimental::signatures };
+
+# Create a script to parse URL and print the components of URL.
+# According to Wiki page, the URL syntax is as below:
+
+# scheme:[//[userinfo@]host[:port]]path[?query][#fragment]
+
+my @list;
+push @list, 'ftp://ftp.cerias.purdue.edu/pub/dict/README.txt';
+push @list, 'http://slashdot.org/';
+push @list, 'https://en.wikipedia.org/wiki/URL';
+push @list, 'https://github.com/manwar/perlweeklychallenge-club/pulse';
+push @list, 'https://mail.google.com/mail/u/0/#inbox/FMfcg';
+push @list, 'https://perlweeklychallenge.org/blog/perl-weekly-challenge-017/';
+push @list, 'https://practimer.me:443/#5m0s';
+push @list, 'https://www.perlmonks.org/?node_id=818843';
+push @list, 'jdbc:mysql://user:password@localhost:3306/pwc?profile=true#h1';
+
+@list = @ARGV if scalar @ARGV; # replace test list if anything is entered
+
+# by the URL definition on wikipedia, jdbc:mysql is not a valid scheme
+# and the scheme contains a trailing colon.
+
+# Notes on implementation:
+# + this is VERY ascii-centric code, and unicode and emoji are allowed
+# in URLs. Take, for example, i❤️tacos.ws
+# + schemas and TLDs are constrained, not just to ascii, but to a small
+# (but larger than before) list. Yeah, you can override this with your
+# hosts file, but otherwise, all URLs should end (case-insensitive)
+# with a string in this list:
+# http://data.iana.org/TLD/tlds-alpha-by-domain.txt
+# + similarly, the lists for path and query are limited to values
+# fitting my dataset. There have been path separator bugs: IE
+# would count \ as a separator, while Mozilla would not, so
+# you could hide information from Windows browsers /with\this\path
+
+# So, this is a very naive implementation, needing more work before
+# it can be trusted with real-world URLs. So, except when it's done
+# for fun, like here, use something like Mojo::URL to split it up
+# for you https://metacpan.org/pod/Mojo::URL
+
+for my $url ( sort @list ) {
+ my ( $scheme, $userinfo, $host, $port, $path, $query, $fragment ) =
+ $url =~ m{
+ ^
+ (\w[A-Za-z0-9\+\.\-\:]+):// # schema
+ (?:([^@]+)@)? # userinfo
+ ([\w\.]+) # host
+ (?:\:(\d+))? # port
+ (/[\w/\+\.\-]*) # path
+ (?:\?([\w/\+\.\-\=]+))? # query
+ (?:\#([^#]+))? # fragment
+ $
+ }mxis;
+ $scheme //= '';
+ $userinfo //= '';
+ $host //= '';
+ $port //= '';
+ $path //= '';
+ $query //= '';
+ $fragment //= '';
+
+ say <<"END";
+ URL $url
+ scheme $scheme
+ userinfo $userinfo
+ host $host
+ port $port
+ path $path
+ query $query
+ fragment $fragment
+END
+}
+
+__DATA__
+
+ URL ftp://ftp.cerias.purdue.edu/pub/dict/README.txt
+ scheme ftp
+ userinfo
+ host ftp.cerias.purdue.edu
+ port
+ path /pub/dict/README.txt
+ query
+ fragment
+
+ URL http://slashdot.org/
+ scheme http
+ userinfo
+ host slashdot.org
+ port
+ path /
+ query
+ fragment
+
+ URL https://en.wikipedia.org/wiki/URL
+ scheme https
+ userinfo
+ host en.wikipedia.org
+ port
+ path /wiki/URL
+ query
+ fragment
+
+ URL https://github.com/manwar/perlweeklychallenge-club/pulse
+ scheme https
+ userinfo
+ host github.com
+ port
+ path /manwar/perlweeklychallenge-club/pulse
+ query
+ fragment
+
+ URL https://mail.google.com/mail/u/0/#inbox/FMfcg
+ scheme https
+ userinfo
+ host mail.google.com
+ port
+ path /mail/u/0/
+ query
+ fragment inbox/FMfcg
+
+ URL https://perlweeklychallenge.org/blog/perl-weekly-challenge-017/
+ scheme https
+ userinfo
+ host perlweeklychallenge.org
+ port
+ path /blog/perl-weekly-challenge-017/
+ query
+ fragment
+
+ URL https://practimer.me:443/#5m0s
+ scheme https
+ userinfo
+ host practimer.me
+ port 443
+ path /
+ query
+ fragment 5m0s
+
+ URL https://www.perlmonks.org/?node_id=818843
+ scheme https
+ userinfo
+ host www.perlmonks.org
+ port
+ path /
+ query node_id=818843
+ fragment
+
+ URL jdbc:mysql://user:password@localhost:3306/pwc?profile=true#h1
+ scheme jdbc:mysql
+ userinfo user:password
+ host localhost
+ port 3306
+ path /pwc
+ query profile=true
+ fragment h1
+
diff --git a/challenge-017/dave-jacoby/ch-2b.pl b/challenge-017/dave-jacoby/ch-2b.pl
new file mode 100755
index 0000000000..d83a61845e
--- /dev/null
+++ b/challenge-017/dave-jacoby/ch-2b.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ postderef say signatures state switch };
+no warnings
+ qw{ experimental::postderef experimental::smartmatch experimental::signatures };
+
+use Mojo::URL;
+
+# Create a script to parse URL and print the components of URL.
+# According to Wiki page, the URL syntax is as below:
+
+# scheme:[//[userinfo@]host[:port]]path[?query][#fragment]
+
+my @list;
+push @list, 'ftp://ftp.cerias.purdue.edu/pub/dict/README.txt';
+push @list, 'http://slashdot.org/';
+push @list, 'https://en.wikipedia.org/wiki/URL';
+push @list, 'https://github.com/manwar/perlweeklychallenge-club/pulse';
+push @list, 'https://mail.google.com/mail/u/0/#inbox/FMfcg';
+push @list, 'https://perlweeklychallenge.org/blog/perl-weekly-challenge-017/';
+push @list, 'https://practimer.me:443/#5m0s';
+push @list, 'https://www.perlmonks.org/?node_id=818843';
+push @list, 'mysql://user:password@localhost:3306/pwc?profile=true#h1';
+
+# Mojo::URL does NOT like the example URL
+push @list, 'jdbc:mysql://user:password@localhost:3306/pwc?profile=true#h1';
+
+@list = @ARGV if scalar @ARGV; # replace test list if anything is entered
+
+for my $url ( sort @list ) {
+ my $mojo = Mojo::URL->new($url);
+ my $scheme = $mojo->scheme || '';
+ my $userinfo = $mojo->userinfo || '';
+ my $host = $mojo->host || '';
+ my $port = $mojo->port || '';
+ my $path = $mojo->path || '';
+ my $query = $mojo->query || '';
+ my $fragment = $mojo->fragment || '';
+
+ say <<"END";
+ URL $url
+ scheme $scheme
+ userinfo $userinfo
+ host $host
+ port $port
+ path $path
+ query $query
+ fragment $fragment
+END
+}
+
+__DATA__
diff --git a/challenge-017/dave-jacoby/picture.jpg b/challenge-017/dave-jacoby/picture.jpg
new file mode 100644
index 0000000000..63559b4ae4
--- /dev/null
+++ b/challenge-017/dave-jacoby/picture.jpg
Binary files differ