Perl Weekly Challenge #013

Challenge 1: Write a script to print the date of the last Friday of every month in a given year

First thought was to use a module to look up the day of the week for the last day of each month in the given year, then work backwards (in each month) to get the last Friday. But — well, once the weekday of any day in the year is known, the rest can be calculated directly without a further module look-up.

Actually, no module look-up is really needed at all once the day-of-the-week of any day in any year is known. And since I know that 17th June, 2019, is a Monday, I should be able to derive the solution from first principles, as it were, by counting backwards or forwards as needed. But working out leap years is tricky! So I compromised: one look-up for each given input year.

Perl 5 solution

Searching Perldocs

Search is a hard problem. It is the task of getting users to what they want to find, even if they don't know exactly what that is. Its requirements vary widely based on the kinds of things people will want to find and the kinds of people that want to find them. It's also an expected feature of almost anywhere on the web that is more complex than a single page. So shortly after putting together a demo for Perldoc Browser which would become the backend for perldoc.pl, I needed to make it searchable.

Perl Weekly Challenge 013: Last Fridays and Hofstadter Female and Male Sequences

Last Fridays

Write a script to print the date of last Friday of every month of a given year.

To handle dates, I used Time::Piece, a core module since 5.10. It has no method to get the last Friday of a month directly, so I tried a simple trick: get the first day of the next month, subtract one day, and continue to subtract days until we get a Friday.

Time::Piece does all the date maths in seconds. I also used Time::Seconds to get the constant ONE_DAY so I didn’t have to count it myself (60 * 60 * 24, right?)

Dancer2 0.208000 released

On behalf of the Dancer Core Team, I would like to announce the release of Dancer2 0.20800 (the TPCiP release). This version introduces a new keyword, prepare_app, and features a small handful of bug and documentation fixes.

We have found a growing number of instances where not having the ability to execute code on application load is a real annoyance. The prepare_app keyword will allow you to run a block of code when your app is loaded, and is inspired from Plack's prepare_app method. Thanks, Sawyer, for making this happen.

The full changelog is as follows:

Perl Weekly Challenge # 13: Fridays and Mutually Recursive Subroutines

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

