Skip to content

Instantly share code, notes, and snippets.

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)
@mcmillhj
mcmillhj / srcAccumulate.idr
Created October 8, 2017 23:23
src/Accumulate.idr
module Accumulate
export
accumulate : (a -> b) -> List a -> List b
accumulate f [] = []
accumulate f (x::xs) = f x :: accumulate f xs
@mcmillhj
mcmillhj / example.sml
Created August 24, 2017 02:36
example.sml
(* 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
@mcmillhj
mcmillhj / tests.sml
Last active February 21, 2017 14:54
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
(* 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"
@mcmillhj
mcmillhj / multi-top.pl
Created December 18, 2014 02:41
ssh into a list of servers and call the top command, then concatenate the results into a single file
#!/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`;
@mcmillhj
mcmillhj / rainforestqa.pl
Created April 29, 2014 16:25
Rainforest QA challenge
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use English qw(-no_match_vars);
use JSON qw(decode_json);
use LWP::UserAgent;