Skip to content

Instantly share code, notes, and snippets.

View MattOates's full-sized avatar

Matt Oates MattOates

View GitHub Profile
from typing import NamedTuple
import json
class NamedTupleJSONEncoder(json.JSONEncoder):
def encode(self, o):
print(f"Encoding {type(o)}")
return super().encode(o)
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 {