Skip to content

Instantly share code, notes, and snippets.

View FCO's full-sized avatar

Fernando Correa de Oliveira FCO

View GitHub Profile
@FCO
FCO / quicksort.raku
Created August 9, 2023 13:10
destructing classify
multi quicksort([]) { Empty }
multi quicksort([$pivot, *@rest]) {
my (:@Less, :@Same, :@More) := @rest.classify(* cmp $pivot);
[ |quicksort(@Less), $pivot, |@Same, |quicksort(@More) ]
}
say quicksort [7, 2, 1, 8, 1, 9, 3]
@FCO
FCO / quicksort.raku
Created August 9, 2023 11:00
Quicksort using classify
multi quicksort([]) { Empty }
multi quicksort([$pivot, *@rest]) {
my %list{Order} is default([]) = @rest.classify: * cmp $pivot;
[ |quicksort(%list{Less}), $pivot, |%list{Same}, |quicksort(%list{More}) ]
}
say quicksort [7, 2, 1, 8, 1, 9, 3]
@FCO
FCO / events.rakumod
Created July 30, 2023 05:10
EEL thinking
enum Area <kanto johto hoenn sinnoh unova kalos alola>;
event Hot {
has Str $.type where * eq "temperature";
has Area $.area;
has Int $.value where * > 40;
}
event Dry {
has Str $.type where * eq "humidity";
@FCO
FCO / test-rakuast.raku
Created May 31, 2023 02:10
First investigation for Red using RakuAST
#!/usr/bin/env raku
use v6.e.PREVIEW;
# Bla.^all.map: { $_ + 1 };
say [1,2,3].map: { $_ + 1 };
CHECK {
sub translate-rakuast-to-redast($raku) {
return RakuAST::IntLiteral.new: 42
➜ Nats git:(main) nats pub --count=10 bla.ble.bli "test pub {{ Count }}"
19:58:50 Published 10 bytes to "bla.ble.bli"
19:58:50 Published 10 bytes to "bla.ble.bli"
19:58:50 Published 10 bytes to "bla.ble.bli"
19:58:50 Published 10 bytes to "bla.ble.bli"
19:58:50 Published 10 bytes to "bla.ble.bli"
19:58:50 Published 10 bytes to "bla.ble.bli"
19:58:50 Published 10 bytes to "bla.ble.bli"
19:58:50 Published 10 bytes to "bla.ble.bli"
19:58:50 Published 10 bytes to "bla.ble.bli"
use Cro::HTTP::Client;
use Red;
model ChatGPTConversation {
has Int $.id is serial;
has Str $.question is column;
has Str $.answer is column;
}
sub chat_with_gpt($prompt) {
@FCO
FCO / test.raku
Last active December 11, 2022 15:06
my @children-names = <Fernanda Sophia Eduardo Rafael Maria Lulu>;
my @countries = <Brazil England Scotland>;
factory "child", :model(Child), {
.name = { "{ @children-names.pick } { .counter-by-model }" };
.country = { @countries.pick };
}
@FCO
FCO / test.raku
Last active December 11, 2022 15:06
use Test;
use Factories; # your factories module
use Child::Helper; # imports &children-on-country
factory-run {
is children-on-country("UK"), 0;
.create: "child", :country<UK>;
is children-on-country("UK"), 1;
@FCO
FCO / test.raku
Last active December 11, 2022 15:05
use Factories; # your factories module
factory-run {
my $child = .create: "child";
}
use Factories; # your factories module
my $*RED-DB = factory-db;
my $child = factory-create "child";