Skip to content

Instantly share code, notes, and snippets.

View MattOates's full-sized avatar

Matt Oates MattOates

View GitHub Profile
@MattOates
MattOates / BioInfo.pm6
Last active August 29, 2015 14:16
Trying to add a little Slang to https://github.com/MattOates/BioInfo so that ` ` construct a Seq object
use QAST:from<NQP>;
sub BioInfo::seq(Str $sequence) is export {
use BioInfo::Parser::FASTA::Grammar;
use BioInfo::Parser::FASTA::Actions;
BioInfo::Parser::FASTA::Grammar.parse($sequence, actions => BioInfo::Parser::FASTA::Actions).ast;
}
sub EXPORT(|) {
role BioInfo::Grammar {
@MattOates
MattOates / six-frame-translation
Created March 24, 2015 12:05
Mising bits from P5 necessary for a port of the six-frame-translation perl6-bench benchmark
use strict;
use feature 'say';
use Data::Dumper;
use List::MoreUtils 'zip';
#Implement something similar to the Perl6 X meta operator
#probably not the best implementation in the world
sub X {
my %words;
given slurp("part-of-speech.txt") {
my int $pos = 0;
my int $chars = $_.chars;
while $pos < $chars {
my int $tab = $_.index("\t", $pos);
my int $nl = $_.index("\n", $tab);
%words{$_.substr($pos, $tab - $pos)} =
$_.substr($tab + 1, $nl - $tab - 1);
# https://raw.githubusercontent.com/kevina/wordlist/master/pos/part-of-speech.txt
my $input = slurp('part-of-speech.txt');
my %words;
sub bench($name, &code) {
%words = ();
my $start = now;
code;
my $end = now;
#!/usr/bin/env perl6
use v6;
use Stats;
#Tim's original times:
#primes-inline-loop(1000) ran in 2.425 seconds (σ = 0.213 seconds).
#primes-inline-loop-upto-sqrt(1000) ran in 2.311 seconds (σ = 0.131 seconds).
#primes-inline-loop-upto-int-sqrt(1000) ran in 2.274 seconds (σ = 0.161).
sub bench($name, &code) {
@MattOates
MattOates / HQ9Plus.p6
Last active August 29, 2015 14:25
An hq9+ REPL inspired by https://github.com/dha/hq9plus-in-perl6 uses grammars and actions to handle commands. Uses a 64bit accumulator to handle super wide future proof memory addresses.
#!/usr/bin/env perl6
use v6;
#Handle terminal colour output by installing a module
#panda install Term::ANSIColor
use Term::ANSIColor;
grammar HQ9Plus::Grammar {
#A valid REPL line is just a sequence of commands and nothing else including white space
token TOP {
@MattOates
MattOates / super_cool_script.pl
Last active August 26, 2015 16:52
Boring script to split on some fields from a reddit post https://www.reddit.com/r/perl/comments/3ih6ha/commissioned_work/
#!/usr/bin/env perl
#Write sane perl
use strict;
use warnings;
use feature 'say';
#Use some modules which are sufficiently round wheels
use Text::CSV;
use Getopt::Long;
@MattOates
MattOates / parallel-primes.p6
Last active September 4, 2015 20:47
Do some parallel prime finding in the most naive way.
#!/usr/bin/env perl6
use v6;
use Stats;
sub bench($name, &code) {
my ($start,$end);
my $max = 1000;
my @times;
@MattOates
MattOates / chomp_lines.p6
Created September 10, 2015 16:17
Chomp files code
#!/usr/bin/env perl6
for 'data.tsv'.IO.lines {}
@MattOates
MattOates / find-primes.p6
Last active May 19, 2024 19:41
Combined primes benchmark with a parallel implementation that does well to keep up despite doing a lot more calculations!
#!/usr/bin/env perl6
use v6;
use Stats;
sub bench(Str $name, Int $upto, &code) {
my ($start,$end);
my @times;
for 1..20 {