Skip to content

Instantly share code, notes, and snippets.

@timo
timo / nbody.p6
Last active May 12, 2016 00:35 — forked from jaffa4/nbody.p6
#
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Christoph Bauer
# converted into Perl by Márton Papp
#
my num $pi = 3.141592653589793e0;
my num $solar_mass =(4 * $pi * $pi);
@timo
timo / post-commit
Last active August 29, 2015 14:15 — forked from kindfulkirby/post-commit
#!/usr/bin/env python3.2
import subprocess, re
matchers = {
'../scripts/public-add': re.compile('[AM]\tpublic/[\w.]'),
'../scripts/public-del': re.compile('D\tpublic/[\w.]'),
}
for line in subprocess.check_output(["git", "show", "--name-status"]).decode().split('\n')[4:-1]:
@timo
timo / gist:11154880
Created April 21, 2014 20:09
simple example for supplies with intervals.
perl6-m -e 'Supply.merge(Supply.interval(2).map({ "tick" }), Supply.interval(2, 1).map({ "tock" })).tap(&say); sleep 10;'
tick
tock
tick
tock
tick
tock
tick
tock
tick
@timo
timo / poll_perl6_vms
Last active August 29, 2015 13:58 — forked from sergot/poll_perl6_vms
Hey!
This is a poll about VMs for Perl 6. It would be awesome if you fill it,
just write a comment with your answers.
I need it because I work on a huge summary (including, among the others, statistics, tests)
of VMs and Perl 6 itself.
Thank you very much in advance!
sergot
@timo
timo / gist:8538083
Created January 21, 2014 11:02
extract common prefixes and suffixes from a comma-separated list of strings
my $in = "rakudo-parrot c8ec1d, rakudo-jvm c8ec1d, rakudo-moar c8ec1d";
my @pieces = $in.split(", ");
my $common-prefix;
for 1..$in.chars {
last unless [eq] @pieces>>.substr(0,$_);
$common-prefix = @pieces[0].substr(0,$_);
}
@pieces = @pieces>>.substr($common-prefix.chars);
my $common-suffix;
@timo
timo / agm.p6
Created January 18, 2014 12:03 — forked from grondilu/agm.p6
sub agm( $a is copy, $g is copy ) {
($a, $g) = ($a + $g)/2, sqrt $a * $g
until abs($a - $g) < 0.000001;
return $a;
}
say agm 1, 1/sqrt 2;
@timo
timo / WINNER.pl
Last active December 28, 2015 16:09
implementation of WINNER sub for perl6
my constant $WINNER_KIND_DONE = 0;
my constant $WINNER_KIND_MORE = 1;
sub WINNER(@winner_args, *@pieces, :$wild_done, :$wild_more, :$later) {
my Int $num_pieces = +@pieces div 3;
sub invoke_right(&block, $key, $value?) {
my @names = map *.name, &block.signature.params;
say @names;
return do if @names eqv ['$k', '$v'] || @names eqv ['$v', '$k'] {
&block(:k($key), :v($value));
@timo
timo / richards.nqp
Last active December 21, 2015 02:38
working version of richards for nqp, nonworking version of richards for perl6.
my int $COUNT := 1000;
my int $DATA_SIZE := 4;
my int $ID_IDLE := 0;
my int $ID_WORKER := 1;
my int $ID_HANDLER_A := 2;
my int $ID_HANDLER_B := 3;
my int $ID_DEVICE_A := 4;
my int $ID_DEVICE_B := 5;
my int $NUMBER_OF_IDS := 6;
@timo
timo / tables.p6
Last active July 20, 2016 22:52
new table grammar
grammar Table {
token TOP {
<pod_block>
}
token pod_newline {
\h* \n
}
method insert_column_part($text, $column, @text-pieces, @columns, $columns-fixed = False) {
@timo
timo / gist:5841141
Last active December 18, 2015 20:38
trying to implement multidimensional slicing
class Foo is Array {
multi method postcircumfix:<[ ]>(\SELF: LoL $coords) is rw {
my $subcoords = $coords[1..^*].lol;
if +@$subcoords == 1 {
$subcoords = $subcoords[0].list;
}
for $coords[0].list {
SELF[$_][@$subcoords];
}
}