Skip to content

Instantly share code, notes, and snippets.

View MattOates's full-sized avatar

Matt Oates MattOates

View GitHub Profile
CREATE TABLE patient (
name text,
administrative_gender uuid references concept.concept_cid,
ethnicity uuid references concept.concept_cid,
phenotypic_sex_cid uuid references concept.concept_cid,
);
-- Parametric trigger for validating concept FK against sets of codesystems
-- concept_ind_codesystem(concept_field_name, array_of_codesystems)
#!/usr/bin/env perl6
sub character_differences(Str $str1, Str $str2) {
$str1.comb Z~~ $str2.comb
}
sub hamming_distance(Str $str1, Str $str2) {
my @differences = character_differences($str1, $str2);
return @differences.grep(* == False).elems;
}
Time: <span id="clockDisplay"></span>
@MattOates
MattOates / main.p6
Created October 16, 2018 15:04
6pad gist test
say "Ohai!";
for ^10 -> $stuff {
say $stuff if $stuff.is-prime;
}
@MattOates
MattOates / hackerrank_bench.p6
Last active September 13, 2018 09:07
Some additional benched P6 examples from Tyil's Hackerrank post https://www.tyil.nl/post/2018/09/13/hackerrank-solutions-python3-and-perl6-part-1/
use Stats;
sub bench($name, &code) {
my ($start,$end);
my @times;
for 1..100 {
$start = now;
code();
@MattOates
MattOates / mandelbrot.p6
Last active August 13, 2018 19:02
Quick and dirty script for plotting the Mandelbrot set in the terminal using unicode shading characters. An example invocation: perl6 mandelbrot.p6 --mid-x=-0.73e0 --mid-y=0.246e0 --zoom=0.03e0 --height=300
use Terminal::Width;
sub is-mandelbrot(Complex $z0, int $max=100) {
my Complex $z = $z0;
for ^$max -> $n {
return $n if ($z.abs() > 2e0);
$z = $z**2 + $z0;
}
return $max;
}
#!/usr/bin/env perl6
use Compress::Zlib;
use IO::String;
my $DATA_DIR = %*ENV<DATA_DIR> // '/Users/matt/data/reference/GRCh37/sequence/dna';
for dir($DATA_DIR).grep(/chr\d+\.fa\.gz/) -> $file {
my $out_file = $file.IO.extension('txt', :2parts).open(:w);
my $chromosome = IO::String.new(buffer=>gzslurp($file));
for $chromosome.lines -> $line {
#!/usr/bin/env perl6
use Compress::Zlib;
use IO::String;
my $DATA_DIR = %*ENV<DATA_DIR> // '/Users/matt/data/reference/GRCh37/sequence/dna';
for dir($DATA_DIR).grep(/chr\d+\.fa\.gz/) -> $file {
my $out_file = $file.IO.extension('txt', :2parts).open(:w);
my $chromosome = IO::String.new(buffer=>gzslurp($file));
for $chromosome.lines -> $line {
#!/usr/bin/env perl6
use Compress::Zlib;
use IO::String;
my $DATA_DIR = %*ENV<DATA_DIR> // '/Users/matt/data/reference/GRCh37/sequence/dna';
for dir($DATA_DIR).grep(/chr\d+\.fa\.gz/) -> $file {
my $out_file = $file.IO.extension('txt', :2parts).open(:w);
my $chromosome = IO::String.new(buffer=>gzslurp($file));
for $chromosome.lines -> $line {
1) every time you don't use sigils you are hogging namespace for something thats not variables. Something close to keywords like
"from" and "to" is a bad plan. I've seen several people including myself use "from $i to $j by $inc" as their own range/list constructing
syntax. I have no idea if Rakudo is smart enough to negotiate sigiless variables and keywords at the same time, Id almost hope its not!
2) to some extent it doesn't matter if the OP finds it easier to read or if you do, almost the entirety of code you will come
across will not use that convention. So learning that way to start out with is only going to cause pain working with others. Just wanting
to write a debug statement for that whats the simple plan? say "from {from} to {to}" not so clean given the norm for the language... You're
changing *semantics* for the sake of visual aesthetic not readability. Your intent is less clear given the language, its less readable but
perhaps prettier.
3) friendlier for the OP to learn a language which isn