Accessible via https://keybase.pub/michelc/repo/carep/filestore
Last active
July 3, 2021 06:10
-
-
Save michel47/9827996505667b725046e7765f31fbc4 to your computer and use it in GitHub Desktop.
CAREPOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
pandoc -o README.html README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# this script take any data and make an image with it (format .ppm) | |
# $Previous: QmPYNQMhMbMjQed32su9q5eNCGurGozhbiSSrh6oGf2Dva$ | |
# deps | |
# convert from ImageMagick | |
# ipfs to push files to carep repository | |
our $dbug=0; | |
#-------------------------------- | |
# -- Options parsing ... | |
# | |
my $if = undef; | |
my $of = undef; | |
my $ratio = undef; | |
while (@ARGV && $ARGV[0] =~ m/^-/) | |
{ | |
$_ = shift; | |
#/^-(l|r|i|s)(\d+)/ && (eval "\$$1 = \$2", next); | |
if (/^-v(?:erbose)?/) { $verbose= 1; } | |
elsif (/^-?if?=?([\w.]+)?/) { $if= $1?$1:shift; } | |
elsif (/^-?of?=?([\w.]+)?/) { $of= $1?$1:shift; } | |
elsif (/^-?r=?([\w.]+)?/) { $ratio= $1?$1:shift; } | |
else { die "Unrecognized switch: $_\n"; } | |
} | |
#understand variable=value on the command line... | |
eval "\$$1='$2'"while $ARGV[0] =~ /^(\w+)=(.*)/ && shift; | |
my $data; | |
if (! defined $of) { | |
if (@ARGV) { $of = pop @ARGV } | |
else { $of = '-' } | |
} | |
if (defined $if) { | |
local *IN; | |
local $/ = undef; | |
open IN,'<',$if; | |
$data = <IN>; | |
close IN; | |
} else { | |
if ($ARGV > 0) { $if = '<>'; } | |
elsif ($#ARGV == 0) { $if = $ARGV[0]; } | |
else { $if = '-'; } | |
local $/ = undef; | |
$data = <>; | |
close STDIN; | |
} | |
my $size = length($data); | |
my $pi = atan2(0,-1); | |
#my $iratio = 4/3; # y/x | |
my $iratio = $ratio || $pi; # x/y | |
my $xy = $size/3 * ($iratio); | |
my $x = sqrt($xy); | |
if ($verbose) { | |
printf STDERR "if: %s\n",$if; | |
printf STDERR "of: %s\n",$of; | |
printf STDERR "size: %s\n",$size; | |
printf STDERR "x: %.3f\n",$x; | |
printf STDERR "y: %.3f\n",$x / $iratio; | |
} | |
my $y = int($x / $iratio + $iratio); | |
$x = int( ( $size / 3 + $y - 1) / $y ); | |
my $n = $x*$y*3; | |
my $delta = $n - $size; | |
if ($delta < 0) { | |
$x++; | |
$n = $x*$y*3; | |
$delta = $n - $size; | |
} | |
my $pad = "\x00" x $delta; | |
if ($verbose) { | |
printf STDERR "playload: %sx%s = %s\n",$x,$y,$n; | |
printf STDERR "delta: %s\n", $delta; | |
} | |
my $hdr = <<"EOS"; | |
P6 | |
$x $y | |
255 | |
EOS | |
#my $fname = $file; $fname =~ s,.*/,,; | |
#my $bname = $fname; $bname =~ s/\.[^\.]*$//; | |
#printf STDERR "fname: %s\n",$fname; | |
#printf STDERR "fname: %s.png\n",$bname; | |
local *PPM; open PPM,"| convert -compress LZW -strip -quality 90 ppm:- $of"; | |
print PPM $hdr; | |
binmode(PPM); | |
print PPM $data; | |
print PPM $pad; | |
close PPM; | |
$ENV{IPFS_PATH} = '/run/user/1000/keybase/kbfs/public/'.$ENV{USER}.'/repo/carep'; | |
local *EXEC; open EXEC, "ipfs add -Q --pin=false -w --raw-leaves --trickle --chunker size-1048576 --hash sha1 $of --cid-base base58btc |"; | |
my $qm=<EXEC>; chomp($qm); | |
printf "qm: %s\n",$qm; | |
close EXEC; | |
local *QMLOG; open QMLOG,'>>',$ENV{IPFS_PATH}.'/filestore/qm.log'; | |
printf QMLOG "%u: %s\n",time,$qm; | |
close QMLOG; | |
exit $?; | |
1; # $Source: /my/perl/scripts/dat2png.pl$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- # QmLog for all CAREP files | |
1625289269: z8bvj1i9DPsnNW7GeXL6WLnraKX23hSe8 | |
1625289667: z8bvizx2yHXyMLGejC1mZX44PHUtgKCeN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
export IPFS_PATH=$PWD/.. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment