Skip to content

Instantly share code, notes, and snippets.

use nqp;
use QAST:from<NQP>;
sub EXPORT(|) {
role MOSDEF::Grammar {
token def { [ \'.*?\' || \".*?\" || .]*? )> <before ';'> } # '
rule routine_declarator:def { <sym> <routine_def('def')> }
rule routine_declarator:sym<def> { <sym> <def> }
#!/usr/bin/env perl6
my \x = "mütter";
my \y = "mütter";
if x eq y {
say "same"
} else {
say "different"
}
#!/usr/bin/env python
#-*- encoding: utf8 -*-
x = "mütter";
y = "mütter";
if x == y:
print "same"
else:
print "different"
class Dee is Date {
has &!formatter = sub { "foo" };
}
say Dee.new('2014-01-01');
use nqp;
use QAST:from<NQP>;
# Slang to make "dog" a synonym for "do"
role Dogdo::Grammar {
token statement_prefix:sym<dog> { <sym><.kok> <blorst> }
}
role Dogdo::Actions {
use nqp;
use QAST:from<NQP>;
# Slang to make "dog" a synonym for "do"
role Dogdo::Grammar {
token statement_prefix:sym<dog> { <sym><.kok> <blorst> }
}
role Dogdo::Actions {
#!/usr/bin/env perl6
my @dates = Date.today, Date.today.succ ... ∞;
my %taken =
# first wednesday
plug-central => { $_.day-of-week == 3 and $_.weekday-of-month == 1 },
# second tuesday
plug-north => { $_.day-of-week == 2 and $_.weekday-of-month == 2 },
@bduggan
bduggan / div.p6
Last active August 30, 2016 13:37
#!/usr/bin/env perl6
grammar divspl {
rule TOP { <x=int>..<y=int> <assignment>+ }
rule assignment { <word> '=' <mod=int> }
token word { \w+ }
token int { \d+ }
}
# Custom operator:
#!/usr/bin/env perl6
# parse a little slim (<http://slim-lang.com>)
grammar slim {
rule TOP { <line>+ %% <eol>}
token line { <indentation> <tag> [ ' ' <text> ]? }
token indentation { <indent>* }
token indent { ' ' }
token tag { \w+ }
@bduggan
bduggan / rsa.p6
Last active October 12, 2016 14:48
sub random-prime(:$digits) {
repeat { $_ = (10**$digits .. (10**($digits+1))).pick } until .is-prime;
return $_;
}
sub encrypt(:$message, :$key) {
return expmod($message,$key[0],$key[1])
}
sub decrypt(:$message, :$key) {