Skip to content

Instantly share code, notes, and snippets.

@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);
package Mojo::UserAgent::Role::AWSSignature4;
use Mojo::Base -role;
use Digest::SHA;
use Time::Piece;
has access_key => sub { $ENV{AWS_ACCESS_KEY} or die 'missing "access_key"' };
has aws_algorithm => 'AWS4-HMAC-SHA256';
has expires => 86_400;
has region => 'us-east-1';
@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';
@s1037989
s1037989 / json2tsv
Last active December 16, 2018 05:27
use ojo;
no warnings;
my $j = j(<>);
my %c = ();
$c{$_}++ foreach map { keys %$_ } @$j;
my @c = sort keys %c;
say join "\t", @c;
say join "\t", @$_{@c} foreach @$j;