Write a script that takes a list of email addresses (one per line) and sorts them first by the domain part of the email address, and then by the part to the left of the @ (known as the mailbox).
Note that the domain is case-insensitive, while the mailbox part is case sensitive. (Some email providers choose to ignore case, but that’s another matter entirely.)
If your script is invoked with arguments, it should treat them as file names and read them in order, otherwise your script should read email addresses from standard input.
Bonus
Add a -u option which only includes unique email addresses in the output, just like sort -u.
There are 5 rings in the Olympic Logo [as shown below]. They are colour coded as in Blue, Black, Red, Yellow and Green. We have allocated some numbers to these rings as below: Blue: 8, Yellow: 7, Green: 5, Red: 9. The Black ring is empty currently. You are given the numbers 1, 2, 3, 4 and 6. Write a script to place these numbers in the rings so that the sum of numbers in each ring is exactly 11.
My first idea was to go over all the possible permutation of the numbers and report those that satisfy the sum condition. I chose Math::Combinatorics as the module to handle the permutations.
Well I think it is a first here in the Paws patrol. I spent the day plunging away with CloudFront and I have no new Paws issues but I did learn and important practical lesson about using CloudFront.
I got stuck on the 'UpdateCloudFrontOriginAccessIdentity' call.
It seemed simple enough
$s3->UpdateCloudFrontOriginAccessIdentity(
CloudFrontOriginAccessIdentityConfig => {
CallerReference => 'Some text here',
Comment => 'Mr Pooppy buthole did this',
},
Id=> 'E3D5Y5RWA05QO1',
);
but I kept running into this error;
The request failed because it didn't meet the preconditions in one or more request-header fields.
Spoiler Alert: This weekly challenge deadline is due in a couple of days (May 24, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.
Task 1: Max Sub-Array Product
Given a list of 4 or more numbers, write a script to find the contiguous sublist that has the maximum product.
Example:
Input: [ 2, 5, -1, 3 ]
Output: [ 2, 5 ] which gives maximum product 10.
Max Sub-Array Product in Raku
Let’s start with a simple loop over a list of indices, as we would do in most procedural programming languages. We loop over the existing indices of the input array, compute the product of each item with the next one, and store in the @max array the max product so far, as well as the two items that led to it:
[This is an addendum post to a series. You may want to begin at the beginning. The last update was update #2.
IMPORTANT NOTE! When I provide you links to code on GitHub, I’m giving you links to particular commits. This allows me to show you the code as it was at the time the blog post was written and insures that the code references will make sense in the context of this post. Just be aware that the latest version of the code may be very different.]
In case you missed my talk on Date::Easy from a couple years back, I’ll sum it up for you: dates are hard, y’all.
Well I left off on form my last post with this Moose error;
Attribute (Items) does not pass the type constraint because: Validation failed for 'ArrayRef[Str|Undef]' with value [ { Method: ARRAY(0x5184cf0) } ] at /wwwveh/lib/x86_64-linux-thread-multi/Moose/Object.pm line 24
but before I tackle that on I wanted to have a closer look at my changes I did to the callresult_class.tt template; I wanted to clean that up nicely and then my plan is to see if my changes have Borden anything else.
So in cleaning it up I found what might be a bug.
It seems that this call
[%- IF (stream_param or shape.payload == param_name) %]
is now out of the attributes foreach loop so I change things about a bit and now I just set a var in the template and apply the new trait if the var has a value;
Please note that this blog post will be shorter than usual, since I’m a bit short of time to prepare it.
Task 1: Excel Columns
Write a script that accepts a number and returns the Excel Column Name it represents and vice-versa.
Excel columns start at A and increase lexicographically using the 26 letters of the English alphabet, A..Z. After Z, the columns pick up an extra “digit”, going from AA, AB, etc., which could (in theory) continue to an arbitrary number of digits. In practice, Excel sheets are limited to 16,384 columns.
Example:
Input Number: 28
Output: AB
Input Column Name: AD
Output: 30
Update: Time::Local 1.30 includes a new pair of functions timegm_posix/timelocal_posix which address all issues outlined in this article, including the issues with the traditional functions, at least as pertains to Time::Local’s purpose as an inverse of the gmtime/localtime Perl builtins.
The new _modern function variants in Time::Local have come up a few times lately. I have some thoughts on them, but presenting my position dispassionately enough to be persuasive demands an essay of unfortunate length… so let’s get on with it.
Let me lead with the positive: it is a problem with the traditional functions that they would sometimes add 1900 to the year and sometimes a different value and sometimes nothing. This heuristic in the interface is bad. Doing something about it is a good idea.
For reasons that must have been clear at the time, I once wrote a test in terms of epoch time, and wanted it to run on systems that did not use January 1 1970 as the epoch. So I loaded Time::Local and added timegm( 0, 0, 0, 1, 0, 70 ) to the desired epoch.
This morning I got a CPAN testers report failure. It seems that if you give timegm() a year in the range 0-99 it assumes it is within 50 years of the current year, so my test suddenly thought the epoch was 2070.
In this case, the obvious response is to specify a four-digit year.
Maybe a better response is to ditch timegm() and timelocal() completely in favor of timegm_modern() and timelocal_modern(). These require Time::Local version 1.27, released June 2019. According to its metadata it works back to Perl 5.6, though so far I have only verified it back to Perl 5.8.1.
With thanks to Dave Rolsky for the *_modern() variants, and to Chris Williams (BINGOS), who uncovered this in one of his CPAN tester systems.
Quite ingenious title I used here, but it's precise. This story starts with the following case:
role R {
method a { 666 }
}
class C does R {
has $.a = 42;
}
say C.new.a;
What would you expect this to print?
For those with basic or no knowledge in Raku I'd like to explain that a public attribute gets an automatic accessor method. So, when one does $obj.attribute it's actually a method call.
There could be some disagreement among devs wether the code should output 42 or 666. Though Raku states it explicitly that things defined by class have priority over role's declared ones. Hence, we expect 42 here.
Period, this post is over, everybody is free to go? Alas, this issue says that the code above outputs 666! Oops... What's going on here?
Spoiler Alert: This weekly challenge deadline is due in a few hours. This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.
Task 1: Linked List Partition
You are given a linked list and a value k. Write a script to partition the linked list such that all nodes less than k come before nodes greater than or equal to k. Make sure you preserve the original relative order of the nodes in each of the two partitions.
he first order of the day was to clean up all the debugging code I peppered across my perl trying to find an answer to my 'Failed Signature' bug.
This did take a while and in the end the changes that I am sticking with are;
if ( my $xml_body = $self->_to_xml_body($call) ) {
$request->content($xml_body);
++ $request->header( 'content-type' => 'application/xml'); #this is an XML interface so it should have this header
}
At the start of the year 2019, I made new year resolution that I will submit at least 50 Pull Request each month in the year 2019. It wasn't easy but I was able to hold on to my resolution with the help of many CPAN authors. In the year 2020, I am going to take little easy and revert back to one Pull Request a day each month.
Perl Weekly Challenge
The main attraction of the year was "Perl Weekly Challenge" started on 25th March 2019. It is platform for Perl and Raku fan to share the knowledge. As of now, we have successfully completed 9 months of weekly challenge. As of today, we have 140 active members.
The Chaos Communication Congress is the hugest convention and festival for hackers on the continent. Its part 5-9 track lecture conference, part massive parallel soldering and other workshops, part dance party and part carneval. I liked especially the one guy, just walking around while making music on it's novation circuit - but there was so much going on - he was hardly noticeable. Because it was gigantismic. When even a small self made booth for baking dough (one of several dozens food stands) sells over a ton (literally > 1000 kg), serving > 13000 people, it earned its name: waffle operation center (WAP). But that's the spirit and humor around here.
Spoiler Alert: This weekly challenge deadline is due in a couple of days (May 3, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.
Task 1: Compare Versions
Compare two given version number strings v1 and v2 such that:
- If v1 > v2 return 1- If v1 < v2 return -1- Otherwise, return 0
The version numbers are non-empty strings containing only digits, and the dot (“.”) and underscore (“”) characters. (“” denotes an alpha/development version, and has a lower precedence than a dot, “.”). Here are some examples:
I decided I might as well get busy with CloudFront and at least get most of my real world scripts written.
At the moment I am getting 400 errors such as 'InvalidArgument' or 'InvalidOrigin' on the Delete and Create actions as I do not have the proper config on the AWS end for the Creates and for the Deletes as I do not have anything on my AWS account to delete.
Reading though the API documentation is seems there is quite the procedure to actually do some of the actions, for example to invoke the DeleteStreamingDistribution action you have to follow a six pre-steps all of which must pass. So I guess I can forget a quick run on this API
So the plan is to get all the real world scripts written up and then go though the full CRUD actions for each and get them working with a good generated test case for each.
CPAN Pull Request Challenge used to match CPAN maintainers to contributors. Contributors would sign up to receive monthly assignments. The goal was to submit at least one pull request. It was fun, but it came to an end at the end of 2018.
I wanted this challenge to go on, so I created Pull Request Club. It has been a whole year since it started, so here’s the annual report with some insights.
New features
While Pull Request Club took its basics from CPAN-PRC, I wanted to make it more self-served. Users can take various actions such as signing up or skipping an assignment with a few clicks.
Users sign up to the site with their GitHub accounts. This lets them add their repositories to the assignment pool without hassle.
Users can see both their “assignment history” and “assignee history”.
You are given two or more arrays. Write a script to display values of each list at a given index.
For example:
Array 1: [ I L O V E Y O U ]
Array 2: [ 2 4 0 3 2 0 1 9 ]
Array 3: [ ! ? £ $ % ^ & * ]
We expect the following output:
I 2 !
L 4 ?
O 0 £
V 3 $
E 2 %
Y 0 ^
O 1 &
U 9 *
The pound sign is not part of the standard ASCII, so we’ll need to properly encode it. The use utf8; clause tells perl that the script itself contains UTF-8 encoded characters, the binmode function sets the encoding for the given filehandle, i.e. standard output.