Skip to content

Instantly share code, notes, and snippets.

@s1037989
s1037989 / job_queue
Last active July 31, 2020 03:52
Bash Job Queue
#!/usr/bin/env bash
# Original: https://hackthology.com/a-job-queue-in-bash.html
# This is a modification that adds receiving "work" from a named pipeline
# Run the job queue and then just pass "work" to it whenever:
# $ q H1 ls -l /tmp
# $ q H2 date
# $ q H1 sleep 4
# $ q H3 echo hi
usage() {
$ echo -n -e "\x3c\x97\x0e\x1d\x3f\x07\xf8\x32\xe4\xc0\x48\xab\x00\x02\x61\x62" | sudo socat -t 1 -lu -x -d -d -d -d - SOCKET-SENDTO:17:3:0:x0003x02000000x0000x00x06x3c970e1d3f070000
2020/06/22 04:34:56.306263 socat[762494] D getpid()
2020/06/22 04:34:56.306315 socat[762494] D getpid() -> 762494
2020/06/22 04:34:56.306322 socat[762494] D setenv("SOCAT_PID", "762494", 1)
2020/06/22 04:34:56.306329 socat[762494] D setenv() -> 0
2020/06/22 04:34:56.306332 socat[762494] D setenv("SOCAT_PPID", "762494", 1)
2020/06/22 04:34:56.306337 socat[762494] D setenv() -> 0
2020/06/22 04:34:56.306341 socat[762494] I socat by Gerhard Rieger and contributors - see www.dest-unreach.org
2020/06/22 04:34:56.306345 socat[762494] I This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)
2020/06/22 04:34:56.306349 socat[762494] I This product includes software written by Tim Hudson ([email protected])
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
@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
$ 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=()
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