This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multi sub postfix:<!> (Int $i where $i < 0) is tighter(&infix:<*>) { fail "Not a Natural Number in Factorial" } | |
multi sub postfix:<!> (Int $i where 0|1) is tighter(&infix:<*>) { 1 } | |
multi sub postfix:<!> (Int $i where $i > 1) is tighter(&infix:<*>) { $i * ($i-1)! } | |
use Test; | |
isa_ok -1!, Failure, "Factorial for -1 fails"; | |
ok 0! == 1, "Factorial for 0"; | |
ok 1! == 1, "Factorial for 1"; | |
ok 5! == 120, "Factorial for a larger integer"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub factorial (Int $i) { | |
given $i { | |
when $i < 0 { fail "Not a Natural Number" } | |
when 0 { 1 } | |
when 1 { 1 } | |
default { $i * factorial $i-1 } | |
} | |
} | |
use Test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub factorial { | |
if $^i < 0 { | |
fail "Not a Natural Number"; | |
} else { | |
[*] 1..$i; | |
} | |
} | |
use Test; | |
isa_ok factorial(-1), Failure, "Factorial for -1 fails"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use 5.10.0; | |
#Let you define the --tag=rule on the command line | |
use Getopt::Long; | |
#Depends on the Mojo DOM because its light weight and nice to use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use v6; | |
role PhoneNumber { | |
proto token phone-num {*} | |
token phone-num:sym<gb> { | |
[<[0]>*]\s*[2<[03489]>]\s*[\d**4]\s*[\d**4] # 02x [eight-digit local number] | |
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, sys, tempfile | |
from subprocess import Popen, PIPE, STDOUT | |
#Name of the pipe, use tempfile to create some random filename usually in /tmp | |
data_pipe = tempfile.mktemp() | |
#Create the actual pipe 'file' where the OS knows you wanted a pipe type thing | |
os.mkfifo( data_pipe, 0644 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, sys, tempfile, csv | |
import re, inspect, ast | |
from subprocess import Popen, PIPE, STDOUT | |
""" | |
Class for dumping data into a SQLite database. | |
You will need the sqlite3 command line client in your PATH, | |
even if you are on Windows and not UNIX (maybe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"fmt" | |
"net/http" | |
"net/url" | |
"io/ioutil" | |
"encoding/json" | |
//"strings" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4 | |
# $Id$ | |
PortSystem 1.0 | |
name rakudo-star | |
conflicts parrot | |
version 2013.08 | |
categories perl | |
platforms darwin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
class BioInfo::Sequence { | |
has Str $.seq; | |
has Str @.residues; | |
submethod BUILD (Str :$seq, Str :@residues) { | |
die X::BioInfo::UnknownResidue.new(seq => $seq, residues => @residues); | |
$!seq := $seq; | |
@!residues := @residues; |
OlderNewer