Skip to content

Instantly share code, notes, and snippets.

@blippy
blippy / pd.pl6
Created November 25, 2020 15:20
Partition dump MBR
#!/usr/bin/env perl6
# Reference:
# https://wiki.osdev.org/Partition_Table
my %ids = 0x00 => "Empty", 0x0b => "W95 FAT32", 0x0c => "W95 FAT32 (LBA)",
0x82 => "Linux swap", 0x83 => "Linux", 0x93 => "Amoeba";
sub MAIN($filename) {
say "Disk: $filename";
@moritz
moritz / fooo
Created July 30, 2020 13:06
Raku Match.gist output
$ ./rakudo-m -e ' for ("a1a2a3a4a5" ~~ m:g/(a \d)/) { say "match {$++}: ", $_}'
match 0: 「a1」
0 => 「a1」
match 0: 「a2」
0 => 「a2」
match 0: 「a3」
0 => 「a3」
match 0: 「a4」
0 => 「a4」
match 0: 「a5」
@raiph
raiph / .md
Last active February 17, 2024 23:12
Raku's "core"

Then mathematical neatness became a goal and led to pruning some features from the core of the language.

— John McCarthy, History of Lisp

If you prefer programming languages with a tidy and tiny core, you're in for a treat. This article drills down to the singleton primitive at the heart of Raku's metamodel ("model of a model") of a model of computation ("how units of computations, memories, and communications are organized")1.

The reason I've written this article

It began with u/faiface's reddit post/thread "I'm impressed with Raku"2. One of their sentences in particular stood out for me:

@moritz
moritz / inverse-regex.p6
Last active August 31, 2020 02:20
Generate shortest strings that match a regex
use v6;
role Generator {
method shortest() { ... }
}
class Literal does Generator {
has Str $.atom is required;
method shortest() { return $.atom.list }
}
@Whateverable
Whateverable / query
Created March 23, 2020 00:07
committable6
for ^5 { my $p = run <perl6 -e>, 「my $cnt=0; $*ARGFILES.words.grep(/whale {++$cnt}/); say $cnt;」, ‘sandbox/moby10b.txt’; exit $p.signal if $p.signal != 0; exit $p.exitcode if $p.exitcode != 0 }
@Kaiepi
Kaiepi / monad.p6
Last active August 8, 2019 04:37
Monads in Perl 6
use v6.d;
role Monad[::T] {
method ACCEPTS(::?ROLE: ::?ROLE $m --> Bool:D) {
for $m.^attributes -> Attribute $x {
my Attribute $y = self.^get_attribute_for_usage: $x.name;
return False unless $x.get_value($m) ~~ $y.get_value(self);
}
True
}
@raiph
raiph / trans.md
Last active January 22, 2021 22:33
trans DWEM

What this is

My documentation of P6's .trans routine for anyone who reads it.

It may be a step toward updating the official doc and/or cleaning up the relevant spec tests and/or functionality.

I have tried to be clear enough that a future me will be able to make sense of it, and hopefully anyone else who reads this.

It's supposedly exhaustive (definitely exhausting!).

@0racle
0racle / where-is-grep.md
Last active March 23, 2020 00:54
where is grep

One of Larry's purported factors in the design of Camelia (and by extension, Perl 6) was to appeal to 7 year old girls (and by extension, people new to programming in general).

In addition, another design principle of Perl6 was to make it "less Unix centric". Whereas Perl had s/// and tr///, Perl 6 retains these but adds subst and trans, which is friendlier to new programmers, and self-documenting to some degree.

It seems odd, then, that we still have the grep operator named so. Even in Perl, grep - as in globally search a regular expression and print - bears little resemblance to what it actually does. It's more of a filter, filtering elements out that do not evaluate True to a given expression.

What then would be it's alternative friendly name? Taking into account these design principles...

@andrie
andrie / gamma_parameters.R
Created October 7, 2015 15:19
Fit a gamma distribution based on prior information
# Objective
#
# Fit a gamma distribution knowing that:
# - 20% fall below 15 days
# - 80% fall below 60 days
# Inspired by http://www.johndcook.com/blog/2010/01/31/parameters-from-percentiles/
x <- c(0.2, 0.8)
y <- c(15, 60)
@seandavi
seandavi / platformMap.txt
Created November 13, 2014 20:49
Bioconductor/GEO platform mapping
"title" "gpl" "bioc_package" "manufacturer" "organism" "data_row_count"
"Illumina Sentrix Array Matrix (SAM) - GoldenGate Methylation Cancer Panel I" "GPL15380" "GGHumanMethCancerPanelv1" "Illumina" "Homo sapiens" 1536
"Illumina HumanMethylation27 BeadChip (HumanMethylation27_270596_v.1.2)" "GPL8490" "IlluminaHumanMethylation27k" "Illumina, Inc." "Homo sapiens" 27578
"Illumina HumanMethylation450 BeadChip (HumanMethylation450_15017482)" "GPL13534" "IlluminaHumanMethylation450k" "Illumina, Inc." "Homo sapiens" 485577
"GE Healthcare/Amersham Biosciences CodeLink™ ADME Rat 16-Assay Bioarray" "GPL2898" "adme16cod" "GE Healthcare" "Rattus norvegicus" 1280
"[AG] Affymetrix Arabidopsis Genome Array" "GPL71" "ag" "Affymetrix" "Arabidopsis thaliana" 8297
"[ATH1-121501] Affymetrix Arabidopsis ATH1 Genome Array" "GPL198" "ath1121501" "Affymetrix" "Arabidopsis thaliana" 22810
"[Bovine] Affymetrix Bovine Genome Array" "GPL2112" "bovine" "Affymetrix" "Bos taurus" 24128
"[Canine] Affymetrix Canine Genome 1.0 Array" "GPL39