Skip to content

Instantly share code, notes, and snippets.

@tommybutler
tommybutler / Snapshot_2024_07_11_00.pm
Created July 11, 2024 20:41
CPAN autobundle example format
package Bundle::Snapshot_2024_07_11_00;
$VERSION = '0.01';
1;
__END__
=head1 NAME
my $start = scalar localtime;
my @records = ( 'some', 'dbi', 'fetchrow', 'hashrefs' );
$promises->{first}->then
(
sub
{
warn 'DONE WITH FIRST PROMISE';
warn 'START: ' . $start;
warn 'FINISH: ' . scalar localtime;
@tommybutler
tommybutler / map.pl
Last active July 9, 2021 20:12
library method that calls Mojo::Promise->map()
return Mojo::Promise->map
(
{ concurrency => 10 },
sub
{
my $record = $_;
my $promise = Mojo::Promise->new();
Mojo::IOLoop->subprocess->run
(
@tommybutler
tommybutler / promise.pl
Last active July 9, 2021 20:16
Mojo Promise Map Concept
# inside my mojo route...
my $result = $library->run_object_method_that_runs_mojo_promise_map();
if ( Scalar::Util::blessed( $result ) && $result->isa( 'Mojo::Promise' ) )
{
$c->render_later();
my $start = scalar localtime;
#!perl
use strict;
use warnings;
use 5.020;
my $cap = 10;
my @ints =
qw(
6.1
@tommybutler
tommybutler / mojo-email-a-pdf.pl
Last active June 26, 2020 17:35
Email a PDF with Mojolicious::Plugin::Mail, and PDF::WebKit
my $pdf = 'my-html-template-for-conversion-to-pdf'; # needs to be a .html.ep template
my $mail = 'my-template-for-the-html-email'; # needs to be a .mail.ep template
$pdf = $c->render_to_string( $pdf )->to_string();
$pdf = PDF::WebKit->new( \$pdf, %pdf_opt )->to_pdf(); # see PDF::WebKit documentation for details
$c->mail
(
mail =>
{
@tommybutler
tommybutler / get_file_types.sh
Created October 2, 2019 14:01
get unique list of file suffixes (types) in current directory tree, recursively
find . -type f | perl -nE '$_ =~ s/.*\///g ; $_ =~ m/.+\..+$/ && $_ =~ s/.*\./\./ && say $_' | sort | uniq
@tommybutler
tommybutler / storage-util-by-atime.pl
Created May 14, 2019 00:31
bracketize utilized disk by last-access time in months
#!perl
use strict;
use warnings;
use Data::Dumper;
my $last_access = {};
my $tot = 0;
my $cnt = 0;
@tommybutler
tommybutler / ClassProxyExample.pm
Last active August 16, 2018 11:17
Proxy an entire class in Perl OOP, in order to memo-ize method calls
use strict;
use warnings;
package My::Class::Proxy; # Drop-in replacement for 'Some Class'
# Proxies all public method calls to Some::Class in order to provide smart
# caching and memoization, e.g.- avoiding expensive DB queries when not required
use 5.020;
use Moose;
@tommybutler
tommybutler / clone-to-usb.log
Created August 11, 2018 21:33
rylan restore log
Clonezilla mode is device-image
ocsroot device is local_dev
Umounting the existing /home/partimag...
Preparing the mount point /home/partimag...
If you want to use USB device as a Clonezilla image repository, please
* Insert USB device into this machine *now*
* Wait for about 5 secs
* Press Enter key
so that the OS can detect the USB device and later we can mount it as /home/partimag.
Press "Enter" to continue......