Spoiler Alert: This weekly challenge deadline is due in several days from now (June 23, 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: Thank God, It's Friday

Write a script to print the date of last Friday of every month of a given year. For example, if the given year is 2019 then it should print the following:

Coding with an even fuller toolset

Sigh. It's always the way, isn't it?

You no sooner get done writing about how having the right tools can make a particular coding task trivially easy...when you realize that, right next door, there was a much better example you could have used to make exactly the same point.

The "longest initial subpath" example I talked about in my previous post was challenge #2 of last week's Weekly Challenge. But challenge #1 that week makes it even clearer how much the right tool can simplify a task.

Challenge #1 was to find the smallest Euclid number that isn't a prime. The Nth Euclid number is given by the product of the first N primes, plus one. So the sequence of Euclid numbers is:

(2)+1, (2*3)+1, (2*3*5)+1, (2*3*5*7)+1, (2*3*5*7*11)+1, ...

Better Shell Completion for Your Tools

In November 2015 I started my App::Spec commandline framework and wrote this blogpost.

It's not only a framework for perl. It can also generate shell tab completion for other tools.

Since then I have been busy with other things, but recently continued working on it for several reasons, and fixed several bugs, mostly for bash.

Last year I started a collection of generated completion scripts for bash and zsh:

https://github.com/perlpunk/shell-completions

Today it contains completions for 20 tools, mostly for perl commands. If you miss a tool there, let me know, or try to write your own YAML specification and generate the completion.

Below you will see some examples.

How to display NA in CPAN Testers

How to display NA in CPAN Testers?

I asked qustion "I want to display NA instead of UNKKONW in CPAN Testers"

I get some answers.

Thank you for everone!

I write a example to to display NA in CPAN Testers.

Perl Weekly Challenge 012: Non-Prime Euclid Numbers and the Common Path

The Smallest Non-Prime Euclid Number

An Euclid number is a number that equals 1 + product of a sequence of primes.

To speed things up, I used an object that caches the sequence of primes discovered so far. The method size returns the length of the sequence of primes; extend_to extends the sequence up to the specified number.

Coding with a full toolset

A few years ago, I created a talk (and later an entire class) about "transparadigm programming" in Raku.

The basic premise was that while some languages restrict you to only a single hammer (or worse: a box full of hammers), Raku was designed to be a complete toolkit: integrating OO, functional, concurrent, declarative, and procedural tools to allow you to choose exactly the right combination for each job.

That idea came back to me in full force recently. In last week's Weekly Challenge, the second task was to take a list of file paths and find the longest common initial subpath (i.e. the deepest directory they all share).

The solutions offered by the various registered participants were all very clean, and often both efficient and elegant. Yet most of them were variations on the same procedural solution: Split each path on the directory separator, then for 1-to-N: compare all the Nth components and quit if they're not identical. Something like:

Perl Weekly Challenge # 12: Euclid's Numbers and Directories

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

Spoiler Alert: This weekly challenge deadline is due in several days from now (June 16, 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: Euclid's Numbers

The numbers formed by adding one to the products of the smallest primes are called the Euclid Numbers (see wiki). Write a script that finds the smallest Euclid Number that is not prime. This challenge was proposed by Laurent Rosenfeld.

I did not even remember I proposed this challenge to my friend Mohammad Anwar.

Can meta cpan display html table

Can meta cpan display html table.

metaCPAN support img tag.

https://metacpan.org/pod/Chart::Clicker

If I use HTML table in pod,

<table>
  <tr>
    <th>title1</th>
    <th>title2</th>
   </tr>
  <tr>
    <td>foo</td>
    <td>bar</td>
  </tr>
</table>
=end html

If you know, tell me the answer.

Simple Event Correlator v2.8.2

From the website's blurb:

Roles and Responsibilities in Scrum

You might find my Roles and Responsibilities in Scrum of interest (Scrum is not Waterfall).

RPerl at the Texas Linux Festival

RPerl is back on the road! We were in Dallas for the 2019 Texas Linux Fest, another wonderful opportunity to show the open source community that Perl is alive and well! One of the participants called our booth “the coolest-looking table of the conference”, and to that I must say: Thank you Wendy for showing me the way! You are my true mentor when it comes to spreading Perl love.

At the booth, we had the help of Tommy Butler, Perl programmer and leader of the Dallas Perl Mongers. On top of having a booth for the event, Will also gave a talk jokingly entitled “Start A Cult: Build A FOSS Community From Scratch”. The talk was well-attended and drew more interest to our overall Perl booth activities.

Dose Imager have utilities for vector graphic to write chart?

Dose Imager have utilities for vector graphic to write chart?

Imager is very portable to manipulate imanges in Perl.

I want to know that Dose Imager have utilities for vector graphic to write chart?

For example, Cairo can write the following Chart.

Perl Cairo tutorial

Cairo Installation is very hard and have many dependency.

If Imager can do the same things, it is useful.

Tech Tips: Handling Int Vectors in Perl 5

Hi all, and Happy Shavuoth.

The Tips

Apparently, perldoc -f vec writes 16-bit / 32-bit / 64-bit quantities in big endian byte order, including on little endian architectures such as x86. This may cause issues when writing XS / etc. bindings.

I ended up using the following approach on x86-64 Linux to overcome that:

Recent work on Chart::GGPlot

loess smooth

A couple of months ago I wrote this blog post Data analysis and visualization in Perl. Then last month I released a 0.0003 version. And today I made a new 0.0005 release to CPAN. Some of the notable improvements in the recent releases are,

Perl Weekly Challenge 011: Fahrenheit, Celsius, and an Identity Matrix

Compute the Equal Point in the Fahrenheit and Celsius Scales

I used a simple numerical method to find the equal point: Start randomly, move in one direction, if the difference is greater, change the direction, otherwise decrease the step, until there’s no difference.

Perl Weekly Challenge # 11: Fahrenheit Celsius and Identity Matrix

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

Spoiler Alert: This weekly challenge deadline is due in several days from now (June 9, 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: Fahrenheit and Celsius Scales Intersection

Write a script that computes the equal point in the Fahrenheit and Celsius scales, knowing that the freezing point of water is 32 °F and 0 °C, and that the boiling point of water is 212 °F and 100 °C. This challenge was proposed by Laurent Rosenfeld.

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.