Skip to content

Instantly share code, notes, and snippets.

@s1037989
s1037989 / bash.txt
Last active March 3, 2023 03:33
Mojo::Promise
# Need a separate process to block to show what happens when a waiting for a non-blocking op
# 12 workers that each handle only 1 concurrent connection so that each connection can immediately be fulfilled and start the countdown
$ perl -Mojo -MTime::HiRes=time,sleep -E 'a("/#n" => sub { my $time = time; my $n = $_->param("n"); sleep $n; $_->render(inline => "<title>$n : Sleep <%= \$n %> seconds</title>", n => time - $time) })->start' prefork -w 12 -c 1
Web application available at http://127.0.0.1:3000
---
$ perl promise.pl 1 http://localhost:3000/4 http://localhost:3000/3 http://localhost:3000/2 http://localhost:3000/5 http://localhost:3000/6 http://localhost:3000/7
Getting 6 URLs starting at 1677811334.05866
$ mojo version
CORE
  Perl        (v5.34.0, linux)
  Mojolicious (9.30, Waffle)

OPTIONAL
  Cpanel::JSON::XS 4.09+   (n/a)
  EV 4.32+                 (n/a)
  IO::Socket::Socks 0.64+  (n/a)
use Mojo::Base -strict, -signatures;
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }
use Test::Mojo;
use Mojo::Server::Daemon;
use Mojo::URL;
use Mojolicious;
use Mojolicious::Lite;
@s1037989
s1037989 / proxy
Last active November 18, 2022 02:40
use Mojolicious::Lite -signatures;
app->ua->max_redirects(10);
# Just forward the response
any '/*whatever' => {whatever => ''} => sub ($c) {
my $proxy_to = Mojo::URL->new($c->req->headers->header('X-Proxy-To') || $ENV{PROXY_TO}) or return $c->reply->not_found;
#my $proxy_for = Mojo::URL->new($c->req->headers->header('X-Proxy-For') || $ENV{PROXY_FOR}) or return $c->reply->not_found;
my $req = $c->req;
my $method = $req->method;
bindir = /usr/bin
sharedir = /usr/share/my_app
all:
cpanm -L local --installdeps .
mkdir -p blib
cp -a script blib
cp -a lib blib
cp -a local/bin blib
cp -a local/lib/perl5/* blib/lib
$ perl -Mojo -E '
c(1,2,3)
->tap(sub{@$_ = (
{properties => {release => ["QQ_2022.08.1_rc1"], commit => [1]}},
{properties => {release => ["QQ_2022.08.1"]}},
{properties => {release => ["QQ_2022.07.1"]}}
)})
->map(sub{[
((grep { /^QQ_2022.08.1(_rc\d+)?$/ } @{$_->{properties}->{release}})[0]||undef),
((grep { $_ eq "1" } @{$_->{properties}->{commit}})[0]||undef)
@s1037989
s1037989 / pac
Last active August 16, 2022 22:28
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_PAC_file
// application/x-ns-proxy-autoconfig
// https://linuxconfig.net/manuals/howto/squid-and-ldap-authentication-from-active-directory.html
function FindProxyForURL(url, host) {
if (shExpMatch(host, "xyz*") && shExpMatch(url, "*:8123*")) {
return "PROXY w3proxy.mozilla.org:8080";
} else {
return "DIRECT";
}
}
@s1037989
s1037989 / sign.sh
Last active March 15, 2025 23:17 — forked from ezimuel/sign.sh
Sign and verify a file using OpenSSL command line tool. It exports the digital signature in Base64 format, and there are functions for storing the signature in the linux extended attributes.
function gen_keys {
[ -z "$1" ] && { echo "Usage: $FUNCNAME passphrase"; return 1; }
local passphrase="$1" privatekey=$(mktemp) publickey=$(mktemp)
openssl genrsa -aes128 -passout pass:"$passphrase" -out $privatekey 2048 >/dev/null
openssl rsa -in $privatekey -passin pass:"$passphrase" -pubout -out $publickey >/dev/null
printf "Private Key: %s\nPublic Key: %s\n" $privatekey $publickey
}
function sign_file {
[ -z "$2" ] && { echo "Usage: $FUNCNAME file privatekey publickey"; return 1; }
@s1037989
s1037989 / dropbox.conf
Created June 20, 2022 01:43
organize files dropped into a single dropbox folder based on their validated tags
{
dropbox => {
'cpa file' => '^sdk/SDKv\d+\.\d+\+\d{8}\.\d+\.tar(\.gz)?$',
'cpa file' => '^tk/TK-\d+\.\d+\+\d{8}\.\d+\.tar(\.gz)?$',
'cpa release file' => '^rc_bundles/XX\d_\d{4}\.\d{2}(\.\d+)?_rc\d+/.*?\.tar(\.gz)?$',
}
}
carmel carton Module::Build ExtUtis::MakeMaker
$ sudo apt install libpq-dev libssl-dev
$ \curl -L https://install.perlbrew.pl | bash
$ perlbrew use perl-5.36.0
$ perlbrew install-cpanm
# mojo.js vscode-mojo vscode-mojo.js nodejs16
$ cpanm Mojolicious Mojo::Pg Minion Mojo::SQLite Minion::Backend::SQLite Future::AsyncAwait Role::Tiny Cpanel::JSON::XS EV IO::Socket::SSL IO::Socket::Socks Net::DNS::Native Mojolicious::Plugin::Status JSON::Validator | grep ^Fetching | sed 's/Fetching \(.*\) ... OK/\1/'
http://www.cpan.org/authors/id/S/SR/SRI/Mojolicious-9.27.tar.gz
http://www.cpan.org/authors/id/S/SR/SRI/Mojo-Pg-4.27.tar.gz