Perl Weekly Challenge 37: Week Days in Each Month and Daylight Gain/loss

These are some answers to the Week 37 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of days (December 8, 2019). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Challenge # 1: Week Days in Each Month

Write a script to calculate the total number of weekdays (Mon-Fri) in each month of the year 2019.

Paws XXIX (Would you like fries with that)

Well still in clean-up mode here in the Paws Pen trying to get the full t/10_response.t test case working.

I was having all sorts of fun with the 'GetBucketPolicy' action test. By fun I mean a good hour of frustration and cursing and gnashing of teeth as my real-time test script was working fine! I just could not get the test in 's3-get-bucket-policy.response.test.yml' to pass.

Then I stumbled on it.

This is the one very odd action on the AWS S3 API where it dose not return XML but returns JSON. Now I do handle this with this code


       } elsif (exists($headers->{'content-type'})
               and $headers->{'content-type'} eq 'application/json'
               and $ret_class->can('_payload')){
        $unserialized_struct->{$ret_class->_payload} = $content;

in RestXMLResponse.pm.

Perl Marketing Four Elements

Benefits

What benefits Perl provide to users?

Target

Who is the Perl user?

Strength

What are the strengths of Perl?

Place

Where do people find Perl?

These are the basic elements of Marketing.

[ Perl | Raku | The ] Weekly Challenge - 2020

Here is my plan for 2020:

https://perlweeklychallenge.org/blog/plan-2020/

Perl Weekly Challenge 36: Vehicle Identification Numbers (VIN) and the Knapsack Problem

These are some answers to the Week 36 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Task # 1: Vehicle Identification Numbers (VIN)

Write a program to validate given Vehicle Identification Number (VIN). For more information, please checkout wikipedia.

From the Wikipedia article, it appears that VINs are made up of 17 digits and upper-case letters, with the exception of letters I (i), O (o) and Q (q), to avoid confusion with numerals 0, 1, and 9. There are some additional rules that only applicable to certain areas of the world but are not internationally recognized.

Vehicle Identification Numbers in Perl 5

We write a simple validate subroutine that returns a true value (1) if the passed parameter complies with the above rules for VINs and a false value (0) otherwise.

Platypus Next Generation

Platypus is getting an update. It’s not backward compatible, so you have to opt-in when you create the platypus instance. That makes it backward compatible for all the old code you may or may not have written. Please spread the word.

# old code:
use FFI::Platypus;
my $ffi = FFI::Platypus->new;

# new code:
use FFI::Platypus 1.00;
my $ffi = FFI::Platypus->new( api => 1 );

You should generally write all new code using the new API so that you can take advantage of the newer features and design fixes. You may want to also consider upgrading your existing code to use the new API for the same reasons.

Paws XXVII (Templated Paws)


Well today on paws I figured I would take a look and see what was outstanding in terms of code to fix. All that I could find was only really one thing and this boto fix well really a Kludge


/{Bucket}?action
/{Bucket}?action&id={Id}

where I add the id to the URI to get around a bug/problems when running this code on RestXmlCaller.pm;


$uri->query_form(%$qparams); 

would scramble the URI so the call would fail.

What I would like to do is roll back the changes I have made for Boto and see if I can find a pure Perl solution to my problem.

Perl Weekly Challenge 034: Slices and a Dispatch Table

Slices

Write a program that demonstrates using hash slices and/or array slices.

In the spirit of TIMTOWTDI I decided to write a single program that demonstrates both the tasks at the same time.

Let’s start with slices. Slices are parts of structures (arrays and hashes). Slicing has a special syntax by which you tell Perl which indices or keys you want to use to obtain a slice.

For example, consider the following array:

my @keys = qw( not_this_one
               this_one
               this_one_too
               it_was_enough );

Naturally, we want to select the second and third one. We can use

$keys[1], $keys[2]

or

map $keys[$_], 1, 2;

but there’s a shorter and cleaner syntax for the same:

@keys[1, 2]

Perl Weekly Challenge 35: Binary Encoded Morse Code

These are some answers to the Week 35 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days (November 24, 2019). This blog post offers some solutions to this challenge, please don't read on if you intend to complete the challenge on your own.

This week, both tasks were contributed by Paul Johnson.

I usually first do task 1 in Perl 5 and in Raku (formerly known as Perl 6), or sometimes the other way around, and then task 2 in both languages. This week, however, the two tasks are so closely related that it makes sense to do both tasks together in one language, and then the two tasks in the other language.

The tasks

Task # 1: Encode Text into Binary Encoded Morse Code

Write a program to encode text into binary encoded morse code.

Pay attention to any changes which might need to be made to the text to make it valid morse code.

LedgerSMB 1.7.3 released

The LedgerSMB project aims to prevent small and mid-size businesses from getting locked-in by their accounting software vendor by providing free and open source accounting software, integrating invoicing, order processing, quotations and more (ERP). It's all Perl!

Having installed it myself, I found it very very fully featured. You can try out their demo and watch one of their numerous youtube intros and tutorials

The LedgerSMB development team has announced release 1.7.3.

This release contains the following fixes and improvements:

Changelog for 1.7.3

Releases for stable branches of 1.6.15 and 1.5.29 have also been released.

The project has an official Docker image, tar balls, and deb packages all detailed on their downloads page.

Paws XXVIII (Just one More )

Seems I lied in my last post when I said there where no longer any boto changes for my S3 fixes. There is still one call 'GetBucketLocation' that is using a new bit I added to boto

"keep_root":true 

I stumbled upon this when I added in a few fixed cases from another branch and when I ran the suite I
got;

ok 10052 - Call S3->GetBucketLocation from t/10_responses/s3-get-bucket-location.response not ok 10053 - Can't test method access because something went horribly wrong in the call to GetBucketLocation # TODO t/10_responses/s3-get-bucket-location.response.test.yml

My present output of the call is

Would you like to get one user instead of the top of TIBOE?

Would you like to get one user instead of the top of TIBOE?

TIBOE provides rankings with a biased perspective.

A few leading engineers understand that TIBOE has no value

Many dishonest media continue to introduce TIBOE ranking.

Rather than getting the top of the biased ranking,

Wouldn't it be better to get one excellent and sincere engineer?

Marketing is not to mislead people.

Low quality marketing is done around the world, but there is no reason for Perl users to join it.

High quality marketing looks at the mind of a one user.

Developer on Fire Interview

On October 22nd I was interviewed by Dave Rael for Developer On Fire podcast.

It has been an interesting experience, and Dave has been a great host making me feel very comfortable during the whole process.

I talked about Open Source, archery, cats and PostgreSQL.
Here there is something more to read about, and for listening the interview just click on the image.


developersonfire.png

Devel::PPPort has been updated

Devel::PPPort 3.55 has more than two hundred commits since the last major releases. The documentation has been extensively revised to make it clearer how to use, and to contribute. And it has been updated to know about the latest blead; the first such update in 5 or more years.

Dozens of functions and macros are newly implemented. The suite of SV handling functions is more complete, with more flags handled. Also the character classification macros (alpha, punct, etc) and case changing functions are greatly expanded. There is more Unicode support, including modern security standards.

ppport.h --api-info foo

is much more complete than before. If you make 'foo' to instead be '/./' you'll get information about every known API element.

And it still supports 5.003, with a surprising number of elements functioning that far back.

The full documentation is available at .

The version backporting is valid for is unknown for quite a few API elements. That is because documentation is lacking on the parameters these take, and so the automatic tests for these elements can't be generated. If you know what some of the missing things do, we would greatly appreciate your contributing documentation for them. in the form of a github pull request.

Paws XXVI (The Big Clean)

So time to hold on a bit and go back and and see if my latest changes have broken anything or for that matter fixed something that was already broken?

So back to my tests script and and I got my first fail on

'PutBucketCors'

and surprise it was a bit of Mooso poop.


You must pass a package name and it cannot be blessed at /wwwveh/lib/x86_64-linux-thread-multi/Moose/Meta/Attribute.pm line 867
        Moose::Meta::Attribute::get_value('Moose::Meta::Class::__ANON__::SERIAL::12=HASH(0x4ad5358)', 'http://www.example.com') called at /home/scolesj/aws-sdk-perl/

So I checked the generated 'PutBucketCors,pm' file with one from a clean .41 build and there was no changes there so it must be someplace else?

Well lots of debugging later I found it here

Perl Weekly Challenge 34: Array and Hash Slices and Dispatch Tables

These are some answers to the Week 34 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days (November 17, 2019). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

This week, both tasks were contributed by Dave Cross.

Task # 1: Array and Hash Slices

Write a program that demonstrates using hash slices and/or array slices.

Slices are a way to access several values of an array or of a hash in one statement, by using multiple subscripts or keys.

Array and Hash Slices in Perl 5

If you have an @array containing for example some successive integers, you can obtain several values from it with the following syntax: @array[3, 7, 2] or even @array[2..7].

Perl Weekly Challenge 033: Count Letters & Formatted Multiplication Table

Count Letters

Create a script that accepts one or more files specified on the command-line and count the number of times letters appeared in the files.

From the example we can see that we should count the letters in a case insensitive way (see the lc in the example below). Similarly to Challenge 032, we can use a hash to keep the counts.

#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };

my %count;
while (<>) {
    ++$count{ lc $1 } while /([a-zA-Z])/g;
}
for my $char (sort keys %count) {
    say "$char: $count{$char}";
}

Tabs or spaces for indentation? Statistics on 3.8 million Perl files created in 24 years

I spotted this on The Twitter, someone processed lots of code to find the truth on this topic of disagreement.

"After I have processed data in the database, I decided to watch from each author he uses for padding. I expect that the most popular will be the use of only spaces, the second place by popularity will be using only tabs, and the third place in popularity is the simultaneous use of tabs and spaces. But it turned out that I was completely wrong. "

Read on: https://squareperl.com/en/tabs-vs-spaces-in-millions-of-perl-files

Paws XXV (A break though)

Well today’s post marks a tuning point in Paws me thinks, at least in the S3 name-space. I have been spending quite allot of time trying to get this action to work;

PutBucketAcl

It is the most nasty bit of AWS code I have come across so far. First one needs to send this XML up to AWS;

<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Owner>
    <ID>852b113e7a2f25102679df27bb0ae12b3f85be6BucketOwnerCanonicalUserID</ID>
    <DisplayName>OwnerDisplayName</DisplayName>
  </Owner>
  <AccessControlList>
    <Grant>
      <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
        <ID>852b113e7a2f25102679df27bb0ae12b3f85be6BucketOwnerCanonicalUserID</ID>
        <DisplayName>OwnerDisplayName</DisplayName>
      </Grantee>
      <Permission>FULL_CONTROL</Permission>
    </Grant>

You will notice that in the 'Grantee' tag there are some XML attributes!!. Sure enough it is in boto JSON

Perl Weekly Challenge 33: Count letters and Multiplication Tables

These are some answers to the Week 33 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (November 10,, 2019). This blog post offers some solutions to this challenge, please don't read on if you intend to complete the challenge on your own.

Challenge # 1: Count Letters (A..Z)

Create a script that accepts one or more files specified on the command-line and count the number of times letters appeared in the files.

So with the following input file sample.txt:

The quick brown fox jumps over the lazy dog.

the script would display something like:

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.