Skip to content

Instantly share code, notes, and snippets.

View dwarring's full-sized avatar

David Warring dwarring

  • The C Peoples
  • New Zealand
View GitHub Profile
% icu-config --unicode-version
5.2
% PERL6LIB=t/spec/packages prove -e 't/fudgeandrun --backend=parrot' -v t/spec/S05-mass/charsets.t
t/spec/S05-mass/charsets.t ..
1..17
ok 1 - ident chars
ok 2 - alpha chars
ok 3 - space chars
ok 4 - digit chars
ok 5 - alnum chars
@dwarring
dwarring / gist:12c1e32440a8aea43337
Last active August 29, 2015 14:06
Bisection for parrot failures of advent-2010-day14.t etc
# rakudo bisections on parrot
# david warring 15-09-2014
# --------------------------
sub capture-said($code) {
my $output = '';
temp $*OUT = class {
method print(*@args) {
$output ~= @args.join;
}
}
sub foo {say 'outer foo'}
sub infix:<bar>($a,$b) {say "outer bar {$a + $b}" }
sub infix:<baz>($a,$b) {say "outer baz {$a * $b}" }
foo();
2 bar 3;
2 baz 3;
say;
{
# courtesy of https://gist.github.com/masak/244255
use v6;
enum Suit < ♥ ♦ ♣ ♠ >;
enum Rank (2, 3, 4, 5, 6, 7, 8, 9, 10,
'j', 'q', 'k', 'a');
class Card {
has Suit $.suit;
has Rank $.rank;
@dwarring
dwarring / gist:10070559
Created April 7, 2014 22:48
BT for S04-phasers/first.t SEGV
davidw@app01:~/git/roast$ gdb /home/davidw/git/rakudo/install/bin/moar
GNU gdb (GDB) 7.0.1-debian
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
use Test;
my $p1000 = start {
(1..Inf).grep(*.is-prime)[999]
}
is $p1000.result, 7919, 'simple promise';
# not exiting on jvm
@dwarring
dwarring / gist:9821113
Created March 27, 2014 23:06
advent 2013 day 14 - config combiner
our %TestFiles = (
'config1.ini' => q:to"END1",
@dwarring
dwarring / gist:9559508
Created March 14, 2014 23:54
Advent 2013 day 09 - final example
my $lisp-list = 1 => 2 => 3 => Nil; # it's nice that infix:<< => >> is right-associative
Pair.^add_fallback(
-> $, $name { $name ~~ /^c<[ad]>+r$/ }, # should we handle this? yes, if /^c<[ad]>+r$/
-> $, $name { # if it turned out to be our job, this is what we do
-> $p {
$name ~~ /^c(<[ad]>*)(<[ad]>)r$/; # split out last 'a' or 'd'
my $r = $1 eq 'a' ?? $p.key !! $p.value; # choose key or value
$0 ?? $r."c{$0}r"() !! $r; # maybe recurse
}
}
# from chr() in nqp/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
if ((val >= 0xfdd0
&& (val <= 0xfdef // non character
|| ((val & 0xfffe) == 0xfffe) // non character
|| val > 0x10ffff) // out of range
@dwarring
dwarring / gist:7848868
Last active December 30, 2015 15:29
An (almost) Simple Grammar

An (almost) Simple Grammar

Today's example constructs a grammar for tracking playing cards in a single deal. We'll say it's poker with one or more players and that each player is being dealt a hand that contains exactly five cards.

The "almost" part is the need to track cards and detect duplicates. We want to check for repeated cards both within each card-hand and between hands.

To start with, here's the basic grammar (no duplicate checks yet):

grammar CardGame {