Dave Cross posted a photo:

Pareidolia

via Instagram ift.tt/2ZjZHHe

@davorg
davorg pushed to master in davorg/template-plugin-audiofile-info Aug 16, 2019
1 commit to master
@davorg
davorg pushed to master in davorg/audiofile-info Aug 16, 2019
1 commit to master
  • @davorg f4abaa9
    Added Dummy.pm to MANIFEST. Bumped version.
@davorg
davorg pushed to master in davorg/template-plugin-audiofile-info Aug 16, 2019
1 commit to master
  • @davorg a330fc2
    Use dummy plugin in tests
@davorg
davorg pushed to master in davorg/audiofile-info Aug 16, 2019
1 commit to master
@davorg
davorg pushed to master in davorg/audiofile-info Aug 16, 2019
1 commit to master

Dave Cross posted a photo:

Gonna be studying this over the weekend

via Instagram ift.tt/2N7GzWf


Some thoughts on ways to measure the quality of Perl code (and, hence, get a basis for improving it)

How (and why) I spent 90 minutes writing a Twitterbot that tweeted the Apollo 11 mission timeline (shifted by 50 years)

A talk from the European Perl Conference 2019 (but not about Perl)

Last week I was in Riga for this year’s European PerlCon (the conference formerly known as YAPC::Europe). As has become traditional, here’s my report of the conference.

My conference began on Tuesday night at the pre-conference meet-up. Most people get into town on the night before the conference starts and the organisers always designate a local bar as a meeting place. This time, as the conference was being held in a hotel, the meeting place was a room in the hotel just outside the main conference room. It’s always good to meet up with friends who you might not have seen since the previous conference and I spent a pleasant hour or two, chatting to people before wandering back over the river to the hotel where I was staying before the conference started. As I walked back over the bridge, I could hear the dulcet tones of Rammstein playing a gig about 4km downstream.

The first day of the conference proper was slightly complicated by the need to check out of one hotel and into another. Effectively, it meant that I spent a lot of the day without a room – which was slightly annoying.

The first keynote was Sawyer X talking about The past, the present, and one possible future of Perl 5. From talking to other people afterwards, I think most of the audience was as impressed by his vision as I was. I particularly look forward to hearing more about his plans to engage more companies in the development of Perl. I think that is a great idea.

Following a coffee break, I saw Thomas Klausner talking about Deploying Perl Apps using Docker, Gitlab & Kubernetes. This is a particular area of interest to me currently and it was interesting to see his take on it. I followed that by watching Mohammad Anwar encouraging people to start contributing to CPAN.

After lunch, I took a brief break from the conference (I guess that’s a benefit to knowing that the videoing of the talks is in really capable hands!) I returned in time to see Kenichi Ishigaki describing Recent PAUSE Changes. Because the overall UI of the site has barely changed, I had failed to spot the wholesale changes that have been taking place behind the scenes. It was interesting to be brought up to date.

After the coffee break, I saw Curtis Poe’s talk on Testing Lies. The big takeaway from that seems to be to never trust anyone who claims that something is “always true”.

Then came the first set of lightning talks. As usual, it was a wide-ranging selection including me talking about my Apollo 11 Twitterbot. I particularly enjoyed Job’s amusing walk down memory lane.

After the conference ended for the day there was a new (as far as I know) experiment for a Perl conference – a cocktail party for people who had bought specific kinds of tickets. I had been invited and went along, only to be slightly surprised to find that the drinks selection didn’t include cocktails. I was further surprised to bump into someone who I used to work with back in 2004 and we spent most of the evening catching up.

The second day started with Liz Mattijsen’s keynote DeMythifying Perl 6. I was surprised when she stated that “Perl 6 has damaged Perl 5” was not a myth, but a fact and was totally blown away when she followed that up with a proposal to rename Perl 6. I’ve been saying for ten years that the only thing I don’t like about Perl 6 is its name and I’m really excited to see core Perl 6 developers finally agreeing with this. I’ll be following the developments here really closely.

I then watched Hauke Dämpfling’s WebPerl – Run Perl in the Browser! – which was certainly very clever, but I’m not sure how useful it is. Then I gave my first long talk of the conference – Monoliths, Balls of Mud and Silver Bullets. I think it went well. I certainly got some interesting questions after it.

I’m not really sure what happened after lunch. I think I went back to my room for a bit of lie down and the next thing I knew it was time for the second day of lightning talks. Before that, there were presentations by the two teams vying to organise next years conference (in either Amsterdam or Limassol) and then this year’s attendees got to vote to choose the winner (that’s what’s going on in the photo above). The winner (by only seven votes) was Amsterdam.

I was slightly embarrassed when Lee Johnson mentioned in his lightning talk that my amazing(!) SEO work for last year’s conference meant that Google still thinks all Perl conferences take place in Glasgow – I should probably work out how to fix that! Best of this set of lightning talks was Mark Keating’s adaptation of Dr. Seuss’s “The Sneetches”.

That evening, the attendees’ dinner took place. This was at the same beer hall that the same event took place at the last time the conference was in Riga. Much buffet was had and a lot of beer was drunk.

Day three started in a slightly more muted vein (it often does – as the attendees’ dinner is always on the second night). I missed the keynote and only made it in time for Mohammad Anwar’s second talk of the conference. This one was on how to Protect your Perl script from common security issues. I had to skip out before he got to the questions as I needed to set up in another room for my final talk of the conference – Measuring the Quality of your Perl Code. I was rather (pleasantly) surprised to see the room was completely full and people seemed to find it useful and interesting.

I took the afternoon easy again. I saw Robert Acock on Progressive Web Applications (something else, I really want to get to know about – and I have the feeling it’s not as complicated as my brain seems to want to make it) and Mallory on Designing and Coding for Low Vision.

Then it was time for the final set of lightning talks. It was great to see Thomas re-running his Acme::ReturnValues talk from 2008 (in celebration of the fact that this was the 20th European Perl Conference).

And then it was over. Andrew Shitov, the organiser, thanked all the helpers, speakers and sponsors. And then some of us went off on a cruise on the river.

The post PerlCon Europe 2019 appeared first on Perl Hacks.

Dave Cross posted a photo:

Cat House, Rīga

via Instagram ift.tt/2YXRXpY

Dave Cross posted a photo:

Sunset in Riga

via Instagram ift.tt/2KC0Bp4

Dave Cross posted a photo:

Photo

via Instagram ift.tt/2KgTXp5

I said that I probably wouldn’t have time to get involved with the Perl Weekly Challenge every week and that has, unfortunately, proven to be the case. But I had a few free minutes earlier in the week so I decided to look at this week’s challenges. I’m glad I did because they seemed to fit the way my brain works pretty well and I had solutions written rather quickly.

Challenge 1: Write a script to display months from the year 1900 to 2019 where you find 5 weekends i.e. 5 Friday, 5 Saturday and 5 Sunday.

This would be simple enough to just brute-force. But when I started to think about it, I realised there’s a bit of a trick we can use which can cut down our search space quite significantly.

If we’re looking for a month with five Fridays, Saturdays and Sundays then we need a month with 31 days (as four weeks is twenty-eight days and we need three extra days). Only seven months ever have 31 days – January, March, May, July, August, October and December. There is no point at all in ever looking in any other month. You might also realise that those three extra days need to be Friday 29th, Saturday 30th and Sunday 31st. And that means that the first day of the month also needs to be a Friday.

So, the problem simplifies to “Find months with 31 days where the 1st is a Friday”. And here’s the code I wrote to do that:

#!/usr/bin/perl

use strict;
use warnings;
use feature 'say';

use Time::Piece;

# Array of months with 31 days
my @months = (qw[Jan Mar May Jul Aug Oct Dec]);
my $format = '%Y-%b';

for my $y (1900 .. 2019) {
  for my $m (@months) {
    # Get the first day of the month as a Time::Piece object
    my $first = Time::Piece->strptime("$y-$m", $format);
    # Print the date if the 1st is a Friday
    say $first->strftime('%b %Y') if $first->day eq 'Fri';
  }
}

I’ve seen a few other solutions published and people seem to split into one group who spotted the shortcuts and another who didn’t. But the actual solutions seem very similar. Some people used DateTime instead of Time::Piece and others used low-level functions like timelocal().

Challenge 2: Write a script that can wrap the given paragraph at a specified column using the greedy algorithm.

Honestly, I didn’t think very hard about this at all. I just read the Wikipedia description of the algorithm and wrote a pretty much word-for-word Perl translation of that.

#!/usr/bin/perl

use strict;
use warnings;

use constant SPACE => ' ';
use constant SPACE_WIDTH => length(SPACE);

my $line_len = shift || 72; # Old-skool Unix

my $text = join ' ', <DATA>;

my $space_left = $line_len;

for (split /\s+/, $text) {
  if (SPACE_WIDTH + length() > $space_left) {
    print "\n$_" . SPACE;
    $space_left = $line_len - length();
  } else {
    print $_ . SPACE;
    $space_left -= (length() + SPACE_WIDTH);
  }
}

print "\n";

__DATA__
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis volutpat,
ipsum nec luctus dictum, velit nisi sodales dui, ut feugiat risus dolor
vel metus. Morbi ut pretium velit. Proin ultricies enim magna, at semper
odio molestie vitae. In hac habitasse platea dictumst. Fusce non sapien
bibendum ligula pellentesque volutpat in et lectus. Vestibulum ante ipsum
primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Vestibulum sodales molestie dignissim.

Next week is all about the European Perl Conference so I very much doubt if I’ll have time to try the Perl Weekly Challenges. But I hope to be able to try more of the problems in the coming weeks.

The post Counting Weekends and Wrapping Text appeared first on Perl Hacks.

It’s only two weeks until I head to Riga for PerlCon 2019. I thought it was worthwhile posting a quick update confirming that I was going and telling you what I would be doing there.

Firstly, I’ve previously mentioned that I was planning to run my “Modern Web Development with Dancer” workshop on the day before the conference. That’s now not going to happen as we didn’t manage to sell enough tickets to make the workshop economically viable.

But I will be giving two talks at the conference. On day two (Thursday) I’ll be speaking on Monoliths, Balls of Mud and Silver Bullets. That’s at 12:30 in the main room. This is a version of a talk I tried out at a London Perl Mongers technical meeting back in February. It’s a not-entirely-serious look at some of the problems you might encounter when replacing old monolithic code with new, shiny micro-services. Then on day three (Friday) I’ll be giving a longer talk on Measuring the Quality of your Perl Code. That’s, again, at 12:30, but in the second room. This does exactly what its title says. We’ll look at some measurements you can use to determine how good your Perl code is and ways to make those measurements automatic.

I have also submitted a proposal for a lightning talk. It’s about a Twitter bot that I wrote last weekend called Apollo 11 at 50 so, hopefully, you’ll find that interesting if you’re interested in either space or Twitter bots.

I’ll be a tourist in Riga for a few days before the conference. I’m arriving on Saturday 3rd August and leaving a week later on the 10th. Hope to see some of you there.

The post Perl Conference in Riga appeared first on Perl Hacks.

I’m not sure that I’ll have time to do these every week, but here are my answers to this week’s two Perl Weekly Challenges.

Challenge #1

Write a script to replace the character ‘e’ with ‘E’ in the string ‘Perl Weekly Challenge’. Also print the number of times the character ‘e’ found in the string.

use strict;
use warnings;
use feature 'say';

$_ = 'Perl Weekly Challenge';

my $count = tr/e/E/;

say;
say "$count changes";

Nothing really complicated here. We can discuss why I reached for tr/.../.../ rather than s/.../.../. I just think it’s silly to invoke the full power of the regex engine when you’re only changing a few letters.

Challenge #2

Write one-liner to solve FizzBuzz problem and print number 1-20. However, any number divisible by 3 should be replaced by the word fizz and any divisible by 5 by the word buzz. Numbers divisible by both become fizz buzz.

perl -E'say +(fizz)[$_ % 3] . (buzz)[$_ % 5] || $_ for 1 .. 20'

This is a bit more interesting. And I have to say that I think this is deeply dirty code. Over the twenty plus years I’ve been writing Perl I’ve trained myself to write code that is use strict and use warnings clean. This code is very much not that and with warnings turned on, you’d see a lot of warnings!

So how does it work?

The core is the (string)[index] construct.  We all know that you can access an individual element in an array with code like $my_array[$index]. But you can also do this with a list of values. For example:

('foo', 'bar', 'baz')[1]

returns “bar”. I often use this when I only need some of the values returned by localtime().

my ($d, $m, $y) = (localtime)[3, 4, 5];

Here, I’m using something very similar. (fizz)[$_ % 3] is looking up a value in a list that contains only a single value (the string “fizz”). So if the index is zero then we get the first (and only) value in the list. If the index is anything other than zero then we’re looking for an element that’s off the end of the list and Perl gives us undef, which is interpreted as an empty string. And the index expression, $_ % 3, gives us zero if $_ is exactly divisable by 3. There are two things here that would throw warnings under use strict and use warnings. Firstly, “fizz” is a bareword and secondly, we’re using undef in a concatenation.

We then repeat the same logic using “buzz” and 5 and we concatenate together the results of those two expressions. That gives us either “fizz”, “buzz”, “fizzbuzz” or the empty string. Of those values, only the empty string is seen as false, so we can use || $_ to replace that with the original number.

There’s one mystery left. Why have I put that + before the first expression? I think I’m going to leave that as an exercise for the reader. If you work it out, please leave a comment.

And there we have it. A solution that is simultaneously both horribly dirty and yet, I think, rather clever.

Have you come up with your own solution yet?

Update:

It’s been pointed out to me that my solution for challenge #2 prints “fizzbuzz” for 15, when the specification clearly asks for “fizz buzz” (with a space). So here’s a version which fixes that:

perl -E'@a=((fizz)[$_ % 3]//(),(buzz)[$_ % 5]//()), say @a?"@a":$_ for 1 .. 20'

The post Perl Weekly Challenge – 2019-03-25 appeared first on Perl Hacks.


I'm pretty sure this will make no sense whatsoever without me talking in front of it
Dave Cross / Monday 19 August 2019 08:03