Skip to content

Instantly share code, notes, and snippets.

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 / 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);
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

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
@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:
#
@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])
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;
$ diff -y Untitled\ Document\ 1 Untitled\ Document\ 2
+ local cur prev words cword split + local cur prev words cword split
+ _init_completion -s + _init_completion -s
+ local exclude= flag outx errx inx OPTIND=1 + local exclude= flag outx errx inx OPTIND=1
+ getopts n:e:o:i:s flag -s + getopts n:e:o:i:s flag -s
+ case $flag in + case $flag in
+ split=false + split=false
+ exclude+== + exclude+==
+ getopts n:e:o:i:s flag -s + getopts n:e:o:i:s flag -s
+ COMPREPLY=() + COMPREPLY=()
@s1037989
s1037989 / gist:271e9f560bd7306c493e51fba1458cfa
Last active June 11, 2020 00:50
Nonblocking network socket programming
http://dwise1.net/pgm/sockets/blocking.html
https://gist.github.com/Alexey-N-Chernyshov/4634731
https://jameshfisher.com/2017/04/05/set_socket_nonblocking/
https://opensourceforu.com/2015/03/a-guide-to-using-raw-sockets/
https://squidarth.com/networking/systems/rc/2018/05/28/using-raw-sockets.html
Text::Unidecode (unidecode)
http://www.theunixschool.com/2012/08/getopts-how-to-pass-command-line-options-shell-script-Linux.html
use strict;
use warnings;
use Fcntl;
use Mojo::File qw(path);
use Mojo::Util qw(getopt);
use Socket qw(SOCK_RAW);
use Socket::Packet qw(
PF_PACKET
ETH_P_ALL
pack_sockaddr_ll unpack_sockaddr_ll recv_len