Skip to content

Instantly share code, notes, and snippets.

@timo
timo / gist:b01c70e2f7ce4a40eddc19517e3aee87
Created September 26, 2018 21:29
hilarious-looking compilation result of allomorphs.pm6 &parse_win
BB 14 (0x7f030419cdf8):
line: 283 (pc 188)
Instructions:
[Annotation: Logged (bytecode offset 188)]
sp_getlex_o r6(20), lex(idx=0,outers=0,newval)
[Annotation: INS Deopt One (idx 8 -> pc 196; line 283)]
[Annotation: INS Deopt One (idx 9 -> pc 202; line 283)]
sp_guardconc r6(4), r6(20), sslot(1), litui32(196)
[Annotation: Logged (bytecode offset 354)]
sp_getlex_o r9(25), lex(idx=0,outers=0,newval)
@timo
timo / mutator-tunnel-operator.p6
Last active September 17, 2018 19:34
A little operator that lets you mutate an object in a one-liner without needing to use the mutator's return value!
"foobarbaz".comb.Array.splice(3,1,"X").join.say;
# Output: b
# Issue: splice returns what was cut out, not the result.
# Solution: Keep the array of characters around for later.
my @a = "foobarbaz".comb; @a.splice(3,1,"X"); @a.join.say;
# Output: fooXarbaz
# Don't want to introduce a local variable for this?
@timo
timo / pass-host-and-port-on-listen.patch
Created July 20, 2018 00:12
pass host and port to a "ListenSocket" in IO::Socket::Async
diff --git a/src/core/IO/Socket/Async.pm6 b/src/core/IO/Socket/Async.pm6
index 87dcf39a5..a86a9f08f 100644
--- a/src/core/IO/Socket/Async.pm6
+++ b/src/core/IO/Socket/Async.pm6
@@ -195,23 +195,32 @@ my class IO::Socket::Async {
$p
}
+ class ListenSocket is Supply {
+ has Promise $.socket-host;
@timo
timo / shlomifish_euler_287.nqp
Created June 3, 2018 01:59
nqp and perl6 optimized versions of shlomi fish's (rindolf's) euler 287 solution.
#!/usr/bin/env perl6
# The Expat License
#
# Copyright (c) 2018, Shlomi Fish
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#!/usr/bin/env perl6
# inspired by https://narimiran.github.io/2018/05/10/python-numpy-nim.html
use nqp;
constant N = 10_000;
constant sigma = 0.1e0;
constant f = (2 / N).Num;
constant mu = 0.001e0;
@timo
timo / result.txt
Created September 8, 2017 11:05 — forked from Skarsnik/result.txt
timo@schmand /tmp> perl6 --profile=heap testshellmem.p6 shell
Before shell call : 101.664 kb
html is 230457 chars
After shell call : 210.332 kb
After forced gc: 249.704 kb
html is 230457 chars
After shell call : 323.016 kb
After forced gc: 354.232 kb
html is 230457 chars
After shell call : 401.640 kb
@timo
timo / trace_spesh_optimize.gdb
Created June 28, 2017 14:55
make a spesh dump after every step of optimization, check 'em all into git, display a log with diffs afterwards
define trace_spesh_optimize
dont-repeat
python
import tempfile
import os
import gdb
spesh_trace_target_folder = tempfile.mkdtemp("", "moar-spesh-trace")
spesh_trace_target_file = os.path.join(spesh_trace_target_folder, "speshdump.txt")
os.system("git init " + spesh_trace_target_folder)
grammar g{
token garble {<[2]>};
token alpha1 {<[2]>};
token beta { <[q]> };
token delta {<+garble +beta>};
token delta1 {<+garble>};
token delta2 {<+alpha1 +beta>}
}
say so "2" ~~ /<g::delta1>/; # OK
say so "2" ~~ /<g::delta2>/; # OK
@timo
timo / cwr.p6
Last active August 18, 2016 23:18 — forked from ahalbert/cwr.p6
use v6;
use Test;
sub combinations_with_replacement(@iterable, $r) {
gather {
cwr(@iterable, [], $r);
}
}
sub cwr(@iterable, @state, $r) {
my $place = @state.elems;
# this is my solution to GRAPH.
# it offers an interactive mode and some test cases
use v6;
class Graph {
has @!nodes;
has %!neighbour;
method connect($a, $b) {