Skip to content

Instantly share code, notes, and snippets.

@librasteve
librasteve / lpq-html.raku
Last active June 6, 2021 20:52
Low Profile Quoting for HTML as Raku Script
#slightly tweaked example of gfldex Low profile quoting post
#viz. https://gfldex.wordpress.com/2021/06/01/low-profile-quoting/
#viz. https://p6steve.wordpress.com/2021/06/04/414/
#in Comma IDE set ⌘, - editor - color scheme - raku - bad syntax OFF
constant term:<§> = class :: does Associative {
sub qh($s) {
$s.trans([ '<' , '>' , '&' ] =>
[ '&lt;', '&gt;', '&amp;' ])
}

#Santa and the Magic Tree (M-Tree)

It was Christmas Eve in the Workhouse and Santa was getting worried about how the weight of all those presents would reduce the height of his sled's flighpath. Would he be able to clear the height of the tallest Christmas trees on his worldwide journey?

He asked one of his helpers to whip up a quick script to see how much danger he would be in and in stepped p6elf to do the job.

Naturally p6elf (pronounced "Physics Elf") wanted to show off his raku skills to grow his reputation with Santa, the reindeer and all the other elves (knowing how much Santa is into the whole raku thing). So he started by picking up two modules and mixing them together. To share with the others so that they could see how they could easily make their own models so he used Brian Duggan's cool Jupyter notebook module.

#This setup cell inherits from the Math::Polygons classes such as Point and Triangle provided by Math::Polygons and overrides their 
root@c99e221dd07f:~/raku-Dan-Polars/bin# ./synopsis-dan-polars.raku
===SORRY!=== Error while compiling /root/raku-Dan-Polars/bin/./synopsis-dan-polars.raku
Index out of range. Is: 2, should be in 0..0
at /root/raku-Dan-Polars/bin/./synopsis-dan-polars.raku:6
root@c99e221dd07f:~/raku-Dan-Polars/bin# raku --ll-exception synopsis-dan-polars.raku
Index out of range. Is: 2, should be in 0..0
at SETTING::src/core.c/Exception.pm6:62 (/root/rakudo/bin/../share/perl6/runtime/CORE.c.setting.moarvm:throw)
from SETTING::src/core.c/CompUnit/PrecompilationRepository.pm6:91 (/root/rakudo/bin/../share/perl6/runtime/CORE.c.setting.moarvm:)
from SETTING::src/core.c/CompUnit/PrecompilationRepository.pm6:89 (/root/rakudo/bin/../share/perl6/runtime/CORE.c.setting.moarvm:)
from SETTING::src/core.c/CompUnit/PrecompilationRepository.pm6:88 (/root/rakudo/bin/../share/perl6/runtime/CORE.c.setting.moarvm:)
@librasteve
librasteve / gist:c733fb6c9ad761f02545c4ff0b1fda32
Created July 11, 2022 17:21
raku Dan::Polars read_csv, to-dataset example
#!/usr/bin/env raku
use lib '../lib';
use Dan;
use Dan::Polars;
my \df = DataFrame.new;
df.read_csv("../dan/src/iris.csv");
df.head;
@librasteve
librasteve / gist:afdfaae596038361e79579345e4f2c08
Created August 4, 2022 20:55
raku, Inline::Perl5 and PHP::Serialize
#phpsmake.php
1 #!/bin/env php
2 <?php
3
4 $array = [
5 "foo" => "bar",
6 "bar" => "foo",
7 ];
8
9 #print( var_dump($array) );
@librasteve
librasteve / synopsis-dan-polars6.raku
Created August 29, 2022 14:49
DSL Generation of Dan::Polars query code in raku
#!/usr/bin/env raku
use lib '../lib';
#`[
### Example Raku code generation from DSL ...
use DSL::English::DataQueryWorkflows;
my $command = 'use starwars;
select species, mass & height;
use JSON::Fast;
#needs $HOME/.aws/credentials
my $et = time; #for unique names
#make key pair
my $key-name = "MyKeyPair$et";
qqx`aws ec2 create-key-pair --key-name $key-name --query 'KeyMaterial' --output text > MyKeyPair.pem`;
qqx`chmod 400 MyKeyPair.pem`;
use YAMLish;
use JSON::Fast;
# uses $HOME/.aws/credentials
my $et = time; # for unique names
class Session {
class KeyPair {
has $.dir = '.';
has $.name;
use YAMLish;
use JSON::Fast;
# uses $HOME/.aws/credentials
my $et = time; # for unique names
class Session {
class KeyPair {
has $.dir = '.';
has $.name;
@librasteve
librasteve / gist:624fe58c68df87528fe5e97d35068496
Created February 7, 2023 21:49
Filter::Simple:from<Perl5> Test
#1 Build & Run this Dockerfile
git clone https://github.com/p6steve/raku-Dan-Paddle.git
# you are welcome to follow the Dockerfile steps (from the Inline::Perl5 installation guidance) in your env
cd raku-Dan-Paddle
docker build -t test .
docker run -it test
#2 Install Deps
cpanm install Filter::Simple