Skip to content

Instantly share code, notes, and snippets.

View fskale's full-sized avatar

Franz Skale fskale

View GitHub Profile
@fskale
fskale / cpu-stat.pl
Last active July 28, 2018 09:50
CPU Usage percentage summary using Mojolicious Non-blocking IO (EV) feature.
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::File 'path';
use Mojo::Collection 'c';
use Mojo::IOLoop;
BEGIN {
#only linux is supported !
#!linux
die( sprintf( "OS %s not supported !\n", $^O ) ) if $^O ne 'linux';
@fskale
fskale / cpu-stats-nb.pl
Created August 3, 2018 09:15
Non Blocking CPU Stats (1s) using Mojo::IOLoop:Delay
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::File 'path';
use Mojo::Collection 'c';
use Mojo::IOLoop;
use Mojo::JSON 'j';
BEGIN {
#only linux is supported !
#!linux
@fskale
fskale / disk-stats-nb.pl
Created August 6, 2018 08:51
Non-blocking disk stats using Mojolicious Framework
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::File 'path';
use Mojo::Collection 'c';
use Mojo::IOLoop;
use Mojo::JSON 'j';
use Mojo::Util 'getopt';
use Number::Bytes::Human;
BEGIN {
@fskale
fskale / write-nb.pl
Created June 6, 2019 08:30
Write delayed but non-blocking to STDOUT using Mojolicious ! (E.g. progress to STDOUT)
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::IOLoop::Stream;
use Mojo::IOLoop::Delay;
use Mojo::ByteStream 'b';
# Create stream
my $stream = Mojo::IOLoop::Stream->new(\*STDOUT)->timeout(0);
my $text
= b(
@fskale
fskale / ojo-find-mtime.pl
Created June 6, 2019 09:38
Mojo oneliner to find files that were modified e.g. < 1 week (depth 2 subdirs) and print the the modification time and and the age in seconds !
perl -E 'use Mojo::File "path"; use Cwd "cwd"; my $cwd=cwd(); say path(qq{$cwd})->list_tree({dir => 0, max_depth => 3})->map( sub { my $mtime = path($_)->lstat->mtime; time() - $mtime < 86400 ? sprintf("%s %d %d", $_, path($_)->lstat->mtime, time() - $mtime ) : undef;})->compact->join("\n");'
@fskale
fskale / dns.pl
Created July 11, 2019 10:41
Non-Blocking DNS Resolution using Net::DNS::Native and Mojo::IOLoop::Delay
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::IOLoop::Delay;
use Net::DNS::Native;
use Socket qw(:addrinfo IPPROTO_UDP SOCK_DGRAM);
my $dns = Net::DNS::Native->new(pool => 5, extra_thread => 1);
my $d = Mojo::IOLoop::Delay->new;
@fskale
fskale / s3-backup.pl
Last active September 4, 2019 10:18
S3 incremental Backup using Mojolicious Non-Blocking I/O (concurrent) (Check Script for required modules) supports Amazon and Hitachi S3 storages (no warranty !)
#!/usr/bin/env perl
package S3::Backup;
use Mojo::Base -base;
use Carp qw(carp croak);
use POSIX qw(strftime ceil floor);
use Fcntl qw(O_WRONLY O_APPEND O_CREAT);
use Fcntl ':mode';
#set utf8 output encoding explicitly
binmode( STDOUT, ":encoding(utf8)" );
@fskale
fskale / gen-moref-op.pl
Last active March 24, 2020 10:27
async/await/non-blocking I/O demo (Vmware MOREF -> operations JSON mapper - concurrency via recursive queuing - live fetching)
#!/usr/bin/env perl
package Vmware::Moref::Operations;
use Mojo::Base -base, -signatures, -async_await;
use Mojo::Collection 'c';
use Mojo::DOM;
use Mojo::JSON 'j';
use Mojo::Promise;
use Mojo::URL;
use Mojo::UserAgent;
@fskale
fskale / hwg.wsdl
Last active January 15, 2021 15:07
Valid HWG-SMS-GW3 WSDL Definition File (Works for Firmware version 1.2.x !)
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:pos="poseidonService.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="poseidonService.xsd"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
@fskale
fskale / async-dns.pl
Last active June 24, 2023 16:43
Async (using Mojolicious, and Future::AsyncAwait) DNS resolution demonstration !
#!/usr/bin/env perl
use 5.026;
use Mojo::Base -strict, -signatures, -async_await;
use Mojo::Promise;
use Socket qw(:addrinfo IPPROTO_UDP SOCK_DGRAM AF_INET AF_INET6);
use Mojo::Collection 'c';
use Net::DNS::Native;
sub _resolve_host ($host, $resolve, $reject) {