Skip to content

Instantly share code, notes, and snippets.

> my @bots = <Optimus Bluestreak Ironhide Jazz Ratchet Sideswipe Sunstreaker Trailbreaker>
[Optimus Bluestreak Ironhide Jazz Ratchet Sideswipe Sunstreaker Trailbreaker]

> @bots.first(/streak/)  
Bluestreak

> @bots.first(/streak/, :end)
Sunstreaker
@0racle
0racle / Listy-Eqv.md
Last active April 26, 2016 12:34
Listy eqv
use Test;

plan 22;

sub infix:<Meqv> { @^a == @^b && all @a Zeqv @b }

my @a =  1 ,  2 ,  3 ;
my @b = '1', '2', '3';
@0racle
0racle / read-only.md
Last active May 27, 2016 07:07
Read Only
> my $a = 10
10
> my $x := $a
10
> $x = 5
5

😞

#If WinActive("ahk_class VanDyke Software - SecureCRT") || WinActive("ahk_class PuTTY")

; KEY MAPS

#IfWinActive

or...

@0racle
0racle / minimal-vimrc.vim
Created September 8, 2016 13:39
Minimal vimrc
set nocompatible
set encoding=utf-8
set fileencodings=utf-8
set number
set wildmenu
filetype plugin indent on
@0racle
0racle / p6.p6
Created September 15, 2016 02:26 — forked from zoffixznet/p6.p6
class LedgerFromFile {...};
class LedgerFromPkg {...};
class Ledger {
proto method new {*}
multi method new(:$file!) { LedgerFromFile.new(:$file) }
multi method new(:$pkg!) { LedgerFromPkg.new(:$pkg) }
}
class LedgerFromFile {
@0racle
0racle / slurpy.p6
Created September 20, 2016 02:09
Slurpy
#!/usr/bin/env perl6
sub plus( +@foo ) { "@foo.elems() elems: ", @foo }
sub star( *@foo ) { "@foo.elems() elems: ", @foo }
my @a = (1, 2),(3, 4);
my @b = (6, 7),(8, 9);
say plus(@a, 5, @b); # OUTPUT: (3 elems: [[(1 2) (3 4)] 5 [(6 7) (8 9)]])
say star(@a, 5, @b); # OUTPUT: (5 elems: [(1 2) (3 4) 5 (6 7) (8 9)])
@0racle
0racle / delete-idx.md
Last active October 5, 2016 05:49
Delete Indexes

Asked on #perl6

I am trying to remove elements from an array by preserving the indexes. Meaning if I delete first element, rest of the elements hold their original position. I wrote a function for it and you can find it here http://pastebin.com/Rfc32sh5 . I am just curious, is there any better way of doing this because Perl 6 is very rich in features and shortcuts.

The sub could be written as this

sub delete-idx( :@array!, :@idx! ) {
    my @del = @array[@idx] :delete;
    @array .= grep(*.defined);
    return @del;
}
@0racle
0racle / guessing-game.p6
Created October 25, 2016 21:44
Guessing Game
say "Guess the number!";
my $secret_number = (1..100).pick;
loop {
my $guess = prompt("Please input your guess: ").Int or next;
say "You guessed: $guess";
given $guess <=> $secret_number {
@0racle
0racle / listy-method.md
Created November 4, 2016 11:10
Listy Method

For a class method that returns a list, I am performing an expensive computation to a list of values

class Thingy {
    has Int $.start;
    has Int $.end;
    
    method things {
        ($.start .. $.end).map( &expensive_transform );
 }