Skip to content

Instantly share code, notes, and snippets.

View holli-holzer's full-sized avatar

Markus "Holli" Holzer holli-holzer

View GitHub Profile
# https://docs.raku.org/language/typesystem#subset
# A subset gives us a thing we can smartmatch ( ~~ ) against
# at which point the where condition gets executed on the thing we
# are smartmatching.
#
# For example:
# subset StartsWithA of Str where *.starts-with("A");
# say "Brussels Sprouts" ~~ StartsWithA; # False
# say "Antonio Banderas" ~~ StartsWithA; # True
#
@holli-holzer
holli-holzer / 111.2.raku
Created May 4, 2021 21:09
Perl Weekly Challenge 111.2 - Binary Matrix Search with comments #Raku #Rakulang
use Test;
my @M =
[ 1, 2, 3, 5, 7 ],
[ 9, 11, 15, 19, 20 ],
[ 23, 24, 25, 29, 31 ],
[ 32, 33, 39, 40, 42 ],
[ 45, 47, 48, 49, 50 ];
# A multi sub implementing a binary search. multi subs are a mechanism
@holli-holzer
holli-holzer / 99bottles.1.raku
Created April 21, 2021 21:37
99 bottles of beer in Raku
# Raku feature: Lazy list. This construct will repeat 99 to 0
# and then start over at 99 ad infintum when iterated
my @bottles = flat (99...0) xx Inf;
# for every index, generate the "xx bottles of beer"
# when using double quotes the Raku parser interprets
# code in curlies as, well, code and embeds the return
# value within the string
# in the first block we see an ordinary logical or
@holli-holzer
holli-holzer / Parser.pm6
Created May 13, 2020 21:00
Fasta::Parser draft
subset NonEmptyStr of Str where *.chars > 0;
subset FastaStr of Str where * ~~ / ^ <[ ACGT ]>+ $/;
subset ReadableFile where { .IO.e && .IO.f && .IO.r };
class Fasta::Sequence
{
has NonEmptyStr $.data is required;
has NonEmptyStr $.description is required;
@holli-holzer
holli-holzer / bm
Created February 22, 2020 15:03
benchmark mistery
# The most common approach, and probably the simplest solution to this challenge
# is to create an array of men, and then keep taking two from the front and putting the first of
# them to the back of the array until it has only one member left.
#
# A concise version of this looks like
sub take-two-push-one
{
given my @men = 1..50 { .push( .splice(0,2).first ) while .elems > 1 };
@men.first;
# People don't learn about this anymore
role Linked { has $.next is rw; }
my $first = my $killer = 1 but Linked;
for 2..50 { my $man = $_ but Linked; $killer.next = $man; $killer = $man; }
$killer.next = $first;
$killer = $first;
while $killer != $killer.next {
$killer = $killer.next = $killer.next.next;
@holli-holzer
holli-holzer / atom-perl6-editor-tools.json
Created October 9, 2017 11:37
Enhanced snippet file for atom-perl6-editor-tools including unicode operators, greek alphabet and some smiley faces
{
".source.perl6, .source.perl6fe": {
"script": {
"prefix": "script",
"body": "#!/usr/bin/env perl6\n\nuse v6;\n\nsay \"Hello world\";"
},
"pod": {
"prefix": "pod",
"body": "=begin pod\n$1\n=end pod"
},
@holli-holzer
holli-holzer / cls
Last active September 26, 2017 21:36
proper cls command for linux ( really resets the terminal, not only scroll to top like 'clear' does )
# install tput
> echo 'tput reset'>cls
> chmod 755 cls
> mv cls /usr/bin
#This code
my $bookFile ="2774.epub";
my $bookUrl = "http://93.174.95.27/foreignfiction/get.php?md5=5d3ef26e36584edd9b2434deaced6a55&key=3XD005UYYM2SP81G";
say qq[curl -o $bookFile "$bookUrl"];
shell qq[curl -o $bookFile "$bookUrl"];
#when run it produces the error. note the extra quote ( ""http" )
D:\P6>perl6 t.p6
curl -o 2774.epub "http://93.174.95.27/foreignfiction/get.php?md5=5d3ef26e36584edd9b2434deaced6a55&key=3XD005UYYM2SP81G"
@holli-holzer
holli-holzer / mwo-launch.ahk
Last active July 16, 2017 16:08
Launch MWO and automatically skip the start screens, enter the password and login
; mwo-auto-launch
; Version 0.2
;
; by Markus "Tailgunner" Holzer
;
; This script launches the Mechwarrior Online Client
; and eliminates the tedious need to enter your password every time
; to play.
;
; To make it work you will need to edit this script and change some values so it works on your system.