Skip to content

Instantly share code, notes, and snippets.

package Provider;
use Mojo::Base -base, -signatures;
has 'log' => sub { Mojo::Log->new };
has 'model';
has [qw/ident token/] => sub { die };
sub get_token {
my ($self, $ident) = @_;
$self->ident($ident)->token(_token($ident)) if $ident;
@s1037989
s1037989 / pdf.pl
Last active January 24, 2020 15:22
Multi-page header-repeating table on template PDF
use Mojo::Base -strict;
use Mojo::Collection;
use Mojo::PDF;
use Mojo::Util 'dumper';
use PDF::API2;
use PDF::Table;
die "Usage: $0 template.pdf output.pdf" unless $ARGV[0] && $ARGV[1];
Mojo::PDF->new($ARGV[1], page_size => [792, 612])
@s1037989
s1037989 / snippets.cson
Created December 1, 2019 07:38
Atom Snippets for Mojolicious
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#

Objectives

  1. Easily provide and manage free SSL certs with Let's Encrypt for all virtual hosts
  2. Easily independently manage all virtual hosts as separate processes and user accounts -- which enables separate versions and libraries for various stages of the development life-cycle
  3. Easily spin up a new virtual host without opening ports or keeping track of all the port numbers that each app listens on -- all behind a single IP

What's Needed?

  1. nginx-1.15.12+
  2. certbot-auto 0.38.0+
  3. firewall passing 80/443 to nginx
  4. Web Apps
function diff_json {
T1=`mktemp -q -t json_diff.XXX`
T2=`mktemp -q -t json_diff.XXX`
jq . "$1" > $T1
jq . "$2" > $T2
diff -y $T1 $T2
rm -f $T1 $T2
}
function tar-manifest {
if [ -e Changes ]; then
@s1037989
s1037989 / 3cx.pl
Last active April 6, 2019 04:33
Expand 3cx Call Report into all timestamps
use Mojo::Base -strict;
use Mojo::ByteStream 'b';
use Mojo::Collection;
use Mojo::CSV;
use Mojo::Util qw(dumper sha1_sum);
use Time::Piece;
my ($SEED, $COUNTER) = ($$ . time . rand, int rand 0xffffff);
@s1037989
s1037989 / Mojo-UserAgent-Role-AWSSignature4.pm
Last active September 28, 2025 19:09
Use Mojo::UserAgent::Role::AWSSignature4 to interface with AWS REST API, such as controlling EC2 or working uploading and downloading S3 content. Works with S3-compatible APIs, of course, such as Digital Ocean Spaces and Wasabi.
package Mojo::UserAgent::Role::AWSSignature4;
use Mojo::Base -role, -signatures;
use Digest::SHA;
use Mojo::Collection;
use Time::Piece;
has access_key => sub { $ENV{AWS_ACCESS_KEY} or die 'missing "access_key"' };
has aws_algorithm => 'AWS4-HMAC-SHA256';
has content => undef;
@s1037989
s1037989 / mycookie
Created February 4, 2019 20:07
Mojolicious::Sessions-like Cookies
package Mojolicious::MyCookie;
use Mojo::Base -base;
use Mojo::JSON;
use Mojo::Util qw(b64_decode b64_encode);
has [qw(cookie_domain secure)];
has cookie_name => 'mycookie';
has cookie_path => '/';
has default_expiration => 3600;
use Mojo::Base -strict;
use Mojo::Util 'dumper';
use Mojo::File 'path';
use Mojo::ByteStream 'b';
my ($at, $qb) = map { b(path($_)->slurp)->split("\n") } @ARGV[0,1];
my %recon;
$at->grep(qr/^\d+\t/)->each(sub {
package Mojolicious::Command::router;
use Mojo::Base 'Mojolicious::Command';
use Mojo::Log;
use Mojo::UserAgent;
use Mojo::Server::Prefork;
use Mojo::File 'path';
use Mojo::Util qw'dumper getopt';
use Mojo::Collection 'c';
use Mojo::ByteStream 'b';