Skip to content

Instantly share code, notes, and snippets.

grammar BraceExpansion {
token TOP { ( <.normalchar>+ | <alt> )* }
token normalchar { \\. | <-[ { , } ]> }
token alt {
'{' ~ '}' <TOP>* % \,
}
}
sub crosswalk($/) {
[X~] $0.map: -> $/ { [$<alt><TOP>».&crosswalk] or ~$/ }
#include <stdio.h>
int main() {
char n = 127;
printf("%d\n", n);
n++;
printf("%d\n", n);
return 0;
}
@grondilu
grondilu / bmo_subdivide.c.diff
Created February 16, 2014 04:50
midpoint random displacement should not alter the extremities of the edge
336,339c336,337
< if (!params->use_fractal) {
< alter_co(v1, &e_tmp, params, 0, &v1_tmp, &v2_tmp);
< alter_co(v2, &e_tmp, params, 1.0, &v1_tmp, &v2_tmp);
< }
---
> alter_co(v1, &e_tmp, params, 0, &v1_tmp, &v2_tmp);
> alter_co(v2, &e_tmp, params, 1.0, &v1_tmp, &v2_tmp);
$ perl6-m t/spec/S32-io/IO-Socket-INET.t
1..41
# [0s] starting tests
# [0s] Testing on port 1024
ok 1 - [7s] echo server and client
ok 2 - finished in time #1
ok 3 - [6s] discard server and client
ok 4 - finished in time #2
ok 5 - [6s] received first 7 characters
ok 6 - finished in time #3
@grondilu
grondilu / holography.m
Created February 20, 2014 10:51
random-number-based holography
function H = hologram(V, m)
H = zeros(m, 1);
for index=1:length(V)
disp(index);
rand("seed", index);
R = rand(m, 1);
H += V(index)*exp(2*pi*R*i);
end
end
class Automaton {
my sub B($x) { 1 +< $x }
has uint $.rule;
has uint64 $.state;
method gist { $!state.fmt("%064b").flip }
method succ {
loop (my uint64 $st = my $i = 0; $i < 64; $i++) {
if ($!rule +& B(7 +& (($!state +> ($i - 1)) +| ($!state +< (65 - $i))))) {
$st = $st +| B($i);
}
#include <stdio.h>
int main(int argc, char *argv[]) {
printf( "%u%s", 1ULL, " WTF " );
}
constant MAX_ITERATIONS = 50;
my $height = @*ARGS[0] // 31;
$height = $height % 2 ?? +$height !! 1+$height;
my $width;
my $re = [ -2, 1/2 ];
my $im = [ 0, 5/4 ];
my $dre = ($re.max - $re.min) / ($height - 1);
my @re = $re.min, * + $dre ... $re.max;
@grondilu
grondilu / gist:11295465
Last active August 29, 2015 14:00
patch to NativeCall test suite so that the tests pass on my 32bit system
diff --git a/t/05-arrays.t b/t/05-arrays.t
index ab9797e..a11f8d3 100644
--- a/t/05-arrays.t
+++ b/t/05-arrays.t
@@ -49,7 +49,7 @@ compile_test_lib('05-arrays');
{
class Struct is repr('CStruct') {
- has int $.val;
+ has int32 $.val;
@grondilu
grondilu / PGN.pm6
Last active August 29, 2015 14:03
PGN grammar in Perl 6
grammar PGN;
rule TOP { ^ <game>+ $ }
rule game { <info>+ <move>+ <adjudication>? }
rule info { '[' ~ ']' [ <tag> <string> ] }
token tag { <.alpha>+ }
token string { '"' .+? '"' }