Skip to content

Instantly share code, notes, and snippets.

View mixin-role.raku
use v6.e.PREVIEW;
say 0 but True;
@0racle
0racle / rsp.md
Last active Oct 8, 2020
Rock Scissor Paper
View rsp.md

An implementation of "Rock Scissor Paper" in Raku.

The "robot" will make a weighted random choice based on your previous moves.

use Term::ReadKey;
use Terminal::ANSIColor;

enum Choice  « :Rock(1) :Paper(2) :Scissors(3) »;
enum Outcome « :WIN(1)  :DRAW(0)  :LOSE(-1)    »;
@0racle
0racle / io-socket-ssl.p6
Last active Oct 28, 2019
IO::Socket::SSL
View io-socket-ssl.p6
use IO::Socket::SSL;
my $ssl = IO::Socket::SSL.new(:host<google.com>, :port(443));
$ssl.print(qq:to<END>);
GET / HTTP/1.1
Host:www.google.com
Connection:close
END
View error-margin.p6
role ErrorMargin[$e] {
method ACCEPTS($lval) { $lval ~~ self - $e .. self + $e }
}
say 2.2 ~~ 2 but ErrorMargin[0.5]; # True
say 2.7 ~~ 2 but ErrorMargin[0.5]; # False
@0racle
0racle / About.md
Created Sep 19, 2019
Slang::ForElse
View About.md
View Nested.md

I was playing around with nesting data in hashes, and came up with... something.
Some kinda tree structure with JSON-Path like access.
Not sure what this might be useful for.

Perl 5 and 5 implementations below...

Perl 6

use Data::Dump;
@0racle
0racle / Bla.pm6
Created Oct 26, 2018 — forked from FCO/Bla.pm6
Exportation Exploration
View Bla.pm6
use Exportable;
sub bla is exportable { "bla" }
sub ble is exportable { "ble" }
sub bli is exportable { "bli" }
sub blo is exportable { "blo" }
sub blu is exportable { "blu" }
View function-compostion.md

Given the example of a count-words function, I could compose it like so

my &f = *.elems  *.words;
say f 'this is a test'; # OUTPUT: 4

or like this...

my &f =      *.elems;
   &f = &f  *.words;
@0racle
0racle / slang.p6
Last active Jul 4, 2018
Perl 6 Slang
View slang.p6
# I could export this role from a module,
# but here I'm just running it at BEGIN phase
BEGIN {
$*LANG.define_slang: 'MAIN',
$*LANG.slang_grammar('MAIN').^mixin:
role :: {
token routine_declarator:sym<sub> {
'fn' <routine_def('sub')>
}
@0racle
0racle / pies.md
Last active Apr 9, 2018
Possible Number of Pies
View pies.md

/r/dailyprogrammer - [2018-03-28] Challenge #355 [Intermediate] - Link

This is not my solution... Just a modification I made of /u/ruincreep's solution while playing around.

my %recipes =
  'Pumpkin pie' => (:1Pumpkin, :3Eggs, :4Milk, :3Sugar).Bag,
  'Apple pie'   => (:1Apple,   :4Eggs, :3Milk, :2Sugar).Bag;

sub solve-pies($items) {
You can’t perform that action at this time.