This file contains hidden or 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
raku -MCro::HTTP::Server -MCro::HTTP::Router -MCro::HTTP::Client -e ' | |
my &where = -> Int $i, Int $actual { say "$actual == $i -> { $actual == $i }"; $actual == $i } | |
Cro::HTTP::Server.new( | |
host => "127.0.0.1", | |
port => 10001, | |
application => route { | |
post -> {request-body -> $data? { content "test/plain", "ok!" } } | |
} | |
).start; | |
Promise.in(5).then: { Cro::HTTP::Client.post: "http://127.0.0.1:10001", :headers["Content-Type" => "application/x-www-form-urlencoded"] } # breaks the server |
This file contains hidden or 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
$ raku -MCro::HTTP::Server -MCro::HTTP::Router -e ' | |
Cro::HTTP::Server.new( | |
host => "127.0.0.1", | |
port => 10001, | |
application => route {my $CRO-ROUTER-RESPONSE = $*CRO-ROUTER-RESPONSE; | |
get -> {content "test/plain", "ok!"} | |
^3 .map: -> $i { | |
post -> Int $a where { say "$_ == $i -> { $_ == $i }"; $_ == $i } { | |
CATCH { default { say "ERROR: $_" } } |
This file contains hidden or 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
raku -I. -MRed -MRed::Type -MRed::AST::Value -MJSON::Fast -e ' | |
red-defaults "SQLite"; | |
my $*RED-DEBUG = True; | |
enum Currency <USD GBP BRL>; | |
class Money { has Rat() $.value; has Currency() $.currency } | |
class DBMoney does Red::Type { | |
method inflator { -> $_ is copy --> Money { given .&from-json { Money.new: :value(.<value>), :currency(Currency::{ .<currency> }) } } } |
This file contains hidden or 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
$ raku -I. -MRed -MRed::Type -MRed::AST::Value -MJSON::Fast -e ' | |
red-defaults "SQLite"; | |
#my $*RED-DEBUG = True; | |
enum Currency <USD GBP BRL>; | |
class Money { has Rat() $.value; has Currency() $.currency } | |
class DBMoney does Red::Type { | |
method inflator { -> $_ is copy --> Money { given .&from-json { Money.new: :value(.<value>), :currency(Currency::{ .<currency> }) } } } |
This file contains hidden or 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
use Singleton; | |
say Singleton.new.WHERE |
This file contains hidden or 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
class Agg does Callable { | |
has Callable @.subs; | |
has Signature $.signature = Signature.new: :params[|@!subs.map: |*.signature.params], :returns(Parameter.new(:type(Map()))); | |
method CALL-ME(|c) { | |
%( | |
|@.subs.map: { | |
my @names = .signature.params.grep({ .named }).map(|*.named_names); | |
my %params := (c.hash{@names}:p).Map; |
This file contains hidden or 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
my $interval = .run-at: :5mins-running, :off, -> :$rule, :$time { | |
$rule.stop; | |
say "$time.hh-mm-ss(): interval has finished" | |
} | |
.run-at: :25mins-running, -> :$rule, :$time { | |
$rule.stop; say "$time.hh-mm-ss(): Time to relax"; | |
$interval.start | |
} |
This file contains hidden or 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
use App::RakuCron::Configuration; | |
use App::RakuCron::Rule; | |
use Lumberjack; | |
sub print-example(Str $msg = "Generic message", :$rule, +@params, :$time, :$delta-secs = "None", :$something-else = "") { | |
$rule.log-warn: "$msg (@params[]) ({ $something-else }): ", $time.hh-mm-ss, " -> { $delta-secs }" | |
} | |
Lumberjack.dispatchers = [ | |
Lumberjack::Dispatcher::Console.new: :colour |
This file contains hidden or 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
use App::RakuCron::Configuration; | |
sub print-example(Str $msg, +@params, :$time, :$delta-secs, :$something-else) { | |
say "$msg (@params[]) ({ $something-else // "" }): ", $time, " -> { $delta-secs // "None" }" | |
} | |
config { | |
# every Mon/Web/Fri at 10:00:00 | |
.run-at: :10hours, :wday<Mon Wed Fri>, { shell "ls -la" } |
This file contains hidden or 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
multi quicksort([]) { Empty } | |
multi quicksort([$pivot, *@rest]) { | |
my (:Less(@less), :Same(@same), :More(@more)) := @rest.classify(* cmp $pivot); | |
[ |quicksort(@less), $pivot, |@same, |quicksort(@more) ] | |
} | |
say quicksort [7, 2, 1, 8, 1, 9, 3] |
NewerOlder