Skip to content

Instantly share code, notes, and snippets.

Day 11 -- Packaging with Libarchive

Distributing physical gifts involves wrapping them up into packages, but suppose you want to distribute digital gifts. How can you use Raku to help you wrap them up? Enter Libarchive!

Simple wrapping files into a package

Let's wrap up just two files, myfile1 and myfile2 into a single package.zip file. (Libarchive just as easily creates tar files, cpio, rar, even iso9660 images for cds or dvds.)

@CurtTilmes
CurtTilmes / gist:0cbc7e821fc172aa9953e0d44794fe15
Last active April 11, 2019 17:27
Playing with Redis Streams
use Redis::Async;
my $r = Redis::Async.new("localhost:6379", :0timeout);
sub xread(*@streams, Int :$timeout = 0, Bool :$add-stream, Bool :$add-id)
{
supply {
my %streams = @streams.map: * => '$';
loop {
with $r.XREAD('block', $timeout, 'streams',
@CurtTilmes
CurtTilmes / gist:bd3b515a6995c473990635e73a4b34a5
Created March 28, 2019 23:12
Start of a CStructArray module
use NativeCall;
class foo is repr('CStruct')
{
has int32 $.a is rw;
has int64 $.b is rw;
}
sub calloc(size_t, size_t --> Pointer) is native {}
sub free(Pointer) is native {}
@CurtTilmes
CurtTilmes / Testit.pm6
Last active December 16, 2017 20:01
Error demonstration
class AnotherTestClass
{
has Str @.something;
}
sub myfunc(% (:%book (Str:D :$title, Str:D :$author), Int :$count,
:@tags ($first-tag, *@other-tags)) )
{...}
class Book {
has $.title;
has $.author;
has $.count;
has @.tags;
}
my @booklist =
Book.new(title => 'A Christmas Carol',
author => 'Charles Dickens',
for @itemlist -> % (:%book (Str:D :$title, Str:D :$author), Int :$count,
:@tags ($first-tag, *@other-tags))
{
say "$title, $author, $count, @tags[], $first-tag, @other-tags[]"
}
use JSON::Fast;
my $item = from-json(q:to/END/);
{
"book" : {
"title" : "A Christmas Carol",
"author" : "Charles Dickens"
},
"count" : 12,
"tags" : [ "christmas", "santa"]
}
sub myfunc(%h) {
die "a must be an Int" unless %h<a> ~~ Int;
die "b must be a Str" unless %h<b> ~~ Str;
die "c must be a Rat" unless %h<c> ~~ Rat;
my $a = %h<a>;
my $b = %h<b>;
my $c = %h<c>;
}
sub myfunc(%h) {
die "a must be an Int" unless %h<a> ~~ Int;
die "b must be a Str" unless %h<b> ~~ Str;
die "c must be a Rat" unless %h<c> ~~ Rat;
}