Stick a secret url in a qr code

There are a couple of qr code libraries on cpan, but I stopped looking when the first one worked:

cpanfile:

requires 'Image::PNG::QRCode', '0.10';
requires 'Mojolicious', '9.35';

$ carton install

qrthing:

#!perl

use Mojolicious::Lite -signatures;
use Image::PNG::QRCode 'qrpng';
use Mojo::Util 'b64_encode';

get '/' => sub ($c)  {
    my $blob  = qrpng(text => $c->url_for('sekrit', {code => 1234})->to_abs);
    $c->stash(template => 'index', 'img' => b64_encode $blob)
};

get '/sekrit/:code' => sub ($c) {
    $c->render(text => 'secret area');
}, 'sekrit';

app->start

__DATA__

@@ index.html.ep

Scan me: 
<img src="data:image/png;base64,<%= $img %>">

We can fire up the webserver the regular mojo way:

$ carton exec -- local/bin/hypnotoad ./qrthing

We've all seen a qr code before, so i think it's Ok to skip the screen shot...

That's it

I just think it's neat.

I like that perl has stuff like ...

... is a 3-in-one power house

I like that perl has stuff like ...

.. goes by many names, but it is actually 3 fairly neat things. perldoc

yada-yada - a placeholder for unimplemented code.

In void context ... is the "yada yada". It is fatal and dies with "unimplemented".

You can use this while planning out a module. You can quickly throw down a

sub write_me_later { ... }

... and when you call it (say from your tests) perl will remind you that you haven't written that sub yet.

A flip flop - with set/reset!

In scalar context it returns true after the thing on the left is true, until the thing on the right becomes true.

This is the set/reset behaviour of a "flip flop", and it is really helpful when parsing lines of a file.

while(<>) {
    if (/flip/.../flop/) {
        # every line between a flip and a flop (including the lines that do)
        say "flipped: $_"
    }
}

Simply /start-of-range/../end-of-range/ is true between those two matches.

Ranges - trade two numbers for many!

Unsurprisingly in list context ... gives a list, it works with similar rules to ++, so: - 1..10 gives you back the numbers you expect. - "OWF1".."OWF9" gives you back a list that includes "OWF6"

It's particularly handy for avoiding off-by-one's when looping over arrays:

for (0..$#array) { # No < @array... or is it <= @array?
    printf "I'm at index %s, which is: %s\n", $_, $array[$_] 
}

It all comes from context

I think it's very cool that 2 or 3 characters can do all of these things, and that their meaning comes entirely from the context.

That's it.

I just think that's neat.

I'll fix it later

proof-post-icon

Come on man, it's an emergency, and we need to fix this right away, so ...

"I'll fix it later"

I mean far be it from me to suggest that you're making that up.

I believe we should give people the benifit of the doubt.

People wouldn't simply lie during a code review to get me to approve a thing and then just ... never follow up...

so, show me one

Fundimentally, we have to assume we're working with good faith actors, right?

So it seems fair to just approve the PR, once they show a pair of commits where:

  • The first one sucks, but they said "i got u next time dawg" and
  • The second one actually fixed the suck from the first commit.