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/perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
use English qw(-no_match_vars); | |
use JSON qw(decode_json); | |
use LWP::UserAgent; |
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/perl | |
use strict; | |
use warnings; | |
exit(0) unless @ARGV; | |
open(my $fh, '>>', 'mutlti-top.out') or die "$!"; | |
foreach my $server ( @ARGV ) { | |
print {$fh} `ssh ${server} top -bn 1`; |
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
(* fn: ('a -> 'b) -> 'a list -> 'b list *) | |
fun accumulate _ [] = [] | |
| accumulate f (x::xs) = f x :: accumulate f xs | |
(* fn: ('a -> 'b) * 'a -> 'b list *) | |
fun accumulate (f: ('a -> 'b), xs: 'a list): 'b list = | |
raise Fail "'accumulate' has not been implemented" |
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
fun run_tests _ [] = [] | |
| run_tests f (x :: xs) = | |
let | |
fun aux { description, is_correct } = | |
let | |
val expl = description ^ ": " ^ | |
(if is_correct then "PASSED" else "FAILED") ^ "\n" | |
in | |
(print (expl); is_correct) | |
end |
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
(* foldl type | |
fn: ('a * 'b -> 'b) -> 'b -> 'a list -> 'b | |
*) | |
fun fromBase base = let | |
fun f (x, NONE ) = NONE | |
| f (x, SOME n) = | |
if x >= 0 andalso x < base then SOME(n * base + x) | |
else NONE | |
in |
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
module Accumulate | |
export | |
accumulate : (a -> b) -> List a -> List b | |
accumulate f [] = [] | |
accumulate f (x::xs) = f x :: accumulate f xs |
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
fun inverse_captcha_2 input = let | |
val digits = List.map (fn c => (Char.ord c) - 48) (explode input) | |
fun halve [] = ([], []) | |
| halve xs = let | |
val length = (List.length xs) div 2 | |
val firstHalf = List.take(xs, length) | |
val secondHalf = List.drop(xs, length) | |
in | |
(xs, secondHalf @ firstHalf) |
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
#!perl6 | |
my @alphabet = ('0' .. '9', 'A' .. 'Z', 'a' .. 'z').flat; | |
sub to-digits(Int $n is copy, Int $b where $b >= 2 && $b <= 62 --> Str) { | |
my @digits; | |
while $n > 0 { | |
@digits.push(@alphabet[$n % $b]); | |
$n = $n div $b; | |
} |
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
> my %h{Array}; | |
{} | |
> %h{[1,2]} = [3,4]; | |
Type check failed in binding to parameter 'key'; expected Array but got Int (1) | |
in block <unit> at <unknown file> line 1 |
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 search(Int $x, Int $y, Int $max-depth is copy = 25000 --> List) { | |
state %cache{Set}; | |
my @queue = (($x, $y, Nil, Nil),); | |
while @queue and --$max-depth > 0 { | |
my ($x, $y, $px, $py) = @queue.shift(); | |
%cache{Set($x, $y)} = [$px, $py]; | |
if $x == $y { | |
my @path; |
OlderNewer