Skip to content

Instantly share code, notes, and snippets.

@s1037989
s1037989 / upload.pl
Last active July 22, 2026 09:19
Mojo/S3/ResumableMultipartUpload.pm
package Mojo::S3::ResumableMultipartUpload;
use Mojo::Base -base, -signatures;
use Carp qw(croak);
use File::Basename qw(basename);
use File::Spec;
use File::Temp qw(tempfile);
use Mojo::File qw(path);
use Mojo::JSON qw(decode_json encode_json);
@s1037989
s1037989 / crc64nvme
Last active July 13, 2026 01:20
s3 resumable multipart uploads; extracts tars on the fly. All object uploads are broken into multiparts and resumable.
#!/usr/bin/env perl
use v5.22;
use strict;
use warnings;
use feature 'signatures';
use MIME::Base64 qw(encode_base64);
use constant {
POLY => 0x9A6C9329AC4BC9B5,
@s1037989
s1037989 / Util.pm
Last active June 8, 2026 22:12
Mojo::Log singleton in a Util package
# $ MOJO_LOG_LEVEL=info perl -Ilib -Mojo -MUtil=sq -E 'BEGIN { $Util::log = app->log; } a("/:n" => sub { $_->render(text => sq) })->start' get /5
# 36
# $ MOJO_LOG_LEVEL=trace perl -Ilib -Mojo -MUtil=sq -E 'BEGIN { $Util::log = app->log; } a("/:n" => sub { $_->render(text => sq) })->start' get /5
# [2026-06-08 17:10:33.96373] [87592] [trace] 6^2 = 36
# 36
package Util;
use Mojo::Base -strict, -signatures;
use Exporter qw(import);
#!/usr/bin/env perl
use v5.40;
use strict;
use warnings;
use Fcntl qw(SEEK_CUR);
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
use IO::Uncompress::Bunzip2 qw(bunzip2 $Bunzip2Error);
use IO::Uncompress::UnXz qw(unxz $UnXzError);
use Time::Piece qw(localtime);
@s1037989
s1037989 / bytecut.c
Created May 8, 2026 17:06
Efficiently read large binary chunks from stdin and print only the bytes in the ranges specified by the -b argument, similar to how cut works
// bytecut.c
// cc -O2 -Wall -Wextra -o bytecut bytecut.c
// $ head -c1024 /dev/urandom | bytecut -b 1-4,9- | wc -c
// 1020
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
Perl’s pack and unpack templates define how binary data is converted to and from Perl scalars. Below are practical examples for the most commonly used templates.
Basic Integer Templates
Signed / Unsigned 8-bit
c — signed char
my $bin = pack('c', -5);
my $num = unpack('c', $bin);
print "$num\n"; # -5
@s1037989
s1037989 / bindiff.pl
Last active May 5, 2026 02:32
A minimal Perl program that compares two binary files byte-for-byte, groups differing bytes into ranges, and prints each differing range in hexdump-like form for both files.
#!/usr/bin/env perl
# chmod +x bindiff.pl
# ./bindiff.pl old.bin new.bin
# Difference range: 0x00000010 - 0x0000001f
# old.bin:
# 00000010 41 42 43 00 ff 10 20 7e |ABC... ~|
# new.bin:
# 00000010 41 42 44 00 fe 10 21 7e |ABD...!~|
package OFP::Asset;
use Mojo::Base -strict, -signatures;
use Mojo::Collection qw(c);
use Mojo::File;
has [qw(fat oat)];
has [qw(core sup partner sil1 sil2 sil3)];
has warnings => sub { Mojo::Collection->new };
@s1037989
s1037989 / Makefile
Created February 5, 2026 02:36
DRM C app
CC ?= cc
CFLAGS ?= -O2 -Wall -Wextra
# Change if you want a stricter install path
LICENSE_PATH ?= /tmp/demo_license.txt
CFLAGS += -DLICENSE_PATH=\"$(LICENSE_PATH)\"
SECRET ?= DEMO-ONLY-SECRET-CHANGE-ME-KEEP-PRIVATE
EXPIRES ?= 2030-12-31
BIND_TYPE ?= hostname
BIND_VALUE ?= $$(hostname)
@s1037989
s1037989 / repo-si.pl
Last active November 12, 2025 10:46
repository software inventory generator
#!/usr/bin/env perl
use Mojo::Base -strict, -signatures;
use Mojo::File qw(path);
use Mojo::Collection qw(c);
use Mojo::ByteStream qw(b);
use Mojo::Util qw(getopt trim decamelize);
use constant DEFAULT_THRESHOLD => 0.60;
# ---- CLI -------------------------------------------------------